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