Search in sources :

Example 6 with BoltStateMachine

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

the class BoltStateMachineTest method testPublishingError.

@Test
public void testPublishingError() throws Throwable {
    // Given a new ready machine...
    BoltStateMachine machine = newMachine(READY);
    // ...and a result ready to be retrieved...
    machine.run("RETURN 1", null, nullResponseHandler());
    // ...and a handler guaranteed to break
    BoltResponseRecorder recorder = new BoltResponseRecorder() {

        @Override
        public void onRecords(BoltResult result, boolean pull) throws Exception {
            throw new RuntimeException("I've been expecting you, Mr Bond.");
        }
    };
    // When we pull using that handler
    machine.pullAll(recorder);
    // Then the breakage should surface as a FAILURE
    assertThat(recorder.nextResponse(), failedWithStatus(Status.General.UnknownError));
    // ...and the machine should have entered a FAILED state
    assertThat(machine, inState(FAILED));
}
Also used : BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) BoltResult(org.neo4j.bolt.v1.runtime.spi.BoltResult) Test(org.junit.Test)

Example 7 with BoltStateMachine

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

the class BoltConnectionAuthIT method shouldCloseConnectionAfterAuthenticationFailure.

@Test
public void shouldCloseConnectionAfterAuthenticationFailure() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    // When... then
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "j4oen"), recorder));
    // ...and
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Security.Unauthorized));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 8 with BoltStateMachine

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

the class BoltConnectionIT method shouldSucceedOn__run__pullAll__run.

@Test
public void shouldSucceedOn__run__pullAll__run() 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 run a new statement
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("RETURN 1", EMPTY_PARAMS, recorder);
    // Then
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 9 with BoltStateMachine

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

the class BoltConnectionIT method shouldBeAbleToCleanlyRunMultipleSessionsInSingleThread.

@Test
public void shouldBeAbleToCleanlyRunMultipleSessionsInSingleThread() throws Throwable {
    // Given
    BoltStateMachine firstMachine = env.newMachine(CONNECTION_DESCRIPTOR);
    firstMachine.init(USER_AGENT, emptyMap(), null);
    BoltStateMachine secondMachine = env.newMachine(CONNECTION_DESCRIPTOR);
    secondMachine.init(USER_AGENT, emptyMap(), null);
    // And given I've started a transaction in one session
    runAndPull(firstMachine, "BEGIN");
    // When I issue a statement in a separate session
    Object[] stream = runAndPull(secondMachine, "CREATE (a:Person) RETURN id(a)");
    long id = (long) ((Record) stream[0]).fields()[0];
    // And when I roll back that first session transaction
    runAndPull(firstMachine, "ROLLBACK");
    // Then the two should not have interfered with each other
    stream = runAndPull(secondMachine, "MATCH (a:Person) WHERE id(a) = " + id + " RETURN COUNT(*)");
    assertThat(((Record) stream[0]).fields()[0], equalTo((Object) 1L));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) Record(org.neo4j.bolt.v1.runtime.spi.Record) Test(org.junit.Test)

Example 10 with BoltStateMachine

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

the class BoltConnectionIT method shouldCloseConnectionOnPullAllBeforeInit.

@Test
public void shouldCloseConnectionOnPullAllBeforeInit() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    // when
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.pullAll(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