use of org.neo4j.bolt.runtime.BoltResponseHandler 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));
}
use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class BoltConnectionIT method shouldHandleFailureDuringResultPublishing.
@Test
void shouldHandleFailureDuringResultPublishing() throws Throwable {
// Given
var machine = newStateMachineAfterAuth();
var pullAllCallbackCalled = new CountDownLatch(1);
var error = new AtomicReference<Neo4jError>();
// When something fails while publishing the result stream
machine.process(run(), nullResponseHandler());
machine.process(pullAll(), new BoltResponseHandler() {
@Override
public boolean onPullRecords(BoltResult result, long size) throws Throwable {
throw new RuntimeException("Ooopsies!");
}
@Override
public boolean onDiscardRecords(BoltResult result, long size) throws Throwable {
throw new RuntimeException("Not this one!");
}
@Override
public void onMetadata(String key, AnyValue value) {
}
@Override
public void markFailed(Neo4jError err) {
error.set(err);
pullAllCallbackCalled.countDown();
}
@Override
public void markIgnored() {
}
@Override
public void onFinish() {
}
});
// Then
assertTrue(pullAllCallbackCalled.await(30, TimeUnit.SECONDS));
var err = error.get();
assertThat(err.status()).isEqualTo(Status.General.UnknownError);
assertThat(err.message()).contains("Ooopsies!");
}
use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class InTransactionStateIT method shouldMoveFromInTxStateToFailedStateOnfail.
@ParameterizedTest
@MethodSource("pullAllDiscardAllMessages")
void shouldMoveFromInTxStateToFailedStateOnfail(RequestMessage message) throws Throwable {
// Given
BoltStateMachineV4 machine = getBoltStateMachineInTxState();
// When
BoltResponseHandler handler = mock(BoltResponseHandler.class);
doThrow(new RuntimeException("Fail")).when(handler).onPullRecords(any(), anyLong());
doThrow(new RuntimeException("Fail")).when(handler).onDiscardRecords(any(), anyLong());
machine.process(message, handler);
// Then
assertThat(machine.state()).isInstanceOf(FailedState.class);
}
use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class TransactionReadyStateIT method shouldMoveToFailedOnRun_fail.
@Test
void shouldMoveToFailedOnRun_fail() throws Throwable {
BoltStateMachineV3 machine = getBoltStateMachineInTxReadyState();
// When
BoltResponseHandler handler = mock(BoltResponseHandler.class);
doThrow(new RuntimeException("Error!")).when(handler).onPullRecords(any(), anyLong());
doThrow(new RuntimeException("Error!")).when(handler).onDiscardRecords(any(), anyLong());
machine.process(new RunMessage("A cypher query"), handler);
// Then
assertThat(machine.state()).isInstanceOf(FailedState.class);
}
use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class TransactionStreamingStateIT method shouldMoveFromTxStreamingStateToFailedStateOnPullAllOrDiscardAll_fail.
@ParameterizedTest
@MethodSource("pullAllDiscardAllMessages")
void shouldMoveFromTxStreamingStateToFailedStateOnPullAllOrDiscardAll_fail(RequestMessage message) throws Throwable {
// Given
BoltStateMachineV3 machine = getBoltStateMachineInTxStreamingState();
// When
BoltResponseHandler handler = mock(BoltResponseHandler.class);
doThrow(new RuntimeException("Fail")).when(handler).onPullRecords(any(), anyLong());
doThrow(new RuntimeException("Fail")).when(handler).onDiscardRecords(any(), anyLong());
machine.process(message, handler);
// Then
assertThat(machine.state()).isInstanceOf(FailedState.class);
}
Aggregations