Commit 2d2242a9 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ec7dafb1
......@@ -68,7 +68,7 @@ type oidCacheEntry struct {
// XXX or?
// cached revisions in descending order
// .before > .serial >= next.before > next.serial ?
revv []*revCacheEntry
revv []*revCacheEntry // XXX -> rcev ?
}
// revCacheEntry is information about 1 cached oid revision
......
......@@ -82,7 +82,7 @@ var tstor = &tStorage{
dataMap: map[zodb.Oid][]tOidData{
1: {
{4, []byte("hello")},
{7, []byte("world")},
{8, []byte("world")},
},
},
}
......@@ -114,6 +114,8 @@ func TestCache(t *testing.T) {
ok1 := func(v bool) { t.Helper(); tc.ok1(v) }
//eq := func(a, b interface{}) { t.Helper(); tc.assertEq(a, b) }
hello := []byte("hello")
c := NewCache(tstor)
checkLoad := func(xid zodb.Xid, data []byte, serial zodb.Tid, err error) {
......@@ -121,13 +123,13 @@ func TestCache(t *testing.T) {
bad := &bytes.Buffer{}
d, s, e := c.Load(xid)
if !reflect.DeepEqual(data, d) {
fmt.Fprintf(bad, "data:\n%s", pretty.Compare(data, d))
fmt.Fprintf(bad, "data:\n%s\n", pretty.Compare(data, d))
}
if serial != s {
fmt.Fprintf(bad, "serial:\n%s", pretty.Compare(serial, s))
fmt.Fprintf(bad, "serial:\n%s\n", pretty.Compare(serial, s))
}
if !reflect.DeepEqual(err, e) {
fmt.Fprintf(bad, "err:\n%s", pretty.Compare(err, e))
fmt.Fprintf(bad, "err:\n%s\n", pretty.Compare(err, e))
}
if bad.Len() != 0 {
......@@ -139,16 +141,16 @@ func TestCache(t *testing.T) {
t.Helper()
bad := &bytes.Buffer{}
if rce.before != before {
fmt.Fprintf(bad, "before:\n%s", pretty.Compare(before, rce.before))
fmt.Fprintf(bad, "before:\n%s\n", pretty.Compare(before, rce.before))
}
if rce.serial != serial {
fmt.Fprintf(bad, "serial:\n%s", pretty.Compare(serial, rce.serial))
fmt.Fprintf(bad, "serial:\n%s\n", pretty.Compare(serial, rce.serial))
}
if !reflect.DeepEqual(rce.data, data) {
fmt.Fprintf(bad, "data:\n%s", pretty.Compare(data, rce.data))
fmt.Fprintf(bad, "data:\n%s\n", pretty.Compare(data, rce.data))
}
if !reflect.DeepEqual(rce.err, err) {
fmt.Fprintf(bad, "err:\n%s", pretty.Compare(err, rce.err))
fmt.Fprintf(bad, "err:\n%s\n", pretty.Compare(err, rce.err))
}
if bad.Len() != 0 {
......@@ -156,10 +158,16 @@ func TestCache(t *testing.T) {
}
}
checkOCE := func(oid zodb.Oid, rcev ...*revCacheEntry) {
t.Helper()
oce := c.entryMap[oid]
if !reflect.DeepEqual(oce.revv, rcev) {
t.Fatalf("oce(%v):\n%s", oid, pretty.Compare(rcev, oce.revv))
}
}
// load <3 -> new rce entry
checkLoad(xidlt(1,3), nil, 0, &zodb.ErrXidMissing{xidlt(1,3)})
//checkOCE(1, rce1_b3)
oce1 := c.entryMap[1]
ok1(len(oce1.revv) == 1)
rce1_b3 := oce1.revv[0]
......@@ -167,7 +175,6 @@ func TestCache(t *testing.T) {
// load <4 -> <3 merged with <4
checkLoad(xidlt(1,4), nil, 0, &zodb.ErrXidMissing{xidlt(1,4)})
ok1(len(oce1.revv) == 1)
rce1_b4 := oce1.revv[0]
ok1(rce1_b4 != rce1_b3) // rce1_b3 was merged into rce1_b4
......@@ -175,10 +182,28 @@ func TestCache(t *testing.T) {
// load <2 -> <2 merged with <4
checkLoad(xidlt(1,2), nil, 0, &zodb.ErrXidMissing{xidlt(1,2)})
ok1(len(oce1.revv) == 1)
ok1(oce1.revv[0] == rce1_b4)
checkRCE(rce1_b4, 4, 0, nil, &zodb.ErrXidMissing{xidlt(1,4)})
// load <6 -> new rce entry with data
checkLoad(xidlt(1,6), hello, 4, nil)
ok1(len(oce1.revv) == 2)
rce1_b6 := oce1.revv[1]
checkRCE(rce1_b6, 6, 4, hello, nil)
checkOCE(1, rce1_b4, rce1_b6)
// load <5 -> merged with <6
checkLoad(xidlt(1,5), hello, 4, nil)
checkOCE(1, rce1_b4, rce1_b6)
// load <7 -> <6 merged -> <7
checkLoad(xidlt(1,7), hello, 4, nil)
ok1(len(oce1.revv) == 2)
rce1_b7 := oce1.revv[1]
ok1(rce1_b7 != rce1_b6)
checkRCE(rce1_b7, 7, 4, hello, nil)
checkOCE(1, rce1_b4, rce1_b7)
}
type Checker struct {
......
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