Search in sources :

Example 16 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class LineDelimitedEventSourceJoltSerializer method writeErrorWrapper.

protected void writeErrorWrapper() {
    if (errors.isEmpty()) {
        return;
    }
    try {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeFieldName("error");
        jsonGenerator.writeStartObject();
        writeErrors();
        jsonGenerator.writeEndObject();
        jsonGenerator.writeEndObject();
        flush();
    } catch (JsonGenerationException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new ConnectionException("Failed to write to the connection", e);
    }
}
Also used : IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Example 17 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class ExecutionResultSerializer method writeFailure.

void writeFailure(FailureEvent failureEvent) {
    try {
        errors.add(failureEvent);
        ensureStatementFieldClosed();
    } catch (JsonGenerationException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new ConnectionException("Failed to write to the connection", e);
    }
}
Also used : IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Example 18 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class ExecutionResultSerializer method writeErrors.

private void writeErrors() {
    try {
        ensureDocumentOpen();
        jsonGenerator.writeArrayFieldStart("errors");
        try {
            for (FailureEvent error : errors) {
                try {
                    jsonGenerator.writeStartObject();
                    jsonGenerator.writeObjectField("code", error.getStatus().code().serialize());
                    jsonGenerator.writeObjectField("message", error.getMessage());
                } finally {
                    jsonGenerator.writeEndObject();
                }
            }
        } finally {
            jsonGenerator.writeEndArray();
            currentState = State.ERRORS_WRITTEN;
        }
    } catch (IOException e) {
        throw new ConnectionException("Failed to write to the response stream", e);
    }
}
Also used : FailureEvent(org.neo4j.server.http.cypher.format.api.FailureEvent) IOException(java.io.IOException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Example 19 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class InvocationTest method shouldHandleConnectionErrorWhenReadingStatementsInImplicitTransaction.

@Test
void shouldHandleConnectionErrorWhenReadingStatementsInImplicitTransaction() {
    // given
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    TransactionHandle handle = getTransactionHandle(executionEngine, registry);
    InputEventStream inputEventStream = mock(InputEventStream.class);
    when(inputEventStream.read()).thenThrow(new ConnectionException("Connection error", new IOException("Broken pipe")));
    Invocation invocation = new Invocation(log, handle, uriScheme.txCommitUri(1337L), mock(MemoryPool.class, RETURNS_MOCKS), inputEventStream, true);
    // when
    var e = assertThrows(ConnectionException.class, () -> invocation.execute(outputEventStream));
    assertEquals("Connection error", e.getMessage());
    // then
    verify(internalTransaction).rollback();
    verify(registry).forget(1337L);
    verifyNoInteractions(outputEventStream);
}
Also used : InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) IOException(java.io.IOException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException) MemoryPool(org.neo4j.memory.MemoryPool) Test(org.junit.jupiter.api.Test)

Example 20 with ConnectionException

use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.

the class InvocationTest method shouldFreeMemoryOnException.

@Test
void shouldFreeMemoryOnException() {
    var handle = getTransactionHandle(executionEngine, registry, false);
    var memoryPool = mock(MemoryPool.class);
    var inputEventStream = mock(InputEventStream.class);
    when(internalTransaction.execute("query", emptyMap())).thenReturn(executionResult);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    when(inputEventStream.read()).thenReturn(new Statement("query", map()), NULL_STATEMENT);
    mockDefaultResult();
    doThrow(new ConnectionException("Something broke", new IOException("Oh no"))).when(outputEventStream).writeStatementEnd(any(), any(), any(), any());
    var invocation = new Invocation(mock(Log.class), handle, uriScheme.txCommitUri(1337L), memoryPool, inputEventStream, true);
    assertThrows(ConnectionException.class, () -> invocation.execute(outputEventStream));
    verify(memoryPool).reserveHeap(Statement.SHALLOW_SIZE);
    verify(memoryPool).releaseHeap(Statement.SHALLOW_SIZE);
    verifyNoMoreInteractions(memoryPool);
}
Also used : Log(org.neo4j.logging.Log) Statement(org.neo4j.server.http.cypher.format.api.Statement) IOException(java.io.IOException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException) Test(org.junit.jupiter.api.Test)

Aggregations

IOException (java.io.IOException)21 ConnectionException (org.neo4j.server.http.cypher.format.api.ConnectionException)21 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)10 Test (org.junit.jupiter.api.Test)5 MemoryPool (org.neo4j.memory.MemoryPool)4 InputEventStream (org.neo4j.server.http.cypher.format.api.InputEventStream)4 Statement (org.neo4j.server.http.cypher.format.api.Statement)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JsonToken (com.fasterxml.jackson.core.JsonToken)2 InOrder (org.mockito.InOrder)2 Notification (org.neo4j.graphdb.Notification)2 TransactionStateChecker (org.neo4j.server.http.cypher.TransactionStateChecker)2 FailureEvent (org.neo4j.server.http.cypher.format.api.FailureEvent)2 InputFormatException (org.neo4j.server.http.cypher.format.api.InputFormatException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ArrayList (java.util.ArrayList)1 Log (org.neo4j.logging.Log)1