Skip to content

Commit

Permalink
Merge pull request #32 from ali-ince/1.7-update-signature-size
Browse files Browse the repository at this point in the history
Update struct signature sizes
  • Loading branch information
ali-ince authored Oct 25, 2018
2 parents dcd86b4 + fc06a33 commit 520f8ab
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 151 deletions.
22 changes: 0 additions & 22 deletions neo4j/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ type Config struct {
//
// default: 5 * time.Second
SocketConnectTimeout time.Duration
// Receive timeout that will be set on underlying sockets. Values less than
// or equal to 0 results in no timeout being applied.
//
// default: 0
SocketReceiveTimeout time.Duration
// Send timeout that will be set on underlying sockets. Values less than
// or equal to 0 results in no timeout being applied.
//
// default: 0
SocketSendTimeout time.Duration
// Whether to enable TCP keep alive on underlying sockets.
//
// default: true
Expand All @@ -102,8 +92,6 @@ func defaultConfig() *Config {
MaxConnectionLifetime: 1 * time.Hour,
ConnectionAcquisitionTimeout: 1 * time.Minute,
SocketConnectTimeout: 5 * time.Second,
SocketReceiveTimeout: 0 * time.Second,
SocketSendTimeout: 0 * time.Second,
SocketKeepalive: true,
}
}
Expand Down Expand Up @@ -138,15 +126,5 @@ func validateAndNormaliseConfig(config *Config) error {
config.SocketConnectTimeout = 0
}

// Socket Receive Timeout
if config.SocketReceiveTimeout < 0 {
config.SocketReceiveTimeout = 0
}

// Socket Send Timeout
if config.SocketSendTimeout < 0 {
config.SocketSendTimeout = 0
}

return nil
}
28 changes: 0 additions & 28 deletions neo4j/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ var _ = Describe("Config", func() {
Expect(config.SocketConnectTimeout).To(BeIdenticalTo(5 * time.Second))
})

It("should have socket receive timeout to be 0", func() {
Expect(config.SocketReceiveTimeout).To(BeIdenticalTo(0 * time.Second))
})

It("should have socket send timeout to be 0", func() {
Expect(config.SocketSendTimeout).To(BeIdenticalTo(0 * time.Second))
})

It("should have socket keep alive enabled", func() {
Expect(config.SocketKeepalive).To(BeTrue())
})
Expand Down Expand Up @@ -131,26 +123,6 @@ var _ = Describe("Config", func() {

Expect(config.SocketConnectTimeout).To(Equal(0 * time.Nanosecond))
})

It("should normalize SocketReceiveTimeout to 0 when negative", func() {
config := defaultConfig()
config.SocketReceiveTimeout = -1 * time.Second

err := validateAndNormaliseConfig(config)
Expect(err).To(BeNil())

Expect(config.SocketReceiveTimeout).To(Equal(0 * time.Nanosecond))
})

