Search in sources :

Example 71 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class TransactionMonitorTest method shouldCountTerminatedTransactions.

@ParameterizedTest(name = "{0}")
@MethodSource("parameters")
void shouldCountTerminatedTransactions(String name, ThrowingConsumer<Transaction, Exception> txConsumer, boolean isWriteTx) throws Exception {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        TransactionCounters counts = db.getDependencyResolver().resolveDependency(TransactionCounters.class);
        TransactionCountersChecker checker = new TransactionCountersChecker(counts);
        try (Transaction tx = db.beginTx()) {
            txConsumer.accept(tx);
            tx.terminate();
        }
        checker.verifyTerminated(isWriteTx, counts);
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) TransactionCounters(org.neo4j.kernel.impl.transaction.stats.TransactionCounters) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 72 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class CheckPointerIntegrationTest method checkPointInTxLog.

private static List<CheckpointInfo> checkPointInTxLog(GraphDatabaseService db) throws IOException {
    DependencyResolver dependencyResolver = ((GraphDatabaseAPI) db).getDependencyResolver();
    LogFiles logFiles = dependencyResolver.resolveDependency(LogFiles.class);
    return logFiles.getCheckpointFile().reachableCheckpoints();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 73 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class CheckPointerIntegrationTest method tracePageCacheAccessOnCheckpoint.

@Test
void tracePageCacheAccessOnCheckpoint() throws Exception {
    var managementService = builder.setConfig(check_point_interval_time, ofMillis(0)).setConfig(check_point_interval_tx, 1).setConfig(logical_log_rotation_threshold, gibiBytes(1)).build();
    try {
        GraphDatabaseAPI databaseAPI = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
        var cacheTracer = databaseAPI.getDependencyResolver().resolveDependency(PageCacheTracer.class);
        long initialFlushes = cacheTracer.flushes();
        long initialBytesWritten = cacheTracer.bytesWritten();
        long initialPins = cacheTracer.pins();
        getCheckPointer(databaseAPI).forceCheckPoint(new SimpleTriggerInfo("tracing"));
        assertThat(cacheTracer.flushes()).isGreaterThan(initialFlushes);
        assertThat(cacheTracer.bytesWritten()).isGreaterThan(initialBytesWritten);
        assertThat(cacheTracer.pins()).isGreaterThan(initialPins);
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test)

Example 74 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class ReuseStorageSpaceIT method shouldPrioritizeFreelistWhenConcurrentlyAllocating.

@Test
void shouldPrioritizeFreelistWhenConcurrentlyAllocating() throws Exception {
    DatabaseManagementService dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).setConfig(GraphDatabaseInternalSettings.force_small_id_cache, true).build();
    try {
        // given
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        int numNodes = 40_000;
        MutableLongSet nodeIds = createNodes(db, numNodes);
        try (Transaction tx = db.beginTx()) {
            nodeIds.forEach(nodeId -> tx.getNodeById(nodeId).delete());
            tx.commit();
        }
        db.getDependencyResolver().resolveDependency(IdController.class).maintenance();
        // First create 40,000 nodes, then delete them, ensure ID maintenance has run and allocate concurrently
        int numThreads = 4;
        Collection<Callable<MutableLongSet>> allocators = new ArrayList<>();
        for (int i = 0; i < numThreads; i++) {
            allocators.add(() -> createNodes(db, numNodes / numThreads));
        }
        ExecutorService executor = Executors.newFixedThreadPool(numThreads);
        List<Future<MutableLongSet>> results = executor.invokeAll(allocators);
        MutableLongSet reallocatedNodeIds = LongSets.mutable.withInitialCapacity(numNodes);
        for (Future<MutableLongSet> result : results) {
            reallocatedNodeIds.addAll(result.get());
        }
        assertThat(reallocatedNodeIds).as(diff(nodeIds, reallocatedNodeIds)).isEqualTo(nodeIds);
    } finally {
        dbms.shutdown();
    }
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) ExecutorService(java.util.concurrent.ExecutorService) IdController(org.neo4j.internal.id.IdController) Future(java.util.concurrent.Future) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 75 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class ImportCommandTest method shouldIgnoreWhitespaceInAndAroundBooleanArrays.

@Test
void shouldIgnoreWhitespaceInAndAroundBooleanArrays() throws Exception {
    // GIVEN
    // Faster to do all successful in one import than in N separate tests
    String[] values = new String[] { "true", "  true", "true   ", "  true  ", " false ", "false ", " false", "false ", " false" };
    String expected = joinStringArray(values);
    Path data = writeArrayCsv(new String[] { "b:boolean[]" }, values);
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--quote", "'", "--nodes", data.toAbsolutePath().toString());
    // THEN
    int nodeCount = 0;
    GraphDatabaseAPI databaseApi = getDatabaseApi();
    try (Transaction tx = databaseApi.beginTx()) {
        for (Node node : tx.getAllNodes()) {
            nodeCount++;
            assertEquals(1, node.getAllProperties().size());
            for (String key : node.getPropertyKeys()) {
                Object things = node.getProperty(key);
                String result = Arrays.toString((boolean[]) things);
                assertEquals(expected, result);
            }
        }
        tx.commit();
    }
    assertEquals(1, nodeCount);
}
Also used : Path(java.nio.file.Path) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.jupiter.api.Test)

Aggregations

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)262 Test (org.junit.Test)91 Test (org.junit.jupiter.api.Test)88 Transaction (org.neo4j.graphdb.Transaction)87 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)61 Node (org.neo4j.graphdb.Node)38 Path (java.nio.file.Path)30 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)26 File (java.io.File)25 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)24 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)19 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)18 DependencyResolver (org.neo4j.graphdb.DependencyResolver)17 Label (org.neo4j.graphdb.Label)15 PageCache (org.neo4j.io.pagecache.PageCache)15 Config (org.neo4j.kernel.configuration.Config)15 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)14 IOException (java.io.IOException)11