Skip to content

Commit

Permalink
Get rid of redundant onUnknown response handler callback (#499)
Browse files Browse the repository at this point in the history
`hydrator#hydrate` supports only a limited number of response
message types, which are then returned to the message queue.

Co-authored-by: Rouven Bauer <[email protected]>
  • Loading branch information
fbiville and robsdedude authored May 25, 2023
1 parent e1b42c9 commit a4ee117
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 39 deletions.
14 changes: 0 additions & 14 deletions neo4j/internal/bolt/bolt4.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,9 +1014,6 @@ func (b *bolt4) discardResponseHandler(stream *stream) responseHandler {
stream.err = failure
b.onFailure(ctx, failure) // Will detach the stream
},
onUnknown: func(msg any) {
b.setError(fmt.Errorf("unknown response %v", msg), true)
},
}
}

Expand Down Expand Up @@ -1056,9 +1053,6 @@ func (b *bolt4) pullResponseHandler(stream *stream) responseHandler {
stream.err = failure
b.onFailure(ctx, failure) // will detach the stream
},
onUnknown: func(msg any) {
b.setError(fmt.Errorf("unknown response %v", msg), true)
},
}

}
Expand All @@ -1084,9 +1078,6 @@ func (b *bolt4) resetResponseHandler() responseHandler {
_ = b.onNeo4jError(ctx, b, failure)
b.state = bolt4_dead
},
onUnknown: func(any) {
b.state = bolt4_dead
},
}
}

Expand Down Expand Up @@ -1123,7 +1114,6 @@ func (b *bolt4) expectedSuccessHandler(onSuccess func(*success)) responseHandler
return responseHandler{
onSuccess: onSuccess,
onFailure: b.onFailure,
onUnknown: b.onUnknown,
onIgnored: onIgnoredNoOp,
}
}
Expand All @@ -1145,10 +1135,6 @@ func (b *bolt4) onFailure(ctx context.Context, failure *db.Neo4jError) {
b.setError(err, isFatalError(failure))
}

func (b *bolt4) onUnknown(msg any) {
b.setError(fmt.Errorf("expected success or database error, got %v", msg), true)
}

const readTimeoutHintName = "connection.recv_timeout_seconds"

func (b *bolt4) initializeReadTimeoutHint(hints map[string]any) {
Expand Down
14 changes: 0 additions & 14 deletions neo4j/internal/bolt/bolt5.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,9 +1015,6 @@ func (b *bolt5) discardResponseHandler(stream *stream) responseHandler {
stream.err = failure
b.onFailure(ctx, failure) // Will detach the stream
},
onUnknown: func(msg any) {
b.setError(fmt.Errorf("unknown response %v", msg), true)
},
}
}

Expand Down Expand Up @@ -1057,9 +1054,6 @@ func (b *bolt5) pullResponseHandler(stream *stream) responseHandler {
stream.err = failure
b.onFailure(ctx, failure) // Will detach the stream
},
onUnknown: func(msg any) {
b.setError(fmt.Errorf("unknown response %v", msg), true)
},
}
}

Expand All @@ -1072,17 +1066,13 @@ func (b *bolt5) resetResponseHandler() responseHandler {
_ = b.onNeo4jError(ctx, b, failure)
b.state = bolt5Dead
},
onUnknown: func(any) {
b.state = bolt5Dead
},
}
}

func (b *bolt5) expectedSuccessHandler(onSuccess func(*success)) responseHandler {
return responseHandler{
onSuccess: onSuccess,
onFailure: b.onFailure,
onUnknown: b.onUnknown,
onIgnored: onIgnoredNoOp,
}
}
Expand Down Expand Up @@ -1120,10 +1110,6 @@ func (b *bolt5) onFailure(ctx context.Context, failure *db.Neo4jError) {
b.setError(err, isFatalError(failure))
}

func (b *bolt5) onUnknown(msg any) {
b.setError(fmt.Errorf("expected success or database error, got %v", msg), true)
}

func (b *bolt5) initializeReadTimeoutHint(hints map[string]any) {
readTimeoutHint, ok := hints[readTimeoutHintName]
if !ok {
Expand Down
6 changes: 1 addition & 5 deletions neo4j/internal/bolt/message_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ func (q *messageQueue) receive(ctx context.Context) error {
}
onIgnored(message)
default:
onUnknown := handler.onUnknown
if onUnknown == nil {
return fmt.Errorf("protocol violation: the server sent an unknown %v response", message)
}
onUnknown(message)
panic(fmt.Errorf("did not expect message %v", res))
}
return nil
}
Expand Down
7 changes: 2 additions & 5 deletions neo4j/internal/bolt/message_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func TestMessageQueue(outer *testing.T) {
msgHello: {onSuccess: func(*success) {}},
msgLogon: {onFailure: func(context.Context, *db.Neo4jError) {}},
msgRoute: {onIgnored: func(*ignored) {}},
msgBegin: {onUnknown: func(any) {}},
msgBegin: {onSuccess: func(*success) {}},
msgRun: {onRecord: func(*db.Record) {}},
msgPullN: {onSuccess: func(*success) {}},
msgCommit: {onFailure: func(context.Context, *db.Neo4jError) {}},
msgRollback: {onIgnored: func(*ignored) {}},
msgDiscardN: {onUnknown: func(any) {}},
msgDiscardN: {onSuccess: func(*success) {}},
msgReset: {onRecord: func(*db.Record) {}},
msgGoodbye: {onSuccess: func(*success) {}},
}
Expand Down Expand Up @@ -311,9 +311,6 @@ func assertEqualResponseHandlers(t *testing.T, handler1, handler2 responseHandle
if !functionEqual(handler1.onFailure, handler2.onFailure) {
t.Errorf("expected onFailure callbacks to be equal")
}
if !functionEqual(handler1.onUnknown, handler2.onUnknown) {
t.Errorf("expected onUnknown callbacks to be equal")
}
}

func functionEqual(func1, func2 any) bool {
Expand Down
1 change: 0 additions & 1 deletion neo4j/internal/bolt/response_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type responseHandler struct {
onSuccess func(*success)
onRecord func(*db.Record)
onFailure func(context.Context, *db.Neo4jError)
onUnknown func(any)
onIgnored func(*ignored)
}

Expand Down

0 comments on commit a4ee117

Please sign in to comment.