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();
}
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));
}
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());
}
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" ) ) ) );
}
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));
}
Aggregations