Commit 9feea1a4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3c40e38d
......@@ -50,14 +50,19 @@ type T struct {
// Commit represent test commit changing a tree.
type Commit struct {
Tree string // the tree in topology-encoding
Prev *Commit // previous commit
At zodb.Tid // commit revision
ΔZ *zodb.EventCommit // raw ZODB changes; δZ.tid == at
Xkv RBucketSet // full tree state as of @at
Δxkv map[Key]Δstring // full tree-diff against parent
ZBlkDataTab map[zodb.Oid]string // full snapshot of all ZBlk data @at
// δzblkData map[zodb.Oid]Δstring // full diff for zblkData against parent XXX ?
Tree string // the tree in topology-encoding
Prev *Commit // previous commit
At zodb.Tid // commit revision
ΔZ *zodb.EventCommit // raw ZODB changes; δZ.tid == at
Xkv RBucketSet // full tree state as of @at
Δxkv map[Key]Δstring // full tree-diff against parent
ZBlkTab map[zodb.Oid]ZBlkInfo // full snapshot of all ZBlk name/data @at
}
// ZBlkInfo describes one ZBlk object.
type ZBlkInfo struct {
Name string // this ZBlk comes under root['treegen/values'][Name]
Data string
}
// NewT creates new T.
......@@ -93,13 +98,13 @@ func NewT(t *testing.T) *T {
head := tt.treeSrv.head
t1 := &Commit{
Tree: "T/B:", // treegen.py creates the tree as initially empty
Prev: nil,
At: head,
Xkv: xGetTree(tt.DB, head, tt.Root()),
ZBlkDataTab: xGetBlkDataTab(tt.DB, head),
ΔZ: nil,
Δxkv: nil,
Tree: "T/B:", // treegen.py creates the tree as initially empty
Prev: nil,
At: head,
Xkv: xGetTree(tt.DB, head, tt.Root()),
ZBlkTab: xGetBlkTab(tt.DB, head),
ΔZ: nil,
Δxkv: nil,
}
tt.commitv = []*Commit{t1}
......@@ -178,11 +183,11 @@ func (t *T) CommitTree(tree string) *Commit {
}
ttree := &Commit{
Tree: tree,
At: δZ.Tid,
ΔZ: δZ,
Xkv: xkv,
ZBlkDataTab: xGetBlkDataTab(t.DB, δZ.Tid),
Tree: tree,
At: δZ.Tid,
ΔZ: δZ,
Xkv: xkv,
ZBlkTab: xGetBlkTab(t.DB, δZ.Tid),
}
tprev := t.Head()
......@@ -194,14 +199,14 @@ func (t *T) CommitTree(tree string) *Commit {
return ttree
}
// xGetBlkDataTab loads all ZBlk from db@at.
// xGetBlkTab loads all ZBlk from db@at.
//
// it returns {} oid -> blkdata.
func xGetBlkDataTab(db *zodb.DB, at zodb.Tid) map[zodb.Oid]string {
defer exc.Contextf("%s: @%s: get blkdatatab", db.Storage().URL(), at)
func xGetBlkTab(db *zodb.DB, at zodb.Tid) map[zodb.Oid]ZBlkInfo {
defer exc.Contextf("%s: @%s: get blktab", db.Storage().URL(), at)
X := exc.Raiseif
blkDataTab := map[zodb.Oid]string{}
blkTab := map[zodb.Oid]ZBlkInfo{}
txn, ctx := transaction.New(context.Background())
defer txn.Abort()
......@@ -228,18 +233,23 @@ func xGetBlkDataTab(db *zodb.DB, at zodb.Tid) map[zodb.Oid]string {
err = zblkdir.PActivate(ctx); X(err)
defer zblkdir.PDeactivate()
for k, xzblk := range zblkdir.Data {
for xname, xzblk := range zblkdir.Data {
name, ok := xname.(string)
if !ok {
exc.Raisef("root['treegen/values']: key [%q]: expected str, got %T", xname, xname)
}
zblk, ok := xzblk.(zodb.IPersistent)
if !ok {
exc.Raisef("root['treegen/values'][%q]: expected IPersistent, got %s", k, xzodb.TypeOf(xzblk))
exc.Raisef("root['treegen/values'][%q]: expected IPersistent, got %s", name, xzodb.TypeOf(xzblk))
}
oid := zblk.POid()
data := xzgetBlkData(ctx, zconn, oid)
blkDataTab[oid] = data
blkTab[oid] = ZBlkInfo{name, data}
}
return blkDataTab
return blkTab
}
// XGetBlkData loads blk data for ZBlk<oid> @t.at
......@@ -249,11 +259,11 @@ func (t *Commit) XGetBlkData(oid zodb.Oid) string {
if oid == VDEL {
return DEL
}
data, ok := t.ZBlkDataTab[oid]
zblki, ok := t.ZBlkTab[oid]
if !ok {
exc.Raisef("getBlkData ZBlk<%s> @%s: no such ZBlk", oid, t.At)
}
return data
return zblki.Data
}
......
......@@ -82,6 +82,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
err = zroot.PActivate(ctx); X(err)
defer zroot.PDeactivate()
zfile := zroot.Data["treegen/file"].(*ZBigFile)
zfileOid := zfile.POid()
err = zfile.PActivate(ctx); X(err)
defer zfile.PDeactivate()
if treeOid := zfile.blktab.POid(); treeOid != t.Root() {
......@@ -103,9 +104,8 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
Zinblk := map[string]setI64{} // ZBlk<name> -> which #blk refer to it
// initialize dataTab from root['treegen/values']
for /*oid*/_, zblk := range t.Head().ZBlkDataTab {
// treegen initializes values[x] = ZBlk(x)
dataTab[zblk] = zblk
for /*oid*/_, zblki := range t.Head().ZBlkTab {
dataTab[zblki.Name] = zblki.Data
}
......@@ -186,7 +186,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
}
δfilesOK := setOid{}
if δfok != nil {
δfilesOK.Add(zfile.POid())
δfilesOK.Add(zfileOid)
}
if !δfiles.Equal(δfilesOK) {
t.Errorf("wrong δF.ByFile:\nhave keys: %s\nwant keys: %s", δfiles, δfilesOK)
......@@ -198,9 +198,31 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
}
// verify δf
δf := δF.ByFile[zfile.POid()]
δf := δF.ByFile[zfileOid]
if !reflect.DeepEqual(δf, δfok) {
t.Errorf("wrong δf:\nhave: %v\nwant: %v", δf, δfok)
t.Errorf("δf:\nhave: %v\nwant: %v", δf, δfok)
}
// verify δftail.trackSetZBlk
trackZinblk := map[string]setI64{}
for oid, zt := range δftail.trackSetZBlk {
zblki := commit.ZBlkTab[oid]
for foid, blocks := range zt.infile {
if foid != zfileOid {
t.Errorf(".trackSetZBlk: zblk %s points to unexpected file %s", zblki.Name, foid)
continue
}
inblk, ok := trackZinblk[zblki.Name]
if !ok {
inblk = setI64{}
trackZinblk[zblki.Name] = inblk
}
inblk.Update(blocks)
}
}
if !reflect.DeepEqual(trackZinblk, Zinblk) {
t.Errorf(".trackSetZBlk:\n~have: %v\n want: %v", trackZinblk, Zinblk)
}
// XXX ForgePast configure threshold
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment