Commit 02891b74 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fdda65cd
...@@ -28,6 +28,7 @@ package zdata ...@@ -28,6 +28,7 @@ package zdata
import ( import (
"context" "context"
"fmt" "fmt"
"reflect"
"sort" "sort"
"strings" "strings"
"testing" "testing"
...@@ -98,7 +99,7 @@ func TestΔFtail(t_ *testing.T) { ...@@ -98,7 +99,7 @@ func TestΔFtail(t_ *testing.T) {
} }
// data built via applying changes from testv // data built via applying changes from testv
vδf := []ΔFile{} // (rev↑, {}blk) XXX +.Size? vδf := []*ΔFile{} // (rev↑, {}blk) XXX +.Size?
blkTab := map[int64]string{} // #blk -> ZBlk<oid> blkTab := map[int64]string{} // #blk -> ZBlk<oid>
dataTab := map[string]string{} // ZBlk<oid> -> data dataTab := map[string]string{} // ZBlk<oid> -> data
Zinblk := map[string]setI64{} // ZBlk<oid> -> which #blk refer to it Zinblk := map[string]setI64{} // ZBlk<oid> -> which #blk refer to it
...@@ -111,7 +112,7 @@ func TestΔFtail(t_ *testing.T) { ...@@ -111,7 +112,7 @@ func TestΔFtail(t_ *testing.T) {
for i, test := range testv { for i, test := range testv {
δf := setI64{} δblk := setI64{}
// rebuild blkTab/Zinblk // rebuild blkTab/Zinblk
for blk, zblk := range test.δblkTab { for blk, zblk := range test.δblkTab {
...@@ -132,9 +133,9 @@ func TestΔFtail(t_ *testing.T) { ...@@ -132,9 +133,9 @@ func TestΔFtail(t_ *testing.T) {
inblk.Add(blk) inblk.Add(blk)
} }
// update δf due to change in blkTab // update δblk due to change in blkTab
if zblk != zprev { if zblk != zprev {
δf.Add(blk) δblk.Add(blk)
} }
} }
...@@ -147,29 +148,56 @@ func TestΔFtail(t_ *testing.T) { ...@@ -147,29 +148,56 @@ func TestΔFtail(t_ *testing.T) {
data = fmt.Sprintf("%s%d", data[:1], i) // e.g. a4 data = fmt.Sprintf("%s%d", data[:1], i) // e.g. a4
dataTab[zblk] = data dataTab[zblk] = data
// update δf due to change in ZBlk data // update δblk due to change in ZBlk data
for blk := range Zinblk[zblk] { for blk := range Zinblk[zblk] {
δf.Add(blk) δblk.Add(blk)
} }
} }
vδf = append(vδf, ΔFile{ if len(δblk) == 0 {
Rev: zodb.InvalidTid, // XXX will be set after treegen commit t.Fatal("BUG: prepared δblk = ø")
Blocks: δf, }
Size: false/*XXX*/,
}) δfok := &ΔFile{
Rev: zodb.InvalidTid, // will be set after treegen commit
Blocks: δblk,
Size: false/*XXX*/,
}
// commit updated blkTab + dataTab // commit updated blkTab + dataTab
tdTxt := fmt.Sprintf("t%s D%s", xbtreetest.KVTxt(blkTab), dataTabTxt(dataTab)) tdTxt := fmt.Sprintf("t%s D%s", xbtreetest.KVTxt(blkTab), dataTabTxt(dataTab))
commit := t.CommitTree(tdTxt) commit := t.CommitTree(tdTxt)
δfok.Rev = commit.At
vδf = append(vδf, δfok)
fmt.Printf("@%s δT: %v δD: %s\n", commit.At, test.δblkTab, test.δdataTab) fmt.Printf("@%s δT: %v δD: %s\n", commit.At, test.δblkTab, test.δdataTab)
fmt.Printf("@%s %s\n", commit.At, commit.Tree) fmt.Printf("@%s %s\n", commit.At, commit.Tree)
// update δftail // update δftail
δF, err := δftail.Update(commit.ΔZ); X(err) δF, err := δftail.Update(commit.ΔZ); X(err)
// XXX assert // assert δF points to the file
_ = δF if δF.Rev != δfok.Rev {
t.Errorf("wrong δF.Rev: have %s ; want %s", δF.Rev, δfok.Rev)
}
δfiles := setOid{}
for δfile := range δF.ByFile {
δfiles.Add(δfile)
}
δfilesOK := setOid{}; δfilesOK.Add(zfile.POid())
if !δfiles.Equal(δfilesOK) {
t.Errorf("wrong δF.ByFile:\nhave keys: %s\nwant keys: %s", δfiles, δfilesOK)
continue
}
// verify δf
δf := δF.ByFile[zfile.POid()]
if !reflect.DeepEqual(δf, δfok) {
t.Errorf("wrong δf:\nhave: %v\nwant: %v", δf, δfok)
}
// XXX verify SliceByFileRev + LastBlkRev
} }
} }
......
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