Search in sources :

Example 1 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ClusterFormationIT method shouldSupportBuiltInProcedures.

@Test
public void shouldSupportBuiltInProcedures() throws Exception {
    cluster.addReadReplicaWithId(0).start();
    Stream.concat(cluster.readReplicas().stream().map(ReadReplica::database), cluster.coreMembers().stream().map(CoreClusterMember::database)).forEach(gdb -> {
        {
            Result result = gdb.execute("CALL dbms.procedures()");
            assertTrue(result.hasNext());
            result.close();
        }
        try (InternalTransaction tx = gdb.beginTransaction(KernelTransaction.Type.explicit, EnterpriseSecurityContext.AUTH_DISABLED)) {
            Result result = gdb.execute(tx, "CALL dbms.listQueries()", Collections.emptyMap());
            assertTrue(result.hasNext());
            result.close();
            tx.success();
        }
    });
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 2 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class CausalClusteringProceduresIT method readReplicaProceduresShouldBeAvailable.

@Test
public void readReplicaProceduresShouldBeAvailable() throws Exception {
    // given
    String[] readReplicaProcs = new String[] { // Server role
    "dbms.cluster.role", // Kernel built procedures
    "dbms.procedures", // Built in procedure from enterprise
    "dbms.listQueries" };
    // when
    for (String procedure : readReplicaProcs) {
        Optional<ReadReplica> firstReadReplica = cluster.readReplicas().stream().findFirst();
        assert firstReadReplica.isPresent();
        ReadReplicaGraphDatabase database = firstReadReplica.get().database();
        InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, AUTH_DISABLED);
        Result readReplicaResult = database.execute("CALL " + procedure + "()");
        // then
        assertTrue("read replica with procedure " + procedure, readReplicaResult.hasNext());
        readReplicaResult.close();
        tx.close();
    }
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 3 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class CausalClusteringProceduresIT method coreProceduresShouldBeAvailable.

@Test
public void coreProceduresShouldBeAvailable() throws Throwable {
    String[] coreProcs = new String[] { // Server role
    "dbms.cluster.role", // Discover the cluster topology
    "dbms.cluster.routing.getServers", // Discover appropriate discovery service
    "dbms.cluster.overview", // Kernel built procedures
    "dbms.procedures", // Built in procedure from enterprise
    "dbms.listQueries" };
    for (String procedure : coreProcs) {
        Optional<CoreClusterMember> firstCore = cluster.coreMembers().stream().findFirst();
        assert firstCore.isPresent();
        CoreGraphDatabase database = firstCore.get().database();
        InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, AUTH_DISABLED);
        Result coreResult = database.execute("CALL " + procedure + "()");
        assertTrue("core with procedure " + procedure, coreResult.hasNext());
        coreResult.close();
        tx.close();
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 4 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class Neo4jTransactionalContextFactory method create.

@Deprecated
public static TransactionalContextFactory create(GraphDatabaseQueryService queryService, PropertyContainerLocker locker) {
    DependencyResolver resolver = queryService.getDependencyResolver();
    ThreadToStatementContextBridge txBridge = resolver.resolveDependency(ThreadToStatementContextBridge.class);
    Guard guard = resolver.resolveDependency(Guard.class);
    Neo4jTransactionalContext.Creator contextCreator = (Supplier<Statement> statementSupplier, InternalTransaction tx, Statement initialStatement, ExecutingQuery executingQuery) -> new Neo4jTransactionalContext(queryService, statementSupplier, guard, txBridge, locker, tx, initialStatement, executingQuery);
    return new Neo4jTransactionalContextFactory(txBridge, contextCreator);
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) Statement(org.neo4j.kernel.api.Statement) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Guard(org.neo4j.kernel.guard.Guard) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 5 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class QueryLoggerIT method shouldLogTXMetaDataInQueryLog.

@Test
public void shouldLogTXMetaDataInQueryLog() throws Throwable {
    // turn on query logging
    databaseBuilder.setConfig(GraphDatabaseSettings.logs_directory, logsDirectory.getPath());
    databaseBuilder.setConfig(GraphDatabaseSettings.log_queries, Settings.TRUE);
    EmbeddedInteraction db = new EmbeddedInteraction(databaseBuilder, Collections.emptyMap());
    GraphDatabaseFacade graph = db.getLocalGraph();
    db.getLocalUserManager().setUserPassword("neo4j", "123", false);
    EnterpriseSecurityContext subject = db.login("neo4j", "123");
    db.executeQuery(subject, "UNWIND range(0, 10) AS i CREATE (:Foo {p: i})", Collections.emptyMap(), ResourceIterator::close);
    // Set meta data and execute query in transaction
    try (InternalTransaction tx = db.beginLocalTransactionAsUser(subject, KernelTransaction.Type.explicit)) {
        graph.execute("CALL dbms.setTXMetaData( { User: 'Johan' } )", Collections.emptyMap());
        graph.execute("CALL dbms.procedures() YIELD name RETURN name", Collections.emptyMap()).close();
        graph.execute("MATCH (n) RETURN n", Collections.emptyMap()).close();
        graph.execute(QUERY, Collections.emptyMap());
        tx.success();
    }
    // Ensure that old meta data is not retained
    try (InternalTransaction tx = db.beginLocalTransactionAsUser(subject, KernelTransaction.Type.explicit)) {
        graph.execute("CALL dbms.setTXMetaData( { Location: 'Sweden' } )", Collections.emptyMap());
        graph.execute("MATCH ()-[r]-() RETURN count(r)", Collections.emptyMap()).close();
        tx.success();
    }
    db.tearDown();
    // THEN
    List<String> logLines = readAllLines(logFilename);
    assertThat(logLines, hasSize(7));
    assertThat(logLines.get(0), not(containsString("User: 'Johan'")));
    // we don't care if setTXMetaData contains the meta data
    //assertThat( logLines.get( 1 ), containsString( "User: Johan" ) );
    assertThat(logLines.get(2), containsString("User: 'Johan'"));
    assertThat(logLines.get(3), containsString("User: 'Johan'"));
    assertThat(logLines.get(4), containsString("User: 'Johan'"));
    // we want to make sure that the new transaction does not carry old meta data
    assertThat(logLines.get(5), not(containsString("User: 'Johan'")));
    assertThat(logLines.get(6), containsString("Location: 'Sweden'"));
}
Also used : EnterpriseSecurityContext(org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext) EmbeddedInteraction(org.neo4j.server.security.enterprise.auth.EmbeddedInteraction) Matchers.containsString(org.hamcrest.Matchers.containsString) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) ResourceIterator(org.neo4j.graphdb.ResourceIterator) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.Test)

Aggregations

InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)126 Transaction (org.neo4j.graphdb.Transaction)58 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)53 Test (org.junit.jupiter.api.Test)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 Node (org.neo4j.graphdb.Node)16 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 Result (org.neo4j.graphdb.Result)12 TokenRead (org.neo4j.internal.kernel.api.TokenRead)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)8 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)7 Relationship (org.neo4j.graphdb.Relationship)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)6 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)5