Commit ce6c0ff3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0c886069
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
// //
// See COPYING file for full licensing terms. // See COPYING file for full licensing terms.
package neo package neo_test
// test interaction between nodes // test interaction between nodes
import ( import (
...@@ -25,6 +25,10 @@ import ( ...@@ -25,6 +25,10 @@ import (
"reflect" "reflect"
"testing" "testing"
. "../neo"
"../neo/client"
"../neo/server"
"../zodb" "../zodb"
"../zodb/storage/fs1" "../zodb/storage/fs1"
...@@ -32,24 +36,20 @@ import ( ...@@ -32,24 +36,20 @@ import (
) )
// xfs1stor creates new NEO storage node backed by fs1 // xfs1stor creates new NEO storage node backed by fs1
// XXX is this wrapper a good idea? // XXX is this wrapper a good idea?
func xfs1stor(net Network, path string) (*Storage, *fs1.FileStorage) { func xfs1stor(net Network, path string) (*server.Storage, *fs1.FileStorage) {
// TODO +readonly ? // TODO +readonly ?
zstor, err := fs1.Open(context.Background(), path) zstor, err := fs1.Open(context.Background(), path)
exc.Raiseif(err) exc.Raiseif(err)
return NewStorage("test cluster", "TODO master", "", net, zstor), zstor return server.NewStorage("test cluster", "TODO master", "", net, zstor), zstor
} }
// M drives cluster with 1 S through recovery -> verification -> service -> shutdown // M drives cluster with 1 S through recovery -> verification -> service -> shutdown
func TestMasterStorage(t *testing.T) { func TestMasterStorage(t *testing.T) {
net := NetPipe("") // test network FIXME New registers to global table net := NetPipe("") // test network FIXME New registers to global table
M := NewMaster("abc1") M := server.NewMaster("abc1")
S, _ := xfs1stor(net, "../zodb/storage/fs1/testdata/1.fs") // XXX +readonly S, _ := xfs1stor(net, "../zodb/storage/fs1/testdata/1.fs") // XXX +readonly
Mctx, Mcancel := context.WithCancel(context.Background()) Mctx, Mcancel := context.WithCancel(context.Background())
...@@ -59,8 +59,8 @@ func TestMasterStorage(t *testing.T) { ...@@ -59,8 +59,8 @@ func TestMasterStorage(t *testing.T) {
Sbind := ""; Mbind := ""; var err error Sbind := ""; Mbind := ""; var err error
_ = Scancel; _ = Mcancel; _ = err _ = Scancel; _ = Mcancel; _ = err
err = ListenAndServe(Mctx, net, Mbind, M) // XXX go err = server.ListenAndServe(Mctx, net, Mbind, M) // XXX go
err = ListenAndServe(Sctx, net, Sbind, S) // XXX go err = server.ListenAndServe(Sctx, net, Sbind, S) // XXX go
} }
// basic interaction between Client -- Storage // basic interaction between Client -- Storage
...@@ -77,7 +77,7 @@ func TestClientStorage(t *testing.T) { ...@@ -77,7 +77,7 @@ func TestClientStorage(t *testing.T) {
// XXX + test error return // XXX + test error return
}) })
C, err := NewClient(Cnl) C, err := client.NewClient(Cnl)
if err != nil { if err != nil {
t.Fatalf("creating/identifying client: %v", err) t.Fatalf("creating/identifying client: %v", err)
} }
......
...@@ -140,7 +140,6 @@ type NodeUUID int32 ...@@ -140,7 +140,6 @@ type NodeUUID int32
var ErrDecodeOverflow = errors.New("decode: bufer overflow") var ErrDecodeOverflow = errors.New("decode: bufer overflow")
// Pkt is the interface implemented by NEO packets to marshal/unmarshal them into/from wire format // Pkt is the interface implemented by NEO packets to marshal/unmarshal them into/from wire format
// XXX -> will be neo.Pkt after splitting into packages
type Pkt interface { type Pkt interface {
// NEOPktMsgCode returns message code needed to be used for particular packet type // NEOPktMsgCode returns message code needed to be used for particular packet type
// on the wire // on the wire
...@@ -157,25 +156,6 @@ type Pkt interface { ...@@ -157,25 +156,6 @@ type Pkt interface {
NEOPktDecode(data []byte) (nread int, err error) NEOPktDecode(data []byte) (nread int, err error)
} }
/*
// XXX do we need to keep it splitted as encoder/decoder ?
// NEOPktDecoder is the interface implemented by packets to unmarshal them from wire format
type NEOPktDecoder interface {
// NEOPktMsgCode returns message code that must have been used on the wire for this packet
NEOPktMsgCode() uint16
}
// NEOPkt is interface combining NEOPktEncoder & NEOPktDecoder
// in particular it covers all NEO packets
type NEOPkt interface {
NEOPktEncoder
NEOPktDecoder
// XXX is in both encoder and decoder
NEOPktMsgCode() uint16
}
*/
type Address struct { type Address struct {
Host string Host string
......
...@@ -69,9 +69,9 @@ func TestPktHeader(t *testing.T) { ...@@ -69,9 +69,9 @@ func TestPktHeader(t *testing.T) {
} }
// test marshalling for one packet type // test marshalling for one packet type
func testPktMarshal(t *testing.T, pkt NEOPkt, encoded string) { func testPktMarshal(t *testing.T, pkt Pkt, encoded string) {
typ := reflect.TypeOf(pkt).Elem() // type of *pkt typ := reflect.TypeOf(pkt).Elem() // type of *pkt
pkt2 := reflect.New(typ).Interface().(NEOPkt) pkt2 := reflect.New(typ).Interface().(Pkt)
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {
t.Errorf("%v: panic ↓↓↓:", typ) t.Errorf("%v: panic ↓↓↓:", typ)
...@@ -152,7 +152,7 @@ func testPktMarshal(t *testing.T, pkt NEOPkt, encoded string) { ...@@ -152,7 +152,7 @@ func testPktMarshal(t *testing.T, pkt NEOPkt, encoded string) {
// test encoding/decoding of packets // test encoding/decoding of packets
func TestPktMarshal(t *testing.T) { func TestPktMarshal(t *testing.T) {
var testv = []struct { var testv = []struct {
pkt NEOPkt pkt Pkt
encoded string // []byte encoded string // []byte
} { } {
// empty // empty
...@@ -268,7 +268,7 @@ func TestPktMarshal(t *testing.T) { ...@@ -268,7 +268,7 @@ func TestPktMarshal(t *testing.T) {
func TestPktMarshalAllOverflowLightly(t *testing.T) { func TestPktMarshalAllOverflowLightly(t *testing.T) {
for _, typ := range pktTypeRegistry { for _, typ := range pktTypeRegistry {
// zero-value for a type // zero-value for a type
pkt := reflect.New(typ).Interface().(NEOPkt) pkt := reflect.New(typ).Interface().(Pkt)
l := pkt.NEOPktEncodedLen() l := pkt.NEOPktEncodedLen()
zerol := make([]byte, l) zerol := make([]byte, l)
// decoding will turn nil slice & map into empty allocated ones. // decoding will turn nil slice & map into empty allocated ones.
......
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