Commit a5d7b5a4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4852419c
...@@ -137,8 +137,107 @@ func ZPyCommitRaw(zurl string, at zodb.Tid, objv ...ZRawObject) (_ zodb.Tid, err ...@@ -137,8 +137,107 @@ func ZPyCommitRaw(zurl string, at zodb.Tid, objv ...ZRawObject) (_ zodb.Tid, err
// ---- tests for storage drivers ---- // ---- tests for storage drivers ----
// state of an object in the database for some particular revision
type objState struct {
tid zodb.Tid
data []byte // nil if obj was deleted
}
// Txn represents one transaction.
type Txn struct {
Header *zodb.TxnInfo
Data []*zodb.DataInfo
}
// checkLoad verifies that zdrv.Load(xid) returns expected result
func checkLoad(t *testing.T, zdrv zodb.IStorageDriver, xid zodb.Xid, expect objState) {
t.Helper()
buf, tid, err := zdrv.Load(context.Background(), xid)
// deleted obj - it should load with "no data"
if expect.data == nil {
errOk := &zodb.OpError{
URL: zdrv.URL(),
Op: "load",
Args: xid,
Err: &zodb.NoDataError{Oid: xid.Oid, DeletedAt: expect.tid},
}
if !reflect.DeepEqual(err, errOk) {
t.Errorf("load %v: returned err unexpected: %v ; want: %v", xid, err, errOk)
}
if tid != 0 {
t.Errorf("load %v: returned tid unexpected: %v ; want: %v", xid, tid, expect.tid)
}
if buf != nil {
t.Errorf("load %v: returned buf != nil", xid)
}
// regular load
} else {
if err != nil {
t.Errorf("load %v: returned err unexpected: %v ; want: nil", xid, err)
}
if tid != expect.tid {
t.Errorf("load %v: returned tid unexpected: %v ; want: %v", xid, tid, expect.tid)
}
switch {
case buf == nil:
t.Errorf("load %v: returned buf = nil", xid)
case !reflect.DeepEqual(buf.Data, expect.data): // NOTE reflect to catch nil != ""
t.Errorf("load %v: different data:\nhave: %q\nwant: %q", xid, buf.Data, expect.data)
}
}
}
// DrvTestLoad verifies that zdrv implements Load correctly.
//
// txnvOk is what data to expect to be in the database.
func DrvTestLoad(t *testing.T, zdrv zodb.IStorageDriver, txnvOk []Txn) {
t.Helper()
// current knowledge of what was "before" for an oid as we scan over
// data base entries
before := map[zodb.Oid]objState{}
for _, txn := range txnvOk {
for _, obj := range txn.Data {
txh := txn.Header
// XXX assert obj.Tid == txn.Tid
// XXX check Load finds data at correct .Pos / etc ?
// ~ loadSerial
xid := zodb.Xid{txh.Tid, obj.Oid}
checkLoad(t, zdrv, xid, objState{txh.Tid, obj.Data})
// ~ loadBefore
xid = zodb.Xid{txh.Tid - 1, obj.Oid}
expect, ok := before[obj.Oid]
if ok {
checkLoad(t, zdrv, xid, expect)
}
before[obj.Oid] = objState{txh.Tid, obj.Data}
}
}
// load at ∞ with TidMax
// XXX should we get "no such transaction" with at > head? - yes
for oid, expect := range before {
xid := zodb.Xid{zodb.TidMax, oid}
checkLoad(t, zdrv, xid, expect)
}
}
// DrvTestWatch verifies that storage driver watcher can observe commits done from outside. // DrvTestWatch verifies that storage driver watcher can observe commits done from outside.
func DrvTestWatch(t *testing.T, zurl string, drvOpen zodb.DriverOpener) { func DrvTestWatch(t *testing.T, zurl string, zdrvOpen zodb.DriverOpener) {
t.Helper() t.Helper()
X := func(err error) { X := func(err error) {
if err != nil { if err != nil {
...@@ -162,7 +261,7 @@ func DrvTestWatch(t *testing.T, zurl string, drvOpen zodb.DriverOpener) { ...@@ -162,7 +261,7 @@ func DrvTestWatch(t *testing.T, zurl string, drvOpen zodb.DriverOpener) {
ctx := context.Background() ctx := context.Background()
watchq := make(chan zodb.Event) watchq := make(chan zodb.Event)
zdrv, at0, err := drvOpen(ctx, u, &zodb.DriverOptions{ReadOnly: true, Watchq: watchq}) zdrv, at0, err := zdrvOpen(ctx, u, &zodb.DriverOptions{ReadOnly: true, Watchq: watchq})
if at0 != at { if at0 != at {
t.Fatalf("opened @ %s ; want %s", at0, at) t.Fatalf("opened @ %s ; want %s", at0, at)
} }
......
...@@ -58,6 +58,7 @@ func (txe *txnEntry) Data() []byte { ...@@ -58,6 +58,7 @@ func (txe *txnEntry) Data() []byte {
return data return data
} }
/*
// state of an object in the database for some particular revision // state of an object in the database for some particular revision
type objState struct { type objState struct {
tid zodb.Tid tid zodb.Tid
...@@ -109,6 +110,7 @@ func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect objState) { ...@@ -109,6 +110,7 @@ func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect objState) {
} }
} }
} }
*/
func xfsopen(t testing.TB, path string) (*FileStorage, zodb.Tid) { func xfsopen(t testing.TB, path string) (*FileStorage, zodb.Tid) {
t.Helper() t.Helper()
...@@ -128,6 +130,27 @@ func TestLoad(t *testing.T) { ...@@ -128,6 +130,27 @@ func TestLoad(t *testing.T) {
fs, _ := xfsopen(t, "testdata/1.fs") fs, _ := xfsopen(t, "testdata/1.fs")
defer exc.XRun(fs.Close) defer exc.XRun(fs.Close)
txnv := []xtesting.Txn{}
for _, dbe := range _1fs_dbEntryv {
txn := xtesting.Txn{Header: &zodb.TxnInfo{
Tid: dbe.Header.Tid,
}}
for _, txe := range dbe.Entryv {
data := &zodb.DataInfo{
Oid: txe.Header.Oid,
Tid: txn.Header.Tid,
Data: txe.Data(),
DataTidHint: txe.DataTidHint,
}
txn.Data = append(txn.Data, data)
}
txnv = append(txnv, txn)
}
xtesting.DrvTestLoad(t, fs, txnv)
/*
// current knowledge of what was "before" for an oid as we scan over // current knowledge of what was "before" for an oid as we scan over
// data base entries // data base entries
before := map[zodb.Oid]objState{} before := map[zodb.Oid]objState{}
...@@ -160,6 +183,7 @@ func TestLoad(t *testing.T) { ...@@ -160,6 +183,7 @@ func TestLoad(t *testing.T) {
xid := zodb.Xid{zodb.TidMax, oid} xid := zodb.Xid{zodb.TidMax, oid}
checkLoad(t, fs, xid, expect) checkLoad(t, fs, xid, expect)
} }
*/
} }
// iterate tidMin..tidMax and expect db entries in expectv // iterate tidMin..tidMax and expect db entries in expectv
...@@ -273,6 +297,7 @@ func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv ...@@ -273,6 +297,7 @@ func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv
} }
} }
// TODO -> xtesting
func TestIterate(t *testing.T) { func TestIterate(t *testing.T) {
fs, _ := xfsopen(t, "testdata/1.fs") fs, _ := xfsopen(t, "testdata/1.fs")
defer exc.XRun(fs.Close) defer exc.XRun(fs.Close)
...@@ -309,6 +334,7 @@ func TestIterate(t *testing.T) { ...@@ -309,6 +334,7 @@ func TestIterate(t *testing.T) {
testIterate(t, fs, 0, zodb.TidMax, _1fs_dbEntryv[:]) testIterate(t, fs, 0, zodb.TidMax, _1fs_dbEntryv[:])
} }
// TODO -> xtesting
func BenchmarkIterate(b *testing.B) { func BenchmarkIterate(b *testing.B) {
fs, _ := xfsopen(b, "testdata/1.fs") fs, _ := xfsopen(b, "testdata/1.fs")
defer exc.XRun(fs.Close) defer exc.XRun(fs.Close)
......
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