It("should normalize SocketSendTimeout to 0 when negative", func() {
config := defaultConfig()
config.SocketSendTimeout = -1 * time.Second

err := validateAndNormaliseConfig(config)
Expect(err).To(BeNil())

Expect(config.SocketSendTimeout).To(Equal(0 * time.Nanosecond))
})
})

})
4 changes: 2 additions & 2 deletions neo4j/gobolt_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func configToGoboltConfig(config *Config) *gobolt.Config {
MaxConnLifetime: config.MaxConnectionLifetime,
ConnAcquisitionTimeout: config.ConnectionAcquisitionTimeout,
SockConnectTimeout: config.SocketConnectTimeout,
SockRecvTimeout: config.SocketReceiveTimeout,
SockSendTimeout: config.SocketSendTimeout,
SockRecvTimeout: 0,
SockSendTimeout: 0,
SockKeepalive: config.SocketKeepalive,
ValueHandlers: []gobolt.ValueHandler{
&nodeValueHandler{},
Expand Down
1 change: 0 additions & 1 deletion neo4j/test-integration/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ func createDriverWithConnectionTimeout(uri, username, password string) (neo4j.Dr
func createDriverWithMaxRetryTime(uri, username, password string) (neo4j.Driver, error) {
return neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""), func(config *neo4j.Config) {
config.MaxTransactionRetryTime = 15 * time.Second
config.Log = neo4j.ConsoleLogger(neo4j.DEBUG)
})
}

Expand Down
49 changes: 0 additions & 49 deletions neo4j/test-integration/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,53 +114,4 @@ var _ = Describe("Timeout and Lifetime", func() {
Expect(err).To(test.BeConnectorErrorWithCode(6))
})

//It("should timeout receive when SocketReceiveTimeout is hit on encrypted connection", func() {
// var err error
// var driver neo4j.Driver
// var session neo4j.Session
// var result neo4j.Result
//
// driver, err = neo4j.NewDriver(server.BoltURI(), server.AuthToken(), server.Config(), func(config *neo4j.Config) {
// config.Log = log
// config.SocketReceiveTimeout = 1 * time.Second
// })
// Expect(err).To(BeNil())
// Expect(driver).NotTo(BeNil())
// defer driver.Close()
//
// session = newSession(driver, neo4j.AccessModeRead)
// defer session.Close()
//
// result, err = session.Run("UNWIND RANGE(1,100000000) AS N RETURN SUM(N)", nil)
// Expect(err).To(BeNil())
//
// _, err = result.Consume()
// Expect(err).To(test.BeConnectorErrorWithCode(6))
//})

It("should timeout receive when SocketReceiveTimeout is hit on plaintext connection", func() {
var err error
var driver neo4j.Driver
var session neo4j.Session
var result neo4j.Result

driver, err = neo4j.NewDriver(server.BoltURI(), server.AuthToken(), server.Config(), func(config *neo4j.Config) {
config.Encrypted = false
config.Log = log
config.SocketReceiveTimeout = 1 * time.Second
})
Expect(err).To(BeNil())
Expect(driver).NotTo(BeNil())
defer driver.Close()

session = newSession(driver, neo4j.AccessModeRead)
defer session.Close()

result, err = session.Run("UNWIND RANGE(1,100000000) AS N RETURN SUM(N)", nil)
Expect(err).To(BeNil())

_, err = result.Consume()
Expect(err).To(test.BeConnectorErrorWithCode(6))
})

})
24 changes: 12 additions & 12 deletions neo4j/values_graph_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ type relationshipValueHandler struct {
type pathValueHandler struct {
}

func (handler *nodeValueHandler) ReadableStructs() []int8 {
return []int8{'N'}
func (handler *nodeValueHandler) ReadableStructs() []int16 {
return []int16{'N'}
}

func (handler *nodeValueHandler) WritableTypes() []reflect.Type {
return []reflect.Type(nil)
}

func (handler *nodeValueHandler) Read(signature int8, values []interface{}) (interface{}, error) {
func (handler *nodeValueHandler) Read(signature int16, values []interface{}) (interface{}, error) {
if len(values) != 3 {
return nil, gobolt.NewValueHandlerError("expected node struct to have %d fields but received %d", 3, len(values))
}
Expand All @@ -64,19 +64,19 @@ func (handler *nodeValueHandler) Read(signature int8, values []interface{}) (int
}, nil
}

func (handler *nodeValueHandler) Write(value interface{}) (int8, []interface{}, error) {
func (handler *nodeValueHandler) Write(value interface{}) (int16, []interface{}, error) {
return 0, nil, gobolt.NewValueHandlerError("Write is not supported for node values")
}

func (handler *relationshipValueHandler) ReadableStructs() []int8 {
return []int8{'R', 'r'}
func (handler *relationshipValueHandler) ReadableStructs() []int16 {
return []int16{'R', 'r'}
}

func (handler *relationshipValueHandler) WritableTypes() []reflect.Type {
return []reflect.Type(nil)
}

func (handler *relationshipValueHandler) Read(signature int8, values []interface{}) (interface{}, error) {
func (handler *relationshipValueHandler) Read(signature int16, values []interface{}) (interface{}, error) {
if signature == 'R' {
if len(values) != 5 {
return nil, gobolt.NewValueHandlerError("expected relationship struct to have %d fields but received %d", 5, len(values))
Expand Down Expand Up @@ -114,19 +114,19 @@ func (handler *relationshipValueHandler) Read(signature int8, values []interface
}, nil
}

func (handler *relationshipValueHandler) Write(value interface{}) (int8, []interface{}, error) {
func (handler *relationshipValueHandler) Write(value interface{}) (int16, []interface{}, error) {
return 0, nil, gobolt.NewValueHandlerError("Write is not supported for relationship values")
}

func (handler *pathValueHandler) ReadableStructs() []int8 {
return []int8{'P'}
func (handler *pathValueHandler) ReadableStructs() []int16 {
return []int16{'P'}
}

func (handler *pathValueHandler) WritableTypes() []reflect.Type {
return []reflect.Type(nil)
}

func (handler *pathValueHandler) Read(signature int8, values []interface{}) (interface{}, error) {
func (handler *pathValueHandler) Read(signature int16, values []interface{}) (interface{}, error) {
if len(values) != 3 {
return nil, gobolt.NewValueHandlerError("expected path struct to have %d fields but received %d", 3, len(values))
}
Expand Down Expand Up @@ -179,6 +179,6 @@ func (handler *pathValueHandler) Read(signature int8, values []interface{}) (int
return &pathValue{segments: segments, nodes: nodes, relationships: rels}, nil
}

func (handler *pathValueHandler) Write(value interface{}) (int8, []interface{}, error) {
func (handler *pathValueHandler) Write(value interface{}) (int16, []interface{}, error) {
return 0, nil, gobolt.NewValueHandlerError("Write is not supported for path values")
}
12 changes: 6 additions & 6 deletions neo4j/values_spatial_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ import (
)

const (
point2DSignature int8 = 'X'
point2DSignature int16 = 'X'
point2DSize = 3
point3DSignature int8 = 'Y'
point3DSignature int16 = 'Y'
point3DSize = 4
)

type pointValueHandler struct {
}

func (handler *pointValueHandler) ReadableStructs() []int8 {
return []int8{point2DSignature, point3DSignature}
func (handler *pointValueHandler) ReadableStructs() []int16 {
return []int16{point2DSignature, point3DSignature}
}

func (handler *pointValueHandler) WritableTypes() []reflect.Type {
return []reflect.Type{reflect.TypeOf(Point{}), reflect.TypeOf(&Point{})}
}

func (handler *pointValueHandler) Read(signature int8, values []interface{}) (interface{}, error) {
func (handler *pointValueHandler) Read(signature int16, values []interface{}) (interface{}, error) {
var (
dimension int
srId int
Expand Down Expand Up @@ -85,7 +85,7 @@ func (handler *pointValueHandler) Read(signature int8, values []interface{}) (in
}, nil
}

func (handler *pointValueHandler) Write(value interface{}) (int8, []interface{}, error) {
func (handler *pointValueHandler) Write(value interface{}) (int16, []interface{}, error) {
var point *Point
var ok bool

Expand Down
Loading

0 comments on commit 520f8ab

Please sign in to comment.