Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
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
Stefane Fermigier
neo
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
Hide 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) {
...
@@ -61,7 +61,7 @@ func (c *Client) LastTid() (zodb.Tid, error) {
switch
reply
:=
reply
.
(
type
)
{
switch
reply
:=
reply
.
(
type
)
{
case
*
Error
:
case
*
Error
:
return
0
,
reply
// XXX err context
return
0
,
errDecode
(
reply
)
// XXX err context
default
:
default
:
// XXX more error context ?
// XXX more error context ?
return
0
,
fmt
.
Errorf
(
"protocol error: unexpected reply: %T"
,
reply
)
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) {
...
@@ -95,7 +95,7 @@ func (c *Client) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
switch
reply
:=
reply
.
(
type
)
{
switch
reply
:=
reply
.
(
type
)
{
case
*
Error
:
case
*
Error
:
return
nil
,
0
,
reply
// XXX err context
return
nil
,
0
,
errDecode
(
reply
)
// XXX err context
default
:
default
:
// XXX more error context ?
// XXX more error context ?
return
nil
,
0
,
fmt
.
Errorf
(
"protocol error: unexpected reply: %T"
,
reply
)
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
...
@@ -19,7 +19,10 @@ package neo
// test interaction between nodes
// test interaction between nodes
import
(
import
(
"bytes"
"context"
"context"
"io"
"reflect"
"testing"
"testing"
"../zodb"
"../zodb"
...
@@ -65,7 +68,7 @@ func TestClientStorage(t *testing.T) {
...
@@ -65,7 +68,7 @@ func TestClientStorage(t *testing.T) {
ziter
:=
zstor
.
Iterate
(
zodb
.
Tid
(
0
),
zodb
.
TidMax
)
ziter
:=
zstor
.
Iterate
(
zodb
.
Tid
(
0
),
zodb
.
TidMax
)
for
{
for
{
txni
,
dataIter
,
err
:=
ziter
.
NextTxn
()
_
,
dataIter
,
err
:=
ziter
.
NextTxn
()
if
err
==
io
.
EOF
{
if
err
==
io
.
EOF
{
break
break
}
}
...
@@ -73,8 +76,6 @@ func TestClientStorage(t *testing.T) {
...
@@ -73,8 +76,6 @@ func TestClientStorage(t *testing.T) {
t
.
Fatalf
(
"ziter.NextTxn: %v"
,
err
)
t
.
Fatalf
(
"ziter.NextTxn: %v"
,
err
)
}
}
txni
.
Tid
for
{
for
{
datai
,
err
:=
dataIter
.
NextData
()
datai
,
err
:=
dataIter
.
NextData
()
if
err
==
io
.
EOF
{
if
err
==
io
.
EOF
{
...
@@ -84,15 +85,30 @@ func TestClientStorage(t *testing.T) {
...
@@ -84,15 +85,30 @@ func TestClientStorage(t *testing.T) {
t
.
Fatalf
(
"ziter.NextData: %v"
,
err
)
t
.
Fatalf
(
"ziter.NextData: %v"
,
err
)
}
}
datai
.
Oid
for
_
,
tidBefore
:=
range
[]
bool
{
false
,
true
}
{
datai
.
Tid
xid
:=
zodb
.
Xid
{
Oid
:
datai
.
Oid
}
// {=,<}tid:oid
.
Data
xid
.
Tid
=
datai
.
Tid
.
DataTid
xid
.
TidBefore
=
tidBefore
if
tidBefore
{
// XXX .Data = nil means deleted
xid
.
Tid
++
}
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) {
...
@@ -98,6 +98,37 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
// TODO wait all spawned serveConn
// 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
// ServeClient serves incoming connection on which peer identified itself as client
// XXX +error return?
// XXX +error return?
func
(
stor
*
Storage
)
ServeClient
(
ctx
context
.
Context
,
conn
*
Conn
)
{
func
(
stor
*
Storage
)
ServeClient
(
ctx
context
.
Context
,
conn
*
Conn
)
{
...
@@ -141,7 +172,7 @@ 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
)
data
,
tid
,
err
:=
stor
.
zstor
.
Load
(
xid
)
if
err
!=
nil
{
if
err
!=
nil
{
// TODO translate err to NEO protocol error codes
// TODO translate err to NEO protocol error codes
reply
=
&
Error
{
Code
:
0
,
Message
:
err
.
Error
()}
// XXX Code
reply
=
errEncode
(
err
)
}
else
{
}
else
{
reply
=
&
AnswerGetObject
{
reply
=
&
AnswerGetObject
{
Oid
:
xid
.
Oid
,
Oid
:
xid
.
Oid
,
...
@@ -163,7 +194,7 @@ func (stor *Storage) ServeClient(ctx context.Context, conn *Conn) {
...
@@ -163,7 +194,7 @@ func (stor *Storage) ServeClient(ctx context.Context, conn *Conn) {
lastTid
,
err
:=
stor
.
zstor
.
LastTid
()
lastTid
,
err
:=
stor
.
zstor
.
LastTid
()
if
err
!=
nil
{
if
err
!=
nil
{
reply
=
&
Error
{
Code
:
0
,
Message
:
err
.
Error
()}
reply
=
errEncode
(
err
)
}
else
{
}
else
{
reply
=
&
AnswerLastTransaction
{
lastTid
}
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