Search in sources :

Example 31 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class SocketTransportHandlerTest method shouldCloseProtocolOnHandlerRemoved.

@Test
public void shouldCloseProtocolOnHandlerRemoved() throws Throwable {
    // Given
    BoltStateMachine machine = mock(BoltStateMachine.class);
    ChannelHandlerContext ctx = channelHandlerContextMock();
    SocketTransportHandler handler = newSocketTransportHandler(protocolChooser(machine));
    // And Given a session has been established
    handler.channelRead(ctx, handshake());
    // When
    handler.handlerRemoved(ctx);
    // Then
    verify(machine).close();
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Test(org.junit.Test)

Example 32 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltConnectionIT method shouldCloseConnectionResetBeforeInit.

@Test
public void shouldCloseConnectionResetBeforeInit() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    // when
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.reset(recorder));
    // then
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Request.Invalid));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 33 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltConnectionIT method shouldAllowUserControlledRollbackOnExplicitTxFailure.

@Test
public void shouldAllowUserControlledRollbackOnExplicitTxFailure() throws Throwable {
    // Given whenever en explicit transaction has a failure,
    // it is more natural for drivers to see the failure, acknowledge it
    // and send a `ROLLBACK`, because that means that all failures in the
    // transaction, be they client-local or inside neo, can be handled the
    // same way by a driver.
    BoltStateMachine machine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("bolt-test", 56789), new InetSocketAddress("test-server", 7468)));
    machine.init(USER_AGENT, emptyMap(), null);
    machine.run("BEGIN", EMPTY_PARAMS, nullResponseHandler());
    machine.discardAll(nullResponseHandler());
    machine.run("CREATE (n:Victim)-[:REL]->()", EMPTY_PARAMS, nullResponseHandler());
    machine.discardAll(nullResponseHandler());
    // When I perform an action that will fail
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("this is not valid syntax", EMPTY_PARAMS, recorder);
    // Then I should see a failure
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Statement.SyntaxError));
    // And when I acknowledge that failure, and roll back the transaction
    recorder.reset();
    machine.ackFailure(recorder);
    machine.run("ROLLBACK", EMPTY_PARAMS, recorder);
    // Then both operations should succeed
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltConnectionDescriptor(org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) InetSocketAddress(java.net.InetSocketAddress) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 34 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltConnectionIT method shouldExecuteStatement.

@Test
public void shouldExecuteStatement() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS, recorder);
    // Then
    assertThat(recorder.nextResponse(), succeeded());
    // When
    recorder.reset();
    machine.pullAll(recorder);
    // Then
    recorder.nextResponse().assertRecord(0, "k");
//assertThat( pulling.next(), streamContaining( StreamMatchers.eqRecord( equalTo( "k" ) ) ) );
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 35 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltConnectionIT method shouldFailOn__pullAll__discardAll.

@Test
public void shouldFailOn__pullAll__discardAll() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // And Given that I've ran and pulled one stream
    machine.run("RETURN 1", EMPTY_PARAMS, nullResponseHandler());
    machine.pullAll(nullResponseHandler());
    // When I attempt to pull more items from the stream
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.discardAll(recorder));
    // Then
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Request.Invalid));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Aggregations

BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)49 Test (org.junit.Test)43 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)31 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 HashMap (java.util.HashMap)4 SocketTransportHandler (org.neo4j.bolt.transport.SocketTransportHandler)4 BoltConnectionFatality (org.neo4j.bolt.v1.runtime.BoltConnectionFatality)4 SynchronousBoltWorker (org.neo4j.bolt.v1.runtime.SynchronousBoltWorker)4 ByteBuf (io.netty.buffer.ByteBuf)3 Channel (io.netty.channel.Channel)3 InetSocketAddress (java.net.InetSocketAddress)3 BaseMatcher (org.hamcrest.BaseMatcher)3 Description (org.hamcrest.Description)3 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)3 Record (org.neo4j.bolt.v1.runtime.spi.Record)3 ProtocolChooser (org.neo4j.bolt.transport.ProtocolChooser)2 BoltResponseHandler (org.neo4j.bolt.v1.runtime.BoltResponseHandler)2 StatementProcessor (org.neo4j.bolt.v1.runtime.StatementProcessor)2 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)2 BoltProtocolV1 (org.neo4j.bolt.v1.transport.BoltProtocolV1)2