Search in sources :

Example 11 with Neo4jError

use of org.neo4j.bolt.runtime.Neo4jError 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));
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltChannel(org.neo4j.bolt.BoltChannel) BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) DefaultDatabaseResolver(org.neo4j.kernel.database.DefaultDatabaseResolver) FailedState(org.neo4j.bolt.v4.runtime.FailedState) Test(org.junit.jupiter.api.Test)

Example 12 with Neo4jError

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

the class MessageProcessingHandlerTest method shouldLogShortWarningOnClientDisconnectMidwayThroughQuery.

@Test
void shouldLogShortWarningOnClientDisconnectMidwayThroughQuery() throws Exception {
    // Connections dying is not exceptional per-se, so we don't need to fill the log with
    // eye-catching stack traces; but it could be indicative of some issue, so log a brief
    // warning in the debug log at least.
    // Given
    PackOutputClosedException outputClosed = new PackOutputClosedException("Output closed", "<client>");
    Neo4jError txTerminated = Neo4jError.from(new TransactionTerminatedException(Status.Transaction.Terminated));
    // When
    AssertableLogProvider logProvider = emulateFailureWritingError(txTerminated, outputClosed);
    // Then
    assertThat(logProvider).forClass(getClass()).forLevel(WARN).containsMessageWithArguments("Client %s disconnected while query was running. Session has been cleaned up. " + "This can be caused by temporary network problems, but if you see this often, ensure your " + "applications are properly waiting for operations to complete before exiting.", "<client>");
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) PackOutputClosedException(org.neo4j.bolt.packstream.PackOutputClosedException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 13 with Neo4jError

use of org.neo4j.bolt.runtime.Neo4jError 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!");
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) AnyValue(org.neo4j.values.AnyValue) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BoltResult(org.neo4j.bolt.runtime.BoltResult) 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