Search in sources :

Example 1 with BoltIOException

use of org.neo4j.bolt.messaging.BoltIOException in project neo4j by neo4j.

the class ChunkedOutput method flush.

@Override
public PackOutput flush() throws IOException {
    if (buffer != null && buffer.readableBytes() > 0) {
        closeChunkIfOpen();
        // check for and apply write throttles
        try {
            throttleGroup.writeThrottle().acquire(channel);
        } catch (TransportThrottleException ex) {
            throw new BoltIOException(Status.Request.InvalidUsage, ex.getMessage(), ex);
        }
        // Local copy and clear the buffer field. This ensures that the buffer is not re-released if the flush call fails
        ByteBuf out = this.buffer;
        this.buffer = null;
        channel.writeAndFlush(out, channel.voidPromise());
        buffer = allocateBuffer();
    }
    return this;
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) TransportThrottleException(org.neo4j.bolt.transport.TransportThrottleException) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with BoltIOException

use of org.neo4j.bolt.messaging.BoltIOException in project neo4j by neo4j.

the class HelloMessageDecoderTest method shouldThrowExceptionOnIncorrectRoutingContextFormat.

@Test
public void shouldThrowExceptionOnIncorrectRoutingContextFormat() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    // incorrect Map type params
    Map<String, Integer> routingContext = new HashMap<>();
    routingContext.put("policy", 4);
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", routingContext);
    HelloMessage originalMessage = new HelloMessage(meta, null, meta);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    BoltIOException ex = assertThrows(BoltIOException.class, () -> decoder.decode(unpacker));
    assertEquals("Routing information in the HELLO message must be a map with string keys and string values.", ex.getMessage());
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) AuthTokenDecoderTest(org.neo4j.bolt.security.auth.AuthTokenDecoderTest) Test(org.junit.jupiter.api.Test)

Example 3 with BoltIOException

use of org.neo4j.bolt.messaging.BoltIOException in project neo4j by neo4j.

the class DiscardMessageTest method shouldThrowExceptionIfZero.

@ParameterizedTest
@ValueSource(longs = { -100L, 0L })
void shouldThrowExceptionIfZero(long value) throws Throwable {
    // When & Then
    BoltIOException exception = assertThrows(BoltIOException.class, () -> new DiscardMessage(asMapValue(singletonMap("n", value))));
    assertThat(exception.getMessage()).startsWith("Expecting DISCARD size to be at least 1");
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BoltIOException

use of org.neo4j.bolt.messaging.BoltIOException in project neo4j by neo4j.

the class AbstractTransactionInitiatingMessage method shouldThrowExceptionIfFailedToParseTransactionMetadataCorrectly.

@Test
void shouldThrowExceptionIfFailedToParseTransactionMetadataCorrectly() throws Throwable {
    // Given
    Map<String, Object> msgMetadata = map("tx_metadata", "invalid value type");
    MapValue meta = ValueUtils.asMapValue(msgMetadata);
    // When & Then
    BoltIOException exception = assertThrows(BoltIOException.class, () -> createMessage(meta));
    assertThat(exception.getMessage()).startsWith("Expecting transaction metadata value to be a Map value");
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 5 with BoltIOException

use of org.neo4j.bolt.messaging.BoltIOException in project neo4j by neo4j.

the class AbstractTransactionInitiatingMessage method shouldThrowExceptionIfFailedToParseTransactionTimeoutCorrectly.

@Test
void shouldThrowExceptionIfFailedToParseTransactionTimeoutCorrectly() throws Throwable {
    // Given
    Map<String, Object> msgMetadata = map("tx_timeout", "invalid value type");
    MapValue meta = ValueUtils.asMapValue(msgMetadata);
    // When & Then
    BoltIOException exception = assertThrows(BoltIOException.class, () -> createMessage(meta));
    assertThat(exception.getMessage()).startsWith("Expecting transaction timeout value to be a Long value");
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Aggregations

BoltIOException (org.neo4j.bolt.messaging.BoltIOException)16 Test (org.junit.jupiter.api.Test)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MapValue (org.neo4j.values.virtual.MapValue)5 HashMap (java.util.HashMap)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)2 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)2 AuthTokenDecoderTest (org.neo4j.bolt.security.auth.AuthTokenDecoderTest)2 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)2 ValueUtils.asMapValue (org.neo4j.kernel.impl.util.ValueUtils.asMapValue)2 ByteBuf (io.netty.buffer.ByteBuf)1 TransactionStateMachineSPIProvider (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider)1 TransportThrottleException (org.neo4j.bolt.transport.TransportThrottleException)1 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)1 HelloMessage (org.neo4j.bolt.v41.messaging.request.HelloMessage)1 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)1 DatabaseNotFoundException (org.neo4j.dbms.api.DatabaseNotFoundException)1