use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltRequestMessageReaderV43Test method testMessageDecoding.
private static void testMessageDecoding(RequestMessage message) throws Exception {
Neo4jPack neo4jPack = newNeo4jPack();
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
BoltRequestMessageReader reader = requestMessageReader(stateMachine);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, message));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
reader.read(unpacker);
verify(stateMachine).process(eq(message), any());
}
use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltStateMachineContextImplTest method shouldResetMachine.
@Test
void shouldResetMachine() throws BoltConnectionFatality {
BoltStateMachine machine = mock(BoltStateMachine.class);
BoltStateMachineContextImpl context = newContext(machine, mock(BoltStateMachineSPI.class));
context.resetMachine();
verify(machine).reset();
}
use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltStateMachineV4Test method shouldRollbackOpenTransactionOnReset.
@Test
void shouldRollbackOpenTransactionOnReset() throws Throwable {
// Given a FAILED machine with an open transaction
final BoltStateMachine machine = newMachineWithTransaction();
machine.markFailed(Neo4jError.from(new RuntimeException()));
// When RESET occurs
reset(machine, nullResponseHandler());
// Then the transaction should have been rolled back...
assertThat(machine).satisfies(hasNoTransaction());
// ...and the machine should go back to READY
assertThat(machine).satisfies(inState(ReadyState.class));
}
use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll.
@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll() throws Throwable {
// Given
BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onDiscardRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
BoltStateMachine machine = init(newMachine());
// move to streaming state
machine.process(BoltV4Messages.run(), nullResponseHandler());
// We assume the only implementation of statement processor is TransactionStateMachine
txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
// When & Then
try {
machine.process(BoltV4Messages.discardAll(), responseHandler);
fail("Exception expected");
} catch (BoltConnectionAuthFatality e) {
assertEquals("Auth expired!", e.getCause().getMessage());
}
}
use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll.
@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll() throws Throwable {
// Given
BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onPullRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
BoltStateMachine machine = init(newMachine());
// move to streaming state
machine.process(BoltV4Messages.run(), nullResponseHandler());
// We assume the only implementation of statement processor is TransactionStateMachine
txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
// When & Then
try {
machine.process(BoltV4Messages.pullAll(), responseHandler);
fail("Exception expected");
} catch (BoltConnectionAuthFatality e) {
assertEquals("Auth expired!", e.getCause().getMessage());
}
verify(responseHandler).onPullRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
}
Aggregations