Search in sources :

Example 1 with Neo4jError

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

the class ErrorReporterTest method onlyDatabaseErrorsAreLogged.

@Test
void onlyDatabaseErrorsAreLogged() {
    AssertableLogProvider userLog = new AssertableLogProvider();
    AssertableLogProvider internalLog = new AssertableLogProvider();
    ErrorReporter reporter = newErrorReporter(userLog, internalLog);
    for (Status.Classification classification : Status.Classification.values()) {
        if (classification != Status.Classification.DatabaseError) {
            Status.Code code = newStatusCode(classification);
            Neo4jError error = Neo4jError.from(() -> code, "Database error");
            reporter.report(error);
            assertThat(userLog).doesNotHaveAnyLogs();
            assertThat(internalLog).doesNotHaveAnyLogs();
        }
    }
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) Neo4jError(org.neo4j.bolt.runtime.Neo4jError) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 2 with Neo4jError

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

the class AbstractBoltStateMachine method handleFailure.

@Override
public void handleFailure(Throwable cause, boolean fatal) throws BoltConnectionFatality {
    if (ExceptionUtils.indexOfType(cause, BoltConnectionFatality.class) != -1) {
        fatal = true;
    }
    Neo4jError error = fatal ? Neo4jError.fatalFrom(cause) : Neo4jError.from(cause);
    fail(error);
    if (error.isFatal()) {
        if (ExceptionUtils.indexOfType(cause, AuthorizationExpiredException.class) != -1) {
            throw new BoltConnectionAuthFatality("Failed to process a bolt message", cause);
        }
        if (cause instanceof AuthenticationException) {
            throw new BoltConnectionAuthFatality((AuthenticationException) cause);
        }
        throw new BoltConnectionFatality("Failed to process a bolt message", cause);
    }
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) AuthenticationException(org.neo4j.bolt.security.auth.AuthenticationException) BoltConnectionFatality(org.neo4j.bolt.runtime.BoltConnectionFatality) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality)

Example 3 with Neo4jError

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

the class AbstractBoltStateMachine method after.

protected void after() {
    if (connectionState.getResponseHandler() != null) {
        try {
            Neo4jError pendingError = connectionState.getPendingError();
            if (pendingError != null) {
                connectionState.markFailed(pendingError);
            }
            if (connectionState.hasPendingIgnore()) {
                connectionState.markIgnored();
            }
            connectionState.resetPendingFailedAndIgnored();
            connectionState.getResponseHandler().onFinish();
        } finally {
            connectionState.setResponseHandler(null);
        }
    }
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError)

Example 4 with Neo4jError

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

the class ErrorReporterTest method databaseErrorShouldLogFullMessageInDebugLogAndHelpfulPointerInUserLog.

@Test
void databaseErrorShouldLogFullMessageInDebugLogAndHelpfulPointerInUserLog() {
    // given
    AssertableLogProvider userLog = new AssertableLogProvider();
    AssertableLogProvider internalLog = new AssertableLogProvider();
    ErrorReporter reporter = newErrorReporter(userLog, internalLog);
    Neo4jError error = Neo4jError.fatalFrom(new TestDatabaseError());
    UUID reference = error.reference();
    // when
    reporter.report(error);
    // then
    assertThat(userLog).containsMessages("Client triggered an unexpected error", reference.toString(), "Database error");
    assertThat(internalLog).containsMessages(reference.toString(), "Database error");
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) UUID(java.util.UUID) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 5 with Neo4jError

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

the class BoltStateMachineV4Test method testMarkFailedShouldYieldSuccessIfAlreadyFailed.

private static void testMarkFailedShouldYieldSuccessIfAlreadyFailed(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(ReadyState.class));
    verify(responseHandler, never()).markIgnored();
    verify(responseHandler, never()).markFailed(any());
}
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)

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