Search in sources :

Example 36 with BoltStateMachine

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

the class BoltConnectionIT method shouldSucceedOn__run_BEGIN__pullAll__run_COMMIT__pullALL__run_COMMIT.

@Test
public void shouldSucceedOn__run_BEGIN__pullAll__run_COMMIT__pullALL__run_COMMIT() 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
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("BEGIN", EMPTY_PARAMS, recorder);
    machine.pullAll(recorder);
    machine.run("COMMIT", EMPTY_PARAMS, recorder);
    machine.pullAll(recorder);
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    // When I run a new statement
    recorder.reset();
    machine.run("BEGIN", 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 37 with BoltStateMachine

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

the class BoltConnectionIT method shouldFailOn__run__run.

@Test
public void shouldFailOn__run__run() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // And Given that I've ran one statement
    machine.run("RETURN 1", EMPTY_PARAMS, nullResponseHandler());
    // When I run a new statement, before consuming the stream
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.run("RETURN 1", EMPTY_PARAMS, 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 38 with BoltStateMachine

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

the class BoltConnectionIT method shouldNotSupportUsingPeriodicCommitInTransaction.

@Test
public void shouldNotSupportUsingPeriodicCommitInTransaction() throws Exception {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    Map<String, Object> params = new HashMap<>();
    params.put("csvFileUrl", createLocalIrisData(machine));
    runAndPull(machine, "BEGIN");
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("USING PERIODIC COMMIT 40\n" + "LOAD CSV WITH HEADERS FROM {csvFileUrl} AS l\n" + "MATCH (c:Class {name: l.class_name})\n" + "CREATE (s:Sample {sepal_length: l.sepal_length, sepal_width: l.sepal_width, petal_length: l" + ".petal_length, petal_width: l.petal_width})\n" + "CREATE (c)<-[:HAS_CLASS]-(s)\n" + "RETURN count(*) AS c", params, recorder);
    // Then
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Statement.SemanticError));
// "Executing queries that use periodic commit in an open transaction is not possible."
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) HashMap(java.util.HashMap) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 39 with BoltStateMachine

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

the class BoltConnectionIT method shouldAllowNewTransactionAfterFailure.

@Test
public void shouldAllowNewTransactionAfterFailure() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // And given I've started a transaction that failed
    runAndPull(machine, "BEGIN");
    machine.run("invalid", EMPTY_PARAMS, nullResponseHandler());
    machine.reset(nullResponseHandler());
    // When
    runAndPull(machine, "BEGIN");
    Object[] stream = runAndPull(machine, "RETURN 1");
    // Then
    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 40 with BoltStateMachine

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

the class BoltConnectionIT method shouldFailOn__discardAll__discardAll.

@Test
public void shouldFailOn__discardAll__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.discardAll(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