Search in sources :

Example 11 with InternalTransaction

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

the class ConfiguredAuthScenariosInteractionTestBase method shouldNotWarnWhenOnlyUsingNativeProvider.

@Test
public void shouldNotWarnWhenOnlyUsingNativeProvider() throws Throwable {
    configuredSetup(stringMap(SecuritySettings.auth_provider.name(), "native"));
    assertSuccess(adminSubject, "CALL dbms.security.listUsers", r -> assertKeyIsMap(r, "username", "roles", userList));
    GraphDatabaseFacade localGraph = neo.getLocalGraph();
    InternalTransaction transaction = localGraph.beginTransaction(KernelTransaction.Type.explicit, StandardEnterpriseSecurityContext.AUTH_DISABLED);
    Result result = localGraph.execute(transaction, "EXPLAIN CALL dbms.security.listUsers", Collections.emptyMap());
    String description = String.format("%s (%s)", Status.Procedure.ProcedureWarning.code().description(), "dbms.security.listUsers only applies to native users.");
    assertThat(containsNotification(result, description), equalTo(false));
    transaction.success();
    transaction.close();
}
Also used : GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 12 with InternalTransaction

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

the class EmbeddedBuiltInProceduresInteractionTest method shouldNotKillQueryIfNotAuthenticated.

@Test
public void shouldNotKillQueryIfNotAuthenticated() throws Throwable {
    EnterpriseSecurityContext authy = createFakeAnonymousEnterpriseSecurityContext();
    GraphDatabaseFacade graph = neo.getLocalGraph();
    DoubleLatch latch = new DoubleLatch(2);
    ThreadedTransaction<EnterpriseSecurityContext> read = new ThreadedTransaction<>(neo, latch);
    String query = read.execute(threading, authy, "UNWIND [1,2,3] AS x RETURN x");
    latch.startAndWaitForAllToStart();
    String id = extractQueryId(query);
    try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.explicit, AnonymousContext.none())) {
        graph.execute(tx, "CALL dbms.killQuery('" + id + "')", Collections.emptyMap());
        throw new AssertionError("Expected exception to be thrown");
    } catch (QueryExecutionException e) {
        assertThat(e.getMessage(), containsString(PERMISSION_DENIED));
    }
    latch.finishAndWaitForAllToFinish();
    read.closeAndAssertSuccess();
}
Also used : EnterpriseSecurityContext(org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) DoubleLatch(org.neo4j.test.DoubleLatch) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.Test)

Example 13 with InternalTransaction

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

the class DocsExecutionEngineTest method createTransactionalContext.

private static TransactionalContext createTransactionalContext(String query) {
    InternalTransaction transaction = database.beginTransaction(Type.implicit, SecurityContext.AUTH_DISABLED);
    BoltConnectionInfo boltConnection = new BoltConnectionInfo("username", "neo4j-java-bolt-driver", new InetSocketAddress("127.0.0.1", 56789), new InetSocketAddress("127.0.0.1", 7687));
    return contextFactory.newContext(boltConnection, transaction, query, EMPTY_MAP);
}
Also used : BoltConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.BoltConnectionInfo) InetSocketAddress(java.net.InetSocketAddress) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 14 with InternalTransaction

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

the class IndexingServiceIntegrationTest method tracePageCacheAccessOnIndexUpdatesApply.

@ParameterizedTest
@MethodSource("parameters")
void tracePageCacheAccessOnIndexUpdatesApply(GraphDatabaseSettings.SchemaIndex schemaIndex) throws KernelException {
    setUp(schemaIndex);
    var marker = Label.label("marker");
    var propertyName = "property";
    var testConstraint = "testConstraint";
    try (Transaction transaction = database.beginTx()) {
        transaction.schema().constraintFor(marker).withName(testConstraint).assertPropertyIsUnique(propertyName).create();
        transaction.commit();
    }
    var dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
    var indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    var pageCacheTracer = dependencyResolver.resolveDependency(PageCacheTracer.class);
    try (Transaction transaction = database.beginTx()) {
        var kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
        var indexDescriptor = kernelTransaction.schemaRead().indexGetForName(testConstraint);
        try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnIndexUpdatesApply"))) {
            Iterable<IndexEntryUpdate<IndexDescriptor>> updates = List.of(add(1, indexDescriptor, longValue(4)));
            indexingService.applyUpdates(updates, cursorContext);
            PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
            assertEquals(5L, cursorTracer.pins());
            assertEquals(5L, cursorTracer.unpins());
            assertEquals(2L, cursorTracer.hits());
            assertEquals(3L, cursorTracer.faults());
        }
    }
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CursorContext(org.neo4j.io.pagecache.context.CursorContext) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with InternalTransaction

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

the class MultipleOpenCursorsTest method multipleIteratorsNestedInterleavedExact.

@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInterleavedExact(IndexCoordinator indexCoordinator) throws Exception {
    indexCoordinator.init(db);
    try (Transaction tx = db.beginTx()) {
        // when
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExact(ktx)) {
            List<Long> actual1 = new ArrayList<>();
            try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExact(ktx)) {
                List<Long> actual2 = new ArrayList<>();
                // Interleave
                exhaustInterleaved(cursor1, actual1, cursor2, actual2);
                // then
                indexCoordinator.assertExactResult(actual1);
                indexCoordinator.assertExactResult(actual2);
            }
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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