use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.
the class ResetFuzzTest method assertWorkerWorks.
private void assertWorkerWorks(BoltWorker worker) throws InterruptedException {
BoltResponseRecorder recorder = new BoltResponseRecorder();
worker.enqueue(machine -> machine.reset(recorder));
try {
RecordedBoltResponse response = recorder.nextResponse();
assertThat(SUCCESS, equalTo(response.message()));
assertThat(machine.state(), equalTo(BoltStateMachine.State.READY));
assertThat(liveTransactions.get(), equalTo(0L));
} catch (AssertionError e) {
throw new AssertionError(String.format("Expected session to return to good state after RESET, but " + "assertion failed: %s.%n" + "Seed: %s%n" + "Messages sent:%n" + "%s", e.getMessage(), seed, Iterables.toString(sent, "\n")), e);
}
}
use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.
the class BoltStateMachineTest method testUsingResetToAcknowledgeError.
@Test
public void testUsingResetToAcknowledgeError() throws Throwable {
// Given
BoltResponseRecorder recorder = new BoltResponseRecorder();
// Given a FAILED machine
BoltStateMachine machine = newMachine(FAILED);
// When I RESET...
machine.reset(recorder);
// ...successfully
assertThat(recorder.nextResponse(), succeeded());
// Then if I RUN a statement...
machine.run("RETURN 1", EMPTY_PARAMS, recorder);
// ...everything should be fine again
assertThat(recorder.nextResponse(), succeeded());
}
use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.
the class BoltStateMachineTest method multipleInterruptsShouldBeMatchedWithMultipleResets.
@Test
public void multipleInterruptsShouldBeMatchedWithMultipleResets() throws Throwable {
// Given
final BoltStateMachine machine = newMachine(READY);
// When
machine.interrupt();
machine.interrupt();
// ...and
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.run("RETURN 1", EMPTY_PARAMS, recorder);
machine.reset(recorder);
machine.run("RETURN 1", EMPTY_PARAMS, recorder);
// Then
assertThat(recorder.nextResponse(), wasIgnored());
assertThat(recorder.nextResponse(), wasIgnored());
assertThat(recorder.nextResponse(), wasIgnored());
// But when
recorder.reset();
machine.reset(recorder);
machine.run("RETURN 1", EMPTY_PARAMS, recorder);
// Then
assertThat(recorder.nextResponse(), succeeded());
assertThat(recorder.nextResponse(), succeeded());
}
use of org.neo4j.bolt.testing.BoltResponseRecorder 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.testing.BoltResponseRecorder in project neo4j by neo4j.
the class BoltConnectionAuthIT method shouldGiveKernelVersionOnInit.
@Test
public void shouldGiveKernelVersionOnInit() throws Throwable {
// Given it is important for client applications to programmatically
// identify expired credentials as the cause of not being authenticated
BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
BoltResponseRecorder recorder = new BoltResponseRecorder();
String version = "Neo4j/" + Version.getNeo4jVersion();
// When
machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j"), recorder);
machine.run("CREATE ()", map(), recorder);
// Then
assertThat(recorder.nextResponse(), succeededWithMetadata("server", version));
}
Aggregations