use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.
the class AutoCommitStateIT method shouldMoveFromAutoCommitToReadyOnDiscardAll_succ.
@Test
void shouldMoveFromAutoCommitToReadyOnDiscardAll_succ() throws Throwable {
// Given
BoltStateMachineV4 machine = getBoltStateMachineInAutoCommitState();
// When
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.process(newDiscardMessage(2L), recorder);
// Then
RecordedBoltResponse response = recorder.nextResponse();
assertThat(response).satisfies(succeeded());
assertTrue(response.hasMetadata("bookmark"));
assertTrue(response.hasMetadata("db"));
assertThat(machine.state()).isInstanceOf(ReadyState.class);
}
use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.
the class AutoCommitStateIT method shouldMoveFromAutoCommitToReadyOnPull_succ_hasMore.
@Test
void shouldMoveFromAutoCommitToReadyOnPull_succ_hasMore() throws Throwable {
// Given
BoltStateMachineV4 machine = getBoltStateMachineInAutoCommitState("Unwind [1, 2, 3] as n return n");
// When
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.process(newPullMessage(2L), recorder);
// Then
RecordedBoltResponse response = recorder.nextResponse();
assertThat(response).satisfies(containsRecord(1L));
assertThat(response).satisfies(succeededWithMetadata("has_more", BooleanValue.TRUE));
assertFalse(response.hasMetadata("db"));
assertFalse(response.hasMetadata("bookmark"));
machine.process(newPullMessage(2L), recorder);
response = recorder.nextResponse();
assertThat(response).satisfies(containsRecord(3L));
assertTrue(response.hasMetadata("type"));
assertTrue(response.hasMetadata("t_last"));
assertTrue(response.hasMetadata("bookmark"));
assertTrue(response.hasMetadata("db"));
assertThat(machine.state()).isInstanceOf(ReadyState.class);
}
use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.
the class AutoCommitStateIT method shouldThrowExceptionOnIllegalMessagesInAutoCommitState.
private void shouldThrowExceptionOnIllegalMessagesInAutoCommitState(RequestMessage message) throws Throwable {
// Given
BoltStateMachineV4 machine = newStateMachine();
machine.process(newHelloMessage(), nullResponseHandler());
machine.process(new RunMessage("CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS), nullResponseHandler());
assertThat(machine.state()).isInstanceOf(AutoCommitState.class);
// when
BoltResponseRecorder recorder = new BoltResponseRecorder();
verifyKillsConnection(() -> machine.process(message, recorder));
// then
assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.Request.Invalid));
assertNull(machine.state());
}
use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.
the class BoltStateMachineV4Test method shouldSetPendingErrorOnMarkFailedIfNoHandler.
@Test
void shouldSetPendingErrorOnMarkFailedIfNoHandler() {
BoltStateMachineSPIImpl spi = mock(BoltStateMachineSPIImpl.class);
BoltChannel boltChannel = mock(BoltChannel.class);
var memoryTracker = mock(MemoryTracker.class);
BoltStateMachine machine = new BoltStateMachineV4(spi, boltChannel, Clock.systemUTC(), mock(DefaultDatabaseResolver.class), MapValue.EMPTY, memoryTracker);
Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
machine.markFailed(error);
assertEquals(error, pendingError(machine));
assertThat(machine).satisfies(inState(FailedState.class));
}
use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.
the class InTransactionStateIT method shouldStayInTxOnAnotherRun_succ.
@Test
void shouldStayInTxOnAnotherRun_succ() throws Throwable {
// Given
BoltStateMachineV4 machine = getBoltStateMachineInTxState();
// When
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.process(new RunMessage("MATCH (n) RETURN n LIMIT 1"), recorder);
// Then
RecordedBoltResponse response = recorder.nextResponse();
assertThat(response).satisfies(succeeded());
assertFalse(response.hasMetadata("bookmark"));
assertThat(machine.state()).isInstanceOf(InTransactionState.class);
}
Aggregations