Search in sources :

Example 6 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeWhenNoRoutingContextProvided.

@Test
void testShouldDecodeWhenNoRoutingContextProvided() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    HelloMessage originalMessage = new HelloMessage(meta, new RoutingContext(false, Collections.emptyMap()), 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 7 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext in project neo4j by neo4j.

the class CommunityEditionEndToEndTest method testRollbackOnStatementFailure.

@Test
void testRollbackOnStatementFailure() {
    // this is intentionally not using the driver, because the driver closes transactions on any failure
    // and this test verifies that the server does the same (we should not rely on the drivers with this behaviour
    // as all the drivers might not come from us)
    var dependencyResolver = graphDatabase.getDependencyResolver();
    var transactionManager = dependencyResolver.resolveDependency(TransactionManager.class);
    var fabricExecutor = dependencyResolver.resolveDependency(FabricExecutor.class);
    var transactionInfo = new FabricTransactionInfo(org.neo4j.bolt.runtime.AccessMode.READ, AUTH_DISABLED, EMBEDDED_CONNECTION, DatabaseIdFactory.from("mega", UUID.randomUUID()), false, Duration.ZERO, Map.of(), new RoutingContext(false, Map.of()));
    var bookmarkManager = mock(TransactionBookmarkManager.class);
    var tx1 = transactionManager.begin(transactionInfo, bookmarkManager);
    var tx2 = transactionManager.begin(transactionInfo, bookmarkManager);
    assertEquals(2, transactionManager.getOpenTransactions().size());
    var query1 = joinAsLines("USE neo4j", "RETURN 1/0 AS res");
    assertThrows(org.neo4j.exceptions.ArithmeticException.class, () -> fabricExecutor.run(tx1, query1, MapValue.EMPTY).records().collectList().block());
    var query2 = joinAsLines("USE neo4j", "UNWIND [1, 0] AS a", "RETURN 1/a AS res");
    assertThrows(org.neo4j.exceptions.ArithmeticException.class, () -> fabricExecutor.run(tx2, query2, MapValue.EMPTY).records().collectList().block());
    assertTrue(transactionManager.getOpenTransactions().isEmpty());
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) FabricTransactionInfo(org.neo4j.fabric.transaction.FabricTransactionInfo) Test(org.junit.jupiter.api.Test)

Example 8 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext in project neo4j by neo4j.

the class HelloMessageDecoder method decode.

@Override
public RequestMessage decode(Neo4jPack.Unpacker unpacker) throws IOException {
    Map<String, Object> meta = readMetaDataMap(unpacker);
    RoutingContext routingContext = parseRoutingContext(meta);
    return new HelloMessage(meta, routingContext, extractAuthToken(meta));
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage)

Example 9 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext in project neo4j by neo4j.

the class ConnectedState method process.

@Override
public BoltStateMachineState process(RequestMessage message, StateMachineContext context) throws BoltConnectionFatality {
    assertInitialized();
    if (message instanceof HelloMessage) {
        HelloMessage helloMessage = (HelloMessage) message;
        String userAgent = helloMessage.userAgent();
        Map<String, Object> authToken = helloMessage.authToken();
        RoutingContext routingContext = helloMessage.routingContext();
        if (processAuthentication(userAgent, authToken, context, routingContext)) {
            context.resolveDefaultDatabase();
            context.connectionState().onMetadata(CONNECTION_ID_KEY, Values.utf8Value(context.connectionId()));
            context.connectionState().onMetadata("hints", hints);
            return readyState;
        } else {
            return null;
        }
    }
    return null;
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage)

Example 10 with RoutingContext

use of org.neo4j.bolt.v41.messaging.RoutingContext 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)

Aggregations

RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)12 HelloMessage (org.neo4j.bolt.v41.messaging.request.HelloMessage)9 Test (org.junit.jupiter.api.Test)7 AuthTokenDecoderTest (org.neo4j.bolt.security.auth.AuthTokenDecoderTest)6 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)5 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)5 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)5 HashMap (java.util.HashMap)4 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)4 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)1 AccessMode (org.neo4j.bolt.runtime.AccessMode)1 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)1 UseEvaluation (org.neo4j.fabric.eval.UseEvaluation)1 StatementLifecycle (org.neo4j.fabric.executor.FabricStatementLifecycles.StatementLifecycle)1 FabricPlan (org.neo4j.fabric.planning.FabricPlan)1 FabricPlanner (org.neo4j.fabric.planning.FabricPlanner)1 Fragment (org.neo4j.fabric.planning.Fragment)1 FabricTransactionInfo (org.neo4j.fabric.transaction.FabricTransactionInfo)1