Commit 35e63fbb authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 02292d4b
...@@ -234,8 +234,10 @@ func (t *tPersistentDB) PActivate(obj IPersistent) { ...@@ -234,8 +234,10 @@ func (t *tPersistentDB) PActivate(obj IPersistent) {
} }
} }
// checkObj state of obj and that it belongs to t.conn. // checkObj checks state of obj and that obj ∈ t.conn.
func (t *tPersistentDB) checkObj(obj IPersistent, oid Oid, serial Tid, state ObjectState, refcnt int32, loading *loadState) { //
// if object is !GHOST - it also verifies its value.
func (t *tPersistentDB) checkObj(obj *MyObject, oid Oid, serial Tid, state ObjectState, refcnt int32, valuev ...string) {
t.Helper() t.Helper()
// any object with live pointer to it must be also in conn's cache. // any object with live pointer to it must be also in conn's cache.
...@@ -244,7 +246,7 @@ func (t *tPersistentDB) checkObj(obj IPersistent, oid Oid, serial Tid, state Obj ...@@ -244,7 +246,7 @@ func (t *tPersistentDB) checkObj(obj IPersistent, oid Oid, serial Tid, state Obj
t.Fatalf("cache.get %s -> not same object:\nhave: %#v\nwant: %#v", oid, connObj, oid) t.Fatalf("cache.get %s -> not same object:\nhave: %#v\nwant: %#v", oid, connObj, oid)
} }
// and conn.Get must return it // and conn.Get must return exactly obj.
connObj, err := t.conn.Get(t.ctx, oid) connObj, err := t.conn.Get(t.ctx, oid)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -253,7 +255,22 @@ func (t *tPersistentDB) checkObj(obj IPersistent, oid Oid, serial Tid, state Obj ...@@ -253,7 +255,22 @@ func (t *tPersistentDB) checkObj(obj IPersistent, oid Oid, serial Tid, state Obj
t.Fatalf("conn.get %s -> not same object:\nhave: %#v\nwant: %#v", oid, connObj, oid) t.Fatalf("conn.get %s -> not same object:\nhave: %#v\nwant: %#v", oid, connObj, oid)
} }
_checkObj(t.T, obj, t.conn, oid, serial, state, refcnt, loading) _checkObj(t.T, obj, t.conn, oid, serial, state, refcnt, /*loading*/nil)
if state == GHOST {
if len(valuev) != 0 {
panic("t.checkObj(GHOST) must come without value")
}
return
}
if len(valuev) != 1 {
panic("t.checkObj(!GHOST) must come with one value")
}
value := valuev[0]
if obj.value != value {
t.Fatalf("obj.value mismatch: have %q; want %q", obj.value, value)
}
} }
// Resync resyncs t to new transaction @at. // Resync resyncs t to new transaction @at.
...@@ -345,40 +362,38 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -345,40 +362,38 @@ func TestPersistentDB(t0 *testing.T) {
// get objects // get objects
obj1 := t.Get(101) obj1 := t.Get(101)
obj2 := t.Get(102) obj2 := t.Get(102)
t.checkObj(obj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(obj1, 101, InvalidTid, GHOST, 0)
t.checkObj(obj2, 102, InvalidTid, GHOST, 0, nil) t.checkObj(obj2, 102, InvalidTid, GHOST, 0)
// activate: jar has to load, state changes -> uptodate // activate: jar has to load, state changes -> uptodate
t.PActivate(obj1) t.PActivate(obj1)
t.PActivate(obj2) t.PActivate(obj2)
t.checkObj(obj1, 101, at1, UPTODATE, 1, nil) t.checkObj(obj1, 101, at1, UPTODATE, 1, "hello")
t.checkObj(obj2, 102, at1, UPTODATE, 1, nil) t.checkObj(obj2, 102, at1, UPTODATE, 1, "world")
assert.Equal(obj1.value, "hello")
assert.Equal(obj2.value, "world")
// activate again: refcnt++ // activate again: refcnt++
t.PActivate(obj1) t.PActivate(obj1)
t.PActivate(obj2) t.PActivate(obj2)
t.checkObj(obj1, 101, at1, UPTODATE, 2, nil) t.checkObj(obj1, 101, at1, UPTODATE, 2, "hello")
t.checkObj(obj2, 102, at1, UPTODATE, 2, nil) t.checkObj(obj2, 102, at1, UPTODATE, 2, "world")
// deactivate: refcnt-- // deactivate: refcnt--
obj1.PDeactivate() obj1.PDeactivate()
obj2.PDeactivate() obj2.PDeactivate()
t.checkObj(obj1, 101, at1, UPTODATE, 1, nil) t.checkObj(obj1, 101, at1, UPTODATE, 1, "hello")
t.checkObj(obj2, 102, at1, UPTODATE, 1, nil) t.checkObj(obj2, 102, at1, UPTODATE, 1, "world")
// deactivate: state dropped for obj1, obj2 stays in live cache // deactivate: state dropped for obj1, obj2 stays in live cache
obj1.PDeactivate() obj1.PDeactivate()
obj2.PDeactivate() obj2.PDeactivate()
t.checkObj(obj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(obj1, 101, InvalidTid, GHOST, 0)
t.checkObj(obj2, 102, at1, UPTODATE, 0, nil) t.checkObj(obj2, 102, at1, UPTODATE, 0, "world")
// invalidate: obj2 state dropped // invalidate: obj2 state dropped
obj1.PInvalidate() obj1.PInvalidate()
obj2.PInvalidate() obj2.PInvalidate()
t.checkObj(obj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(obj1, 101, InvalidTid, GHOST, 0)
t.checkObj(obj2, 102, InvalidTid, GHOST, 0, nil) t.checkObj(obj2, 102, InvalidTid, GHOST, 0)
// commit change to obj2 from external process // commit change to obj2 from external process
_obj2.value = "kitty" _obj2.value = "kitty"
...@@ -396,34 +411,30 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -396,34 +411,30 @@ func TestPersistentDB(t0 *testing.T) {
c2obj1 := t2.Get(101) c2obj1 := t2.Get(101)
c2obj2 := t2.Get(102) c2obj2 := t2.Get(102)
t2.checkObj(c2obj1, 101, InvalidTid, GHOST, 0, nil) t2.checkObj(c2obj1, 101, InvalidTid, GHOST, 0)
t2.checkObj(c2obj2, 102, InvalidTid, GHOST, 0, nil) t2.checkObj(c2obj2, 102, InvalidTid, GHOST, 0)
t2.PActivate(c2obj1) t2.PActivate(c2obj1)
t2.PActivate(c2obj2) t2.PActivate(c2obj2)
t2.checkObj(c2obj1, 101, at1, UPTODATE, 1, nil) t2.checkObj(c2obj1, 101, at1, UPTODATE, 1, "hello")
t2.checkObj(c2obj2, 102, at2, UPTODATE, 1, nil) t2.checkObj(c2obj2, 102, at2, UPTODATE, 1, "kitty")
assert.Equal(c2obj1.value, "hello")
assert.Equal(c2obj2.value, "kitty")
c2obj1.PDeactivate() c2obj1.PDeactivate()
c2obj2.PDeactivate() c2obj2.PDeactivate()
// conn1 stays at older view for now // conn1 stays at older view for now
t1.checkObj(obj1, 101, InvalidTid, GHOST, 0, nil) t1.checkObj(obj1, 101, InvalidTid, GHOST, 0)
t1.checkObj(obj2, 102, InvalidTid, GHOST, 0, nil) t1.checkObj(obj2, 102, InvalidTid, GHOST, 0)
t1.PActivate(obj1) t1.PActivate(obj1)
t1.PActivate(obj2) t1.PActivate(obj2)
t1.checkObj(obj1, 101, at1, UPTODATE, 1, nil) t1.checkObj(obj1, 101, at1, UPTODATE, 1, "hello")
t1.checkObj(obj2, 102, at1, UPTODATE, 1, nil) t1.checkObj(obj2, 102, at1, UPTODATE, 1, "world")
assert.Equal(obj1.value, "hello")
assert.Equal(obj2.value, "world")
// conn1 deactivate: obj2 stays in conn1 live cache with old state // conn1 deactivate: obj2 stays in conn1 live cache with old state
obj1.PDeactivate() obj1.PDeactivate()
obj2.PDeactivate() obj2.PDeactivate()
t1.checkObj(obj1, 101, InvalidTid, GHOST, 0, nil) t1.checkObj(obj1, 101, InvalidTid, GHOST, 0)
t1.checkObj(obj2, 102, at1, UPTODATE, 0, nil) t1.checkObj(obj2, 102, at1, UPTODATE, 0, "world")
// txn1 completes - conn1 goes back to db pool // txn1 completes - conn1 goes back to db pool
t1.Abort() t1.Abort()
...@@ -438,21 +449,19 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -438,21 +449,19 @@ func TestPersistentDB(t0 *testing.T) {
assert.Equal(db.pool, []*Connection{}) assert.Equal(db.pool, []*Connection{})
// obj2 should be invalidated // obj2 should be invalidated
t.checkObj(obj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(obj1, 101, InvalidTid, GHOST, 0)
t.checkObj(obj2, 102, InvalidTid, GHOST, 0, nil) t.checkObj(obj2, 102, InvalidTid, GHOST, 0)
// obj2 data should be new // obj2 data should be new
t.PActivate(obj1); t.PActivate(obj1);
t.PActivate(obj2); t.PActivate(obj2);
t.checkObj(obj1, 101, at1, UPTODATE, 1, nil) t.checkObj(obj1, 101, at1, UPTODATE, 1, "hello")
t.checkObj(obj2, 102, at2, UPTODATE, 1, nil) t.checkObj(obj2, 102, at2, UPTODATE, 1, "kitty")
assert.Equal(obj1.value, "hello")
assert.Equal(obj2.value, "kitty")
obj1.PDeactivate() obj1.PDeactivate()
obj2.PDeactivate() obj2.PDeactivate()
t.checkObj(obj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(obj1, 101, InvalidTid, GHOST, 0)
t.checkObj(obj2, 102, at2, UPTODATE, 0, nil) t.checkObj(obj2, 102, at2, UPTODATE, 0, "kitty")
// finish tnx3 and txn2 - conn1 and conn2 go back to db pool // finish tnx3 and txn2 - conn1 and conn2 go back to db pool
t.Abort() t.Abort()
...@@ -473,21 +482,19 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -473,21 +482,19 @@ func TestPersistentDB(t0 *testing.T) {
// it should see latest data // it should see latest data
robj1 := t.Get(101) robj1 := t.Get(101)
robj2 := t.Get(102) robj2 := t.Get(102)
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
t.checkObj(robj2, 102, InvalidTid, GHOST, 0, nil) t.checkObj(robj2, 102, InvalidTid, GHOST, 0)
t.PActivate(robj1) t.PActivate(robj1)
t.PActivate(robj2) t.PActivate(robj2)
t.checkObj(robj1, 101, at1, UPTODATE, 1, nil) t.checkObj(robj1, 101, at1, UPTODATE, 1, "hello")
t.checkObj(robj2, 102, at2, UPTODATE, 1, nil) t.checkObj(robj2, 102, at2, UPTODATE, 1, "kitty")
assert.Equal(robj1.value, "hello")
assert.Equal(robj2.value, "kitty")
// obj2 stays in live cache // obj2 stays in live cache
robj1.PDeactivate() robj1.PDeactivate()
robj2.PDeactivate() robj2.PDeactivate()
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
t.checkObj(robj2, 102, at2, UPTODATE, 0, nil) t.checkObj(robj2, 102, at2, UPTODATE, 0, "kitty")
// txn4 completes, but its conn stays out of db pool // txn4 completes, but its conn stays out of db pool
t.Abort() t.Abort()
...@@ -498,21 +505,19 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -498,21 +505,19 @@ func TestPersistentDB(t0 *testing.T) {
assert.Equal(db.pool, []*Connection{t1.conn, t2.conn}) assert.Equal(db.pool, []*Connection{t1.conn, t2.conn})
// obj2 should be invalidated // obj2 should be invalidated
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
t.checkObj(robj2, 102, InvalidTid, GHOST, 0, nil) t.checkObj(robj2, 102, InvalidTid, GHOST, 0)
// obj2 data should be old // obj2 data should be old
t.PActivate(robj1) t.PActivate(robj1)
t.PActivate(robj2) t.PActivate(robj2)
t.checkObj(robj1, 101, at1, UPTODATE, 1, nil) t.checkObj(robj1, 101, at1, UPTODATE, 1, "hello")
t.checkObj(robj2, 102, at1, UPTODATE, 1, nil) t.checkObj(robj2, 102, at1, UPTODATE, 1, "world")
assert.Equal(robj1.value, "hello")
assert.Equal(robj2.value, "world")
robj1.PDeactivate() robj1.PDeactivate()
robj2.PDeactivate() robj2.PDeactivate()
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
t.checkObj(robj2, 102, at1, UPTODATE, 0, nil) t.checkObj(robj2, 102, at1, UPTODATE, 0, "world")
// Resync ↑ (at1 -> at2; within δtail coverage) // Resync ↑ (at1 -> at2; within δtail coverage)
t.Abort() t.Abort()
...@@ -521,20 +526,18 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -521,20 +526,18 @@ func TestPersistentDB(t0 *testing.T) {
assert.Equal(db.pool, []*Connection{t1.conn, t2.conn}) assert.Equal(db.pool, []*Connection{t1.conn, t2.conn})
// obj2 should be invalidated // obj2 should be invalidated
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
t.checkObj(robj2, 102, InvalidTid, GHOST, 0, nil) t.checkObj(robj2, 102, InvalidTid, GHOST, 0)
t.PActivate(robj1) t.PActivate(robj1)
t.PActivate(robj2) t.PActivate(robj2)
t.checkObj(robj1, 101, at1, UPTODATE, 1, nil) t.checkObj(robj1, 101, at1, UPTODATE, 1, "hello")
t.checkObj(robj2, 102, at2, UPTODATE, 1, nil) t.checkObj(robj2, 102, at2, UPTODATE, 1, "kitty")
assert.Equal(robj1.value, "hello")
assert.Equal(robj2.value, "kitty")
robj1.PDeactivate() robj1.PDeactivate()
robj2.PDeactivate() robj2.PDeactivate()
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
t.checkObj(robj2, 102, at2, UPTODATE, 0, nil) t.checkObj(robj2, 102, at2, UPTODATE, 0, "kitty")
// Resync ↓ (at1 -> at0; to outside δtail coverage) // Resync ↓ (at1 -> at0; to outside δtail coverage)
t.Abort() t.Abort()
...@@ -543,20 +546,18 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -543,20 +546,18 @@ func TestPersistentDB(t0 *testing.T) {
assert.Equal(db.pool, []*Connection{t1.conn, t2.conn}) assert.Equal(db.pool, []*Connection{t1.conn, t2.conn})
// obj2 should be invalidated // obj2 should be invalidated
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
t.checkObj(robj2, 102, InvalidTid, GHOST, 0, nil) t.checkObj(robj2, 102, InvalidTid, GHOST, 0)
t.PActivate(robj1) t.PActivate(robj1)
t.PActivate(robj2) t.PActivate(robj2)
t.checkObj(robj1, 101, at0, UPTODATE, 1, nil) t.checkObj(robj1, 101, at0, UPTODATE, 1, "init")
t.checkObj(robj2, 102, at0, UPTODATE, 1, nil) t.checkObj(robj2, 102, at0, UPTODATE, 1, "db")
assert.Equal(robj1.value, "init")
assert.Equal(robj2.value, "db")
robj1.PDeactivate() robj1.PDeactivate()
robj2.PDeactivate() robj2.PDeactivate()
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil) t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
t.checkObj(robj2, 102, at0, UPTODATE, 0, nil) t.checkObj(robj2, 102, at0, UPTODATE, 0, "db")
// Resync ↑ (at0 -> at2; from outside δtail coverage) // Resync ↑ (at0 -> at2; from outside δtail coverage)
t.Abort() t.Abort()
...@@ -565,10 +566,8 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -565,10 +566,8 @@ func TestPersistentDB(t0 *testing.T) {
assert.Equal(db.pool, []*Connection{t1.conn, t2.conn}) assert.Equal(db.pool, []*Connection{t1.conn, t2.conn})
// obj2 should be invalidated // obj2 should be invalidated
assert.Equal(t.conn.Cache().Get(101), robj1) // XXX is t.checkObj(robj1, 101, InvalidTid, GHOST, 0)
assert.Equal(t.conn.Cache().Get(102), robj2) // XXX is t.checkObj(robj2, 102, InvalidTid, GHOST, 0)
t.checkObj(robj1, 101, InvalidTid, GHOST, 0, nil)
t.checkObj(robj2, 102, InvalidTid, GHOST, 0, nil)
......
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