Search in sources :

Example 11 with PackedInputArray

use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.

the class BoltRequestMessageReaderV3Test method testMessageDecoding.

private static void testMessageDecoding(RequestMessage message) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    BoltRequestMessageReader reader = requestMessageReader(stateMachine);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, message));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    reader.read(unpacker);
    verify(stateMachine).process(eq(message), any());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)

Example 12 with PackedInputArray

use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeWhenEmptyRoutingContextProvided.

@Test
void testShouldDecodeWhenEmptyRoutingContextProvided() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Map<String, String> parameterMap = new HashMap<>();
    RoutingContext routingContext = new RoutingContext(true, parameterMap);
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", parameterMap);
    HelloMessage originalMessage = new HelloMessage(meta, routingContext, 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();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
    assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) 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 13 with PackedInputArray

use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeRoutingContext.

@Test
void testShouldDecodeRoutingContext() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Map<String, Object> authToken;
    Map<String, String> parameterMap = new HashMap<>();
    RoutingContext routingContext = new RoutingContext(true, parameterMap);
    parameterMap.put("policy", "fast");
    parameterMap.put("region", "eu-west");
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", parameterMap);
    authToken = new HashMap<>(Map.copyOf(meta));
    authToken.remove("routing");
    HelloMessage originalMessage = new HelloMessage(meta, routingContext, authToken);
    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();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
    assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) 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 14 with PackedInputArray

use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.

the class PullMessageDecoderTest method assertOriginalMessageEqualsToDecoded.

private static void assertOriginalMessageEqualsToDecoded(RequestMessage originalMessage, RequestMessageDecoder decoder) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    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();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertEquals(originalMessage, deserializedMessage);
}
Also used : RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) BoltProtocolV4ComponentFactory.newNeo4jPack(org.neo4j.bolt.v4.BoltProtocolV4ComponentFactory.newNeo4jPack) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack)

Example 15 with PackedInputArray

use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldErrorForMissingUserAgent.

@Test
protected void testShouldErrorForMissingUserAgent() throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    Map<String, Object> authToken = new HashMap<>();
    HelloMessage originalMessage = new HelloMessage(authToken);
    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 exception = assertThrows(BoltIOException.class, () -> decoder.decode(unpacker));
    assertEquals("Expected \"user_agent\" in metadata", exception.getMessage());
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) HelloMessage(org.neo4j.bolt.v3.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)

Aggregations

Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)19 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)19 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)11 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)10 BoltRequestMessageReader (org.neo4j.bolt.messaging.BoltRequestMessageReader)8 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)8 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)5 AuthTokenDecoderTest (org.neo4j.bolt.security.auth.AuthTokenDecoderTest)5 HelloMessage (org.neo4j.bolt.v41.messaging.request.HelloMessage)5 BoltProtocolV4ComponentFactory.newNeo4jPack (org.neo4j.bolt.v4.BoltProtocolV4ComponentFactory.newNeo4jPack)4 RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)4 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)3 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)2 BoltProtocolV41ComponentFactory.newNeo4jPack (org.neo4j.bolt.v41.BoltProtocolV41ComponentFactory.newNeo4jPack)2 IOException (java.io.IOException)1 System.lineSeparator (java.lang.System.lineSeparator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1