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
a95287ab
Commit
a95287ab
authored
May 03, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X draft tests for Load via Client -- Storage
parent
cb2ce72c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
15 deletions
+62
-15
go/neo/client.go
go/neo/client.go
+2
-2
go/neo/cluster_test.go
go/neo/cluster_test.go
+27
-11
go/neo/storage.go
go/neo/storage.go
+33
-2
No files found.
go/neo/client.go
View file @
a95287ab
...
...
@@ -61,7 +61,7 @@ func (c *Client) LastTid() (zodb.Tid, error) {
switch
reply
:=
reply
.
(
type
)
{
case
*
Error
:
return
0
,
reply
// XXX err context
return
0
,
errDecode
(
reply
)
// XXX err context
default
:
// XXX more error context ?
return
0
,
fmt
.
Errorf
(
"protocol error: unexpected reply: %T"
,
reply
)
...
...
@@ -95,7 +95,7 @@ func (c *Client) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
switch
reply
:=
reply
.
(
type
)
{
case
*
Error
:
return
nil
,
0
,
reply
// XXX err context
return
nil
,
0
,
errDecode
(
reply
)
// XXX err context
default
:
// XXX more error context ?
return
nil
,
0
,
fmt
.
Errorf
(
"protocol error: unexpected reply: %T"
,
reply
)
...
...
go/neo/cluster_test.go
View file @
a95287ab
...
...
@@ -19,7 +19,10 @@ package neo
// test interaction between nodes
import
(
"bytes"
"context"
"io"
"reflect"
"testing"
"../zodb"
...
...
@@ -65,7 +68,7 @@ func TestClientStorage(t *testing.T) {
ziter
:=
zstor
.
Iterate
(
zodb
.
Tid
(
0
),
zodb
.
TidMax
)
for
{
txni
,
dataIter
,
err
:=
ziter
.
NextTxn
()
_
,
dataIter
,
err
:=
ziter
.
NextTxn
()
if
err
==
io
.
EOF
{
break
}
...
...
@@ -73,8 +76,6 @@ func TestClientStorage(t *testing.T) {
t
.
Fatalf
(
"ziter.NextTxn: %v"
,
err
)
}
txni
.
Tid
for
{
datai
,
err
:=
dataIter
.
NextData
()
if
err
==
io
.
EOF
{
...
...
@@ -84,15 +85,30 @@ func TestClientStorage(t *testing.T) {
t
.
Fatalf
(
"ziter.NextData: %v"
,
err
)
}
datai
.
Oid
datai
.
Tid
.
Data
.
DataTid
for
_
,
tidBefore
:=
range
[]
bool
{
false
,
true
}
{
xid
:=
zodb
.
Xid
{
Oid
:
datai
.
Oid
}
// {=,<}tid:oid
xid
.
Tid
=
datai
.
Tid
xid
.
TidBefore
=
tidBefore
if
tidBefore
{
xid
.
Tid
++
}
// XXX .Data = nil means deleted
data
,
tid
,
err
:=
C
.
Load
(
xid
)
if
datai
.
Data
!=
nil
{
if
!
(
bytes
.
Equal
(
data
,
datai
.
Data
)
&&
tid
==
datai
.
Tid
&&
err
==
nil
)
{
t
.
Fatalf
(
"load: %v:
\n
have: %v %v %q
\n
want: %v nil %q"
,
xid
,
tid
,
err
,
data
,
datai
.
Tid
,
datai
.
Data
)
}
}
else
{
// deleted
errWant
:=
&
zodb
.
ErrXidMissing
{
xid
}
if
!
(
data
==
nil
&&
tid
==
0
&&
reflect
.
DeepEqual
(
err
,
errWant
))
{
t
.
Fatalf
(
"load: %v:
\n
have: %v, %#v, %#v
\n
want: %v, %#v, %#v"
,
xid
,
tid
,
err
,
data
,
zodb
.
Tid
(
0
),
errWant
,
[]
byte
(
nil
))
}
}
}
zodb
.
Xid
{
zodb
.
XTid
{
datai
.
Tid
,
false
},
datai
.
Oid
}
// =tid:oid
// TODO check Load
}
}
...
...
go/neo/storage.go
View file @
a95287ab
...
...
@@ -98,6 +98,37 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
// TODO wait all spawned serveConn
}
// XXX move err{Encode,Decode} out of here
// errEncode translates an error into Error packet
func
errEncode
(
err
error
)
*
Error
{
switch
err
:=
err
.
(
type
)
{
case
*
Error
:
return
err
case
*
zodb
.
ErrXidMissing
:
// XXX abusing message for xid
return
&
Error
{
Code
:
OID_NOT_FOUND
,
Message
:
err
.
Xid
.
String
()}
default
:
return
&
Error
{
Code
:
BROKEN_NODE
,
Message
:
err
.
Error
()}
}
}
// errDecode decodes error from Error packet
func
errDecode
(
e
*
Error
)
error
{
switch
e
.
Code
{
case
OID_NOT_FOUND
:
xid
,
err
:=
zodb
.
ParseXid
(
e
.
Message
)
// XXX abusing message for xid
if
err
==
nil
{
return
&
zodb
.
ErrXidMissing
{
xid
}
}
}
return
e
}
// ServeClient serves incoming connection on which peer identified itself as client
// XXX +error return?
func
(
stor
*
Storage
)
ServeClient
(
ctx
context
.
Context
,
conn
*
Conn
)
{
...
...
@@ -141,7 +172,7 @@ func (stor *Storage) ServeClient(ctx context.Context, conn *Conn) {
data
,
tid
,
err
:=
stor
.
zstor
.
Load
(
xid
)
if
err
!=
nil
{
// TODO translate err to NEO protocol error codes
reply
=
&
Error
{
Code
:
0
,
Message
:
err
.
Error
()}
// XXX Code
reply
=
errEncode
(
err
)
}
else
{
reply
=
&
AnswerGetObject
{
Oid
:
xid
.
Oid
,
...
...
@@ -163,7 +194,7 @@ func (stor *Storage) ServeClient(ctx context.Context, conn *Conn) {
lastTid
,
err
:=
stor
.
zstor
.
LastTid
()
if
err
!=
nil
{
reply
=
&
Error
{
Code
:
0
,
Message
:
err
.
Error
()}
reply
=
errEncode
(
err
)
}
else
{
reply
=
&
AnswerLastTransaction
{
lastTid
}
}
...
...
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