Search in sources :

Example 31 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class TransactionIT method shouldInterpretEmptyStatementAsReuseLastStatementInAutocommitTransaction.

@Test
public void shouldInterpretEmptyStatementAsReuseLastStatementInAutocommitTransaction() 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("", emptyMap(), nullResponseHandler());
    machine.pullAll(recorder);
    // 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)

Example 32 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class TransactionIT method shouldHandleBeginRollback.

@Test
public void shouldHandleBeginRollback() 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(nullResponseHandler());
    machine.run("CREATE (n:InTx)", emptyMap(), recorder);
    machine.discardAll(nullResponseHandler());
    machine.run("ROLLBACK", emptyMap(), recorder);
    machine.discardAll(nullResponseHandler());
    // Then
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 33 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class TransactionIT method shouldHandleBeginCommit.

@Test
public void shouldHandleBeginCommit() 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(nullResponseHandler());
    machine.run("CREATE (n:InTx)", emptyMap(), recorder);
    machine.discardAll(nullResponseHandler());
    machine.run("COMMIT", emptyMap(), recorder);
    machine.discardAll(nullResponseHandler());
    // Then
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 34 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class TransactionIT method shouldFailNicelyWhenOutOfOrderRollback.

@Test
public void shouldFailNicelyWhenOutOfOrderRollback() throws Throwable {
    // Given
    BoltResponseRecorder runRecorder = new BoltResponseRecorder();
    BoltResponseRecorder pullAllRecorder = new BoltResponseRecorder();
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // When
    machine.run("ROLLBACK", emptyMap(), runRecorder);
    machine.pullAll(pullAllRecorder);
    // Then
    assertThat(runRecorder.nextResponse(), failedWithStatus(Status.Statement.SemanticError));
    assertThat(pullAllRecorder.nextResponse(), wasIgnored());
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 35 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class TransactionIT method shouldInterpretEmptyStatementAsReuseLastStatementInExplicitTransaction.

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

BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)36 Test (org.junit.Test)34 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)30 InetSocketAddress (java.net.InetSocketAddress)2 RecordedBoltResponse (org.neo4j.bolt.testing.RecordedBoltResponse)2 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)2 HashMap (java.util.HashMap)1 BoltConnectionFatality (org.neo4j.bolt.v1.runtime.BoltConnectionFatality)1 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)1 BinaryLatch (org.neo4j.concurrent.BinaryLatch)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1