Search in sources :

Example 41 with BoltStateMachine

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

the class BoltConnectionIT method shouldFailOn__discardAll__pullAll.

@Test
public void shouldFailOn__discardAll__pullAll() 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.discardAll(nullResponseHandler());
    // When I attempt to pull more items from the stream
    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)

Example 42 with BoltStateMachine

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

the class BoltConnectionIT method shouldSucceedOn__run__discardAll__run.

@Test
public void shouldSucceedOn__run__discardAll__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.discardAll(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 43 with BoltStateMachine

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

the class SessionRule method newMachine.

BoltStateMachine newMachine(BoltConnectionDescriptor connectionDescriptor, Clock clock) {
    if (boltFactory == null) {
        throw new IllegalStateException("Cannot access test environment before test is running.");
    }
    BoltStateMachine connection = boltFactory.newMachine(connectionDescriptor, () -> {
    }, clock);
    runningMachines.add(connection);
    return connection;
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine)

Example 44 with BoltStateMachine

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

the class TransactionIT method shouldReceiveBookmarkOnCommitAndDiscardAll.

@Test
public void shouldReceiveBookmarkOnCommitAndDiscardAll() throws Throwable {
    // Given
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // When
    machine.run("BEGIN", emptyMap(), recorder);
    machine.discardAll(recorder);
    machine.run("CREATE (a:Person)", emptyMap(), recorder);
    machine.discardAll(recorder);
    machine.run("COMMIT", emptyMap(), recorder);
    machine.discardAll(recorder);
    // Then
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 45 with BoltStateMachine

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

the class TransactionIT method beginShouldNotOverwriteLastStatement.

@Test
public void beginShouldNotOverwriteLastStatement() throws Throwable {
    // Given
    final BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // When
    machine.run("RETURN 1", emptyMap(), nullResponseHandler());
    machine.pullAll(recorder);
    machine.run("BEGIN", emptyMap(), nullResponseHandler());
    machine.discardAll(nullResponseHandler());
    machine.run("", emptyMap(), nullResponseHandler());
    machine.pullAll(recorder);
    machine.run("COMMIT", emptyMap(), nullResponseHandler());
    machine.discardAll(nullResponseHandler());
    // Then
    assertThat(recorder.nextResponse(), succeededWithRecord(1L));
    assertThat(recorder.nextResponse(), succeededWithRecord(1L));
}
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