Search in sources :

Example 6 with Neo4jError

use of org.neo4j.bolt.runtime.Neo4jError in project neo4j by neo4j.

the class BoltStateMachineV4Test method testMarkFailedShouldYieldIgnoredIfAlreadyFailed.

private static void testMarkFailedShouldYieldIgnoredIfAlreadyFailed(ThrowingBiConsumer<BoltStateMachine, BoltResponseHandler, BoltConnectionFatality> action) throws Exception {
    // Given
    BoltStateMachine machine = init(newMachine());
    machine.markFailed(Neo4jError.from(new RuntimeException()));
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    machine.markFailed(error);
    // When
    action.accept(machine, responseHandler);
    // Expect
    assertNull(pendingError(machine));
    assertFalse(pendingIgnore(machine));
    assertThat(machine).satisfies(inState(FailedState.class));
    verify(responseHandler).markIgnored();
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) FailedState(org.neo4j.bolt.v4.runtime.FailedState)

Example 7 with Neo4jError

use of org.neo4j.bolt.runtime.Neo4jError in project neo4j by neo4j.

the class BoltStateMachineV4Test method testMarkFailedOnNextMessage.

private static void testMarkFailedOnNextMessage(ThrowingBiConsumer<BoltStateMachine, BoltResponseHandler, BoltConnectionFatality> action) throws Exception {
    // Given
    BoltStateMachine machine = init(newMachine());
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    machine.markFailed(error);
    // When
    action.accept(machine, responseHandler);
    // Expect
    assertNull(pendingError(machine));
    assertFalse(pendingIgnore(machine));
    assertThat(machine).satisfies(inState(FailedState.class));
    verify(responseHandler).markFailed(error);
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) FailedState(org.neo4j.bolt.v4.runtime.FailedState)

Example 8 with Neo4jError

use of org.neo4j.bolt.runtime.Neo4jError in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldInvokeResponseHandlerOnMarkFailedIfThereIsHandler.

@Test
void shouldInvokeResponseHandlerOnMarkFailedIfThereIsHandler() throws Exception {
    BoltStateMachine machine = init(newMachine());
    Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    ((AbstractBoltStateMachine) machine).connectionState().setResponseHandler(responseHandler);
    machine.markFailed(error);
    assertNull(pendingError(machine));
    assertFalse(pendingIgnore(machine));
    assertThat(machine).satisfies(inState(FailedState.class));
    verify(responseHandler).markFailed(error);
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) FailedState(org.neo4j.bolt.v4.runtime.FailedState) Test(org.junit.jupiter.api.Test)

Example 9 with Neo4jError

use of org.neo4j.bolt.runtime.Neo4jError in project neo4j by neo4j.

the class BoltStateMachineV4Test method testReadyStateAfterMarkFailedOnNextMessage.

private static void testReadyStateAfterMarkFailedOnNextMessage(ThrowingBiConsumer<BoltStateMachine, BoltResponseHandler, BoltConnectionFatality> action) throws Exception {
    // Given
    BoltStateMachine machine = init(newMachine());
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    machine.markFailed(error);
    // When
    action.accept(machine, responseHandler);
    // Expect
    assertNull(pendingError(machine));
    assertFalse(pendingIgnore(machine));
    assertThat(machine).satisfies(inState(ReadyState.class));
    verify(responseHandler, never()).markFailed(any());
    verify(responseHandler, never()).markIgnored();
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) ReadyState(org.neo4j.bolt.v4.runtime.ReadyState) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler)

Example 10 with Neo4jError

use of org.neo4j.bolt.runtime.Neo4jError in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldSetPendingIgnoreOnMarkFailedIfAlreadyFailedAndNoHandler.

@Test
void shouldSetPendingIgnoreOnMarkFailedIfAlreadyFailedAndNoHandler() throws Exception {
    BoltStateMachine machine = newMachine();
    Neo4jError error1 = Neo4jError.from(new RuntimeException());
    machine.markFailed(error1);
    Neo4jError error2 = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    machine.markFailed(error2);
    assertTrue(pendingIgnore(machine));
    // error remained the same and was ignored
    assertEquals(error1, pendingError(machine));
    assertThat(machine).satisfies(inState(FailedState.class));
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) FailedState(org.neo4j.bolt.v4.runtime.FailedState) Test(org.junit.jupiter.api.Test)

Aggregations

Neo4jError (org.neo4j.bolt.runtime.Neo4jError)13 Test (org.junit.jupiter.api.Test)7 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)7 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)6 FailedState (org.neo4j.bolt.v4.runtime.FailedState)5 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)3 ReadyState (org.neo4j.bolt.v4.runtime.ReadyState)2 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BoltChannel (org.neo4j.bolt.BoltChannel)1 PackOutputClosedException (org.neo4j.bolt.packstream.PackOutputClosedException)1 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)1 BoltConnectionFatality (org.neo4j.bolt.runtime.BoltConnectionFatality)1 BoltResult (org.neo4j.bolt.runtime.BoltResult)1 AuthenticationException (org.neo4j.bolt.security.auth.AuthenticationException)1 BoltStateMachineV4 (org.neo4j.bolt.v4.BoltStateMachineV4)1 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)1 AuthorizationExpiredException (org.neo4j.graphdb.security.AuthorizationExpiredException)1 Status (org.neo4j.kernel.api.exceptions.Status)1