Search in sources :

Example 11 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class BoltRequestMessageReaderV43 method buildDecoders.

private static List<RequestMessageDecoder> buildDecoders(BoltConnection connection, BoltResponseMessageWriter responseMessageWriter, BookmarksParser bookmarksParser, LogService logService) {
    BoltResponseHandler resultHandler = new ResultHandler(responseMessageWriter, connection, internalLog(logService));
    BoltResponseHandler defaultHandler = newSimpleResponseHandler(responseMessageWriter, connection, logService);
    return Arrays.asList(new HelloMessageDecoder(defaultHandler), new RunMessageDecoder(defaultHandler, bookmarksParser), new DiscardMessageDecoder(resultHandler), new PullMessageDecoder(resultHandler), new BeginMessageDecoder(defaultHandler, bookmarksParser), new CommitMessageDecoder(resultHandler), new RollbackMessageDecoder(resultHandler), new ResetMessageDecoder(connection, defaultHandler), new GoodbyeMessageDecoder(connection, defaultHandler), // New in 4.3
    new RouteMessageDecoder(defaultHandler, bookmarksParser));
}
Also used : DiscardMessageDecoder(org.neo4j.bolt.v4.messaging.DiscardMessageDecoder) RollbackMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.RollbackMessageDecoder) HelloMessageDecoder(org.neo4j.bolt.v41.messaging.decoder.HelloMessageDecoder) GoodbyeMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.GoodbyeMessageDecoder) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) ResetMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.ResetMessageDecoder) RouteMessageDecoder(org.neo4j.bolt.v43.messaging.decoder.RouteMessageDecoder) ResultHandler(org.neo4j.bolt.v3.messaging.ResultHandler) CommitMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.CommitMessageDecoder) PullMessageDecoder(org.neo4j.bolt.v4.messaging.PullMessageDecoder) BeginMessageDecoder(org.neo4j.bolt.v4.messaging.BeginMessageDecoder) RunMessageDecoder(org.neo4j.bolt.v4.messaging.RunMessageDecoder)

Example 12 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class BoltRequestMessageReaderTest method shouldHandleErrorThatCausesFailureMessage.

@Test
void shouldHandleErrorThatCausesFailureMessage() throws Exception {
    Unpacker unpacker = mock(Unpacker.class);
    BoltIOException error = new BoltIOException(Status.General.UnknownError, "Hello");
    when(unpacker.unpackStructHeader()).thenThrow(error);
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    BoltConnection connection = new SynchronousBoltConnection(stateMachine);
    BoltResponseHandler externalErrorResponseHandler = responseHandlerMock();
    BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, externalErrorResponseHandler, emptyList(), mock(ChannelProtector.class));
    reader.read(unpacker);
    verify(stateMachine).handleExternalFailure(Neo4jError.from(error), externalErrorResponseHandler);
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) Unpacker(org.neo4j.bolt.packstream.Neo4jPack.Unpacker) Test(org.junit.jupiter.api.Test)

Example 13 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class BoltRequestMessageReaderTest method shouldDecodeKnownMessage.

@Test
void shouldDecodeKnownMessage() throws Exception {
    Unpacker unpacker = mock(Unpacker.class);
    when(unpacker.unpackStructSignature()).thenReturn('a');
    RequestMessage message = mock(RequestMessage.class);
    BoltResponseHandler responseHandler = responseHandlerMock();
    RequestMessageDecoder decoder = new TestRequestMessageDecoder('a', responseHandler, message);
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    BoltConnection connection = new SynchronousBoltConnection(stateMachine);
    BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, responseHandlerMock(), singletonList(decoder), mock(ChannelProtector.class));
    reader.read(unpacker);
    verify(stateMachine).process(message, responseHandler);
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) Unpacker(org.neo4j.bolt.packstream.Neo4jPack.Unpacker) Test(org.junit.jupiter.api.Test)

Example 14 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class BoltRequestMessageReaderV4 method buildDecoders.

private static List<RequestMessageDecoder> buildDecoders(BoltConnection connection, BoltResponseMessageWriter responseMessageWriter, BookmarksParser bookmarksParser, LogService logService) {
    BoltResponseHandler resultHandler = new ResultHandler(responseMessageWriter, connection, internalLog(logService));
    BoltResponseHandler defaultHandler = newSimpleResponseHandler(responseMessageWriter, connection, logService);
    return Arrays.asList(new HelloMessageDecoder(defaultHandler), // New
    new RunMessageDecoder(defaultHandler, bookmarksParser), // New
    new DiscardMessageDecoder(resultHandler), // New
    new PullMessageDecoder(resultHandler), // New
    new BeginMessageDecoder(defaultHandler, bookmarksParser), new CommitMessageDecoder(resultHandler), new RollbackMessageDecoder(resultHandler), new ResetMessageDecoder(connection, defaultHandler), new GoodbyeMessageDecoder(connection, defaultHandler));
}
Also used : RollbackMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.RollbackMessageDecoder) HelloMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.HelloMessageDecoder) GoodbyeMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.GoodbyeMessageDecoder) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) ResetMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.ResetMessageDecoder) ResultHandler(org.neo4j.bolt.v3.messaging.ResultHandler) CommitMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.CommitMessageDecoder)

Example 15 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll.

@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll() throws Throwable {
    // Given
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onDiscardRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
    BoltStateMachine machine = init(newMachine());
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // We assume the only implementation of statement processor is TransactionStateMachine
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    // When & Then
    try {
        machine.process(BoltV4Messages.discardAll(), responseHandler);
        fail("Exception expected");
    } catch (BoltConnectionAuthFatality e) {
        assertEquals("Auth expired!", e.getCause().getMessage());
    }
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Aggregations

BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)20 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)10 Test (org.junit.jupiter.api.Test)8 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 CommitMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.CommitMessageDecoder)4 GoodbyeMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.GoodbyeMessageDecoder)4 ResetMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.ResetMessageDecoder)4 RollbackMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.RollbackMessageDecoder)4 FailedState (org.neo4j.bolt.v4.runtime.FailedState)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)3 BoltStateMachineV3 (org.neo4j.bolt.v3.BoltStateMachineV3)3 ResultHandler (org.neo4j.bolt.v3.messaging.ResultHandler)3 Unpacker (org.neo4j.bolt.packstream.Neo4jPack.Unpacker)2 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)2 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)2 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)2 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)2 HelloMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.HelloMessageDecoder)2