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);
}
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());
}
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));
}
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;
}
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);
}
Aggregations