Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
fb4ece21
Commit
fb4ece21
authored
Aug 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
fddbe660
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
47 deletions
+56
-47
go/neo/client/cache_test.go
go/neo/client/cache_test.go
+56
-47
No files found.
go/neo/client/cache_test.go
View file @
fb4ece21
...
...
@@ -20,6 +20,7 @@
package
client
import
(
"fmt"
"reflect"
"sort"
"testing"
...
...
@@ -43,8 +44,10 @@ type tOidData struct {
}
func
(
s
*
tStorage
)
Load
(
xid
zodb
.
Xid
)
(
data
[]
byte
,
serial
zodb
.
Tid
,
err
error
)
{
fmt
.
Printf
(
"> load(%v)
\n
"
,
xid
)
defer
func
()
{
fmt
.
Printf
(
"< %v, %v, %v
\n
"
,
data
,
serial
,
err
)
}()
tid
:=
xid
.
Tid
if
xid
.
TidBefore
{
if
!
xid
.
TidBefore
{
tid
++
// XXX overflow
}
...
...
@@ -56,47 +59,24 @@ func (s *tStorage) Load(xid zodb.Xid) (data []byte, serial zodb.Tid, err error)
// find max entry with .serial < tid
n
:=
len
(
datav
)
i
:=
n
-
1
-
sort
.
Search
(
n
,
func
(
i
int
)
bool
{
return
datav
[
n
-
1
-
i
]
.
serial
<
tid
v
:=
datav
[
n
-
1
-
i
]
.
serial
<
tid
fmt
.
Printf
(
"@%d -> %v (@%d; %v)
\n
"
,
i
,
v
,
n
-
1
-
i
,
tid
)
return
v
})
fmt
.
Printf
(
"i: %d n: %d
\n
"
,
i
,
n
)
if
i
==
-
1
{
// tid < all .serial - no such transaction
return
nil
,
0
,
&
zodb
.
ErrXidMissing
{
xid
}
}
// check we have exact match if it was loadSerial
if
xid
.
TidBefore
&&
datav
[
i
]
.
serial
!=
xid
.
Tid
{
if
!
xid
.
TidBefore
&&
datav
[
i
]
.
serial
!=
xid
.
Tid
{
return
nil
,
0
,
&
zodb
.
ErrXidMissing
{
xid
}
}
return
datav
[
i
]
.
data
,
datav
[
i
]
.
serial
,
nil
}
/*
type tTxnRecord struct {
tid zodb.Tid
// data records for oid changed in transaction
// .oid↑
datav []tDataRecord
}
type tDataRecord struct {
oid zodb.Oid
data []byte
}
if xid.TidBefore {
// find max txn with .tid < xid.Tid
n := len(s.txnv)
i := n - 1 - sort.Search(n, func(i int) bool {
return s.txnv[n - 1 - i].tid < xid.Tid
})
if i == -1 {
// XXX xid.Tid < all .tid - no such transaction
}
}
*/
var
tstor
=
&
tStorage
{
dataMap
:
map
[
zodb
.
Oid
][]
tOidData
{
1
:
{
...
...
@@ -106,24 +86,6 @@ var tstor = &tStorage{
},
}
type
Checker
struct
{
t
*
testing
.
T
}
func
(
c
*
Checker
)
ok1
(
v
bool
)
{
c
.
t
.
Helper
()
if
!
v
{
c
.
t
.
Fatal
(
"!ok"
)
}
}
func
(
c
*
Checker
)
assertEq
(
a
,
b
interface
{})
{
c
.
t
.
Helper
()
if
!
reflect
.
DeepEqual
(
a
,
b
)
{
c
.
t
.
Fatal
(
"!eq:
\n
"
,
pretty
.
Compare
(
a
,
b
))
}
}
func
TestCache
(
t
*
testing
.
T
)
{
// XXX <100 <90 <80
// q<110 -> a) 110 <= cache.before b) otherwise
...
...
@@ -142,6 +104,9 @@ func TestCache(t *testing.T) {
c
:=
NewCache
(
tstor
)
// XXX hack; place=ok?
pretty
.
CompareConfig
.
PrintStringers
=
true
xid1
:=
zodb
.
Xid
{
Oid
:
1
,
XTid
:
zodb
.
XTid
{
Tid
:
2
,
TidBefore
:
true
}}
data
,
serial
,
err
:=
c
.
Load
(
xid1
)
// -> nil, 0, &zodb.ErrXidMissing{1,<2}
ok1
(
data
==
nil
)
...
...
@@ -164,3 +129,47 @@ func TestCache(t *testing.T) {
eq
(
len
(
oce1
.
revv
),
1
)
eq
(
oce1
.
revv
[
0
],
rce1_b2
)
}
type
Checker
struct
{
t
*
testing
.
T
}
func
(
c
*
Checker
)
ok1
(
v
bool
)
{
c
.
t
.
Helper
()
if
!
v
{
c
.
t
.
Fatal
(
"!ok"
)
}
}
func
(
c
*
Checker
)
assertEq
(
a
,
b
interface
{})
{
c
.
t
.
Helper
()
if
!
reflect
.
DeepEqual
(
a
,
b
)
{
c
.
t
.
Fatal
(
"!eq:
\n
"
,
pretty
.
Compare
(
a
,
b
))
}
}
/*
type tTxnRecord struct {
tid zodb.Tid
// data records for oid changed in transaction
// .oid↑
datav []tDataRecord
}
type tDataRecord struct {
oid zodb.Oid
data []byte
}
if xid.TidBefore {
// find max txn with .tid < xid.Tid
n := len(s.txnv)
i := n - 1 - sort.Search(n, func(i int) bool {
return s.txnv[n - 1 - i].tid < xid.Tid
})
if i == -1 {
// XXX xid.Tid < all .tid - no such transaction
}
}
*/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment