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

.

parent 503c430b
...@@ -9,6 +9,12 @@ import ( ...@@ -9,6 +9,12 @@ import (
"../../zodb" "../../zodb"
) )
// one database transaction record
type dbEntry struct {
Header TxnHeader
Entryv []txnEntry
}
// one entry inside transaction // one entry inside transaction
type txnEntry struct { type txnEntry struct {
Header DataHeader Header DataHeader
...@@ -16,6 +22,7 @@ type txnEntry struct { ...@@ -16,6 +22,7 @@ type txnEntry struct {
userData []byte // data client should see on load; nil means same as RawData userData []byte // data client should see on load; nil means same as RawData
} }
// Data returns data a client should see
func (txe *txnEntry) Data() []byte { func (txe *txnEntry) Data() []byte {
data := txe.userData data := txe.userData
if data == nil { if data == nil {
...@@ -24,9 +31,27 @@ func (txe *txnEntry) Data() []byte { ...@@ -24,9 +31,27 @@ func (txe *txnEntry) Data() []byte {
return data return data
} }
type dbEntry struct { // successfull result of load for an oid
Header TxnHeader type oidLoadedOk struct {
Entryv []txnEntry tid zodb.Tid
data []byte
}
// current knowledge of what was "before" for an oid as we scan over
// data base entries
type beforeMap map[zodb.Oid]oidLoadedOk
func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect oidLoadedOk) {
data, tid, err := fs.Load(xid)
if err != nil {
t.Errorf("load %v: %v", xid, err)
}
if tid != expect.tid {
t.Errorf("load %v: returned tid unexpected: %v ; want: %v", xid, tid, expect.tid)
}
if !bytes.Equal(data, expect.data) {
t.Errorf("load %v: different data:\nhave: %q\nwant: %q", xid, data, expect.data)
}
} }
func TestLoad(t *testing.T) { func TestLoad(t *testing.T) {
...@@ -35,22 +60,39 @@ func TestLoad(t *testing.T) { ...@@ -35,22 +60,39 @@ func TestLoad(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
before := beforeMap{}
for _, dbe := range _1fs_dbEntryv { for _, dbe := range _1fs_dbEntryv {
for _, txe := range dbe.Entryv { for _, txe := range dbe.Entryv {
txh := txe.Header txh := txe.Header
// loadSerial // loadSerial
xid := zodb.Xid{zodb.XTid{txh.Tid, false}, txh.Oid} xid := zodb.Xid{zodb.XTid{txh.Tid, false}, txh.Oid}
data, tid, err := fs.Load(xid) checkLoad(t, fs, xid, oidLoadedOk{txh.Tid, txe.Data()})
if err != nil { //data, tid, err := fs.Load(xid)
t.Errorf("load %v: %v", xid, err) //if err != nil {
} // t.Errorf("load %v: %v", xid, err)
if tid != txh.Tid { //}
t.Errorf("load %v: returned tid unexpected: %v", xid, tid) //if tid != txh.Tid {
} // t.Errorf("load %v: returned tid unexpected: %v", xid, tid)
if !bytes.Equal(data, txe.Data()) { //}
t.Errorf("load %v: different data:\nhave: %q\nwant: %q", xid, data, txe.Data()) //if !bytes.Equal(data, txe.Data()) {
// t.Errorf("load %v: different data:\nhave: %q\nwant: %q", xid, data, txe.Data())
//}
// loadBefore
// TODO also test loadBefore (TixMax)
xid = zodb.Xid{zodb.XTid{txh.Tid, true}, txh.Oid}
expect, ok := before[txh.Oid]
// TODO also test for getting error when !ok
if ok {
checkLoad(t, fs, xid, expect)
} }
before[txh.Oid] = oidLoadedOk{txh.Tid, txe.Data()}
} }
} }
} }
...@@ -83,7 +83,7 @@ type ErrXidMissing struct { ...@@ -83,7 +83,7 @@ type ErrXidMissing struct {
} }
func (e *ErrXidMissing) Error() string { func (e *ErrXidMissing) Error() string {
return fmt.Sprintf("") // TODO return fmt.Sprintf("%v: no matching data record found", e.Xid) // XXX ok?
} }
// ---------------------------------------- // ----------------------------------------
......
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