use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltConditions method verifyOneResponse.
public static void verifyOneResponse(ThrowingBiConsumer<BoltStateMachine, BoltResponseRecorder, BoltConnectionFatality> transition) throws Exception {
BoltStateMachine machine = newMachine();
BoltResponseRecorder recorder = new BoltResponseRecorder();
try {
transition.accept(machine, recorder);
} catch (BoltConnectionFatality connectionFatality) {
// acceptable for invalid transitions
}
assertEquals(1, recorder.responseCount());
}
use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltStateMachineContextImplTest method shouldHandleFailure.
@Test
void shouldHandleFailure() throws BoltConnectionFatality {
BoltStateMachine machine = mock(BoltStateMachine.class);
BoltStateMachineContextImpl context = newContext(machine, mock(BoltStateMachineSPI.class));
RuntimeException cause = new RuntimeException();
context.handleFailure(cause, true);
verify(machine).handleFailure(cause, true);
}
use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltStateMachineV4Test method shouldRemainStoppedAfterInterrupted.
@Test
void shouldRemainStoppedAfterInterrupted() throws Throwable {
// Given a ready machine
final BoltStateMachine machine = init(newMachine());
// ...which is subsequently closed
machine.close();
assertThat(machine).satisfies(isClosed());
// When and interrupt and reset occurs
reset(machine, nullResponseHandler());
// Then the machine should remain closed
assertThat(machine).satisfies(isClosed());
}
use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltStateMachineV4Test method testCantDoAnythingIfInFailedState.
@Test
void testCantDoAnythingIfInFailedState() throws Throwable {
// Given a FAILED machine
BoltStateMachine machine = init(newMachine());
machine.markFailed(Neo4jError.from(new RuntimeException()));
// Then no RUN...
machine.process(BoltV4Messages.run(), nullResponseHandler());
assertThat(machine).satisfies(inState(FailedState.class));
// ...DISCARD_ALL...
machine.process(BoltV4Messages.discardAll(), nullResponseHandler());
assertThat(machine).satisfies(inState(FailedState.class));
// ...or PULL_ALL should be possible
machine.process(BoltV4Messages.pullAll(), nullResponseHandler());
assertThat(machine).satisfies(inState(FailedState.class));
}
use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltStateMachineV4Test method multipleInterruptsShouldBeMatchedWithMultipleResets.
@Test
void multipleInterruptsShouldBeMatchedWithMultipleResets() throws Throwable {
// Given
final BoltStateMachine machine = init(newMachine());
// When
machine.interrupt();
machine.interrupt();
// ...and
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.process(BoltV4Messages.run(), recorder);
machine.process(BoltV4Messages.reset(), recorder);
machine.process(BoltV4Messages.run(), recorder);
// Then
assertThat(recorder.nextResponse()).satisfies(wasIgnored());
assertThat(recorder.nextResponse()).satisfies(wasIgnored());
assertThat(recorder.nextResponse()).satisfies(wasIgnored());
// But when
recorder.reset();
machine.process(BoltV4Messages.reset(), recorder);
machine.process(BoltV4Messages.run(), recorder);
// Then
assertThat(recorder.nextResponse()).satisfies(succeeded());
assertThat(recorder.nextResponse()).satisfies(succeeded());
}
Aggregations