Search in sources :

Example 11 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class CheckPointerIntegrationTest method shouldCheckPointBasedOnTime.

@Test
void shouldCheckPointBasedOnTime() throws Throwable {
    // given
    long millis = 200;
    DatabaseManagementService managementService = builder.setConfig(check_point_interval_time, ofMillis(millis)).setConfig(check_point_interval_tx, 10000).setConfig(logical_log_rotation_threshold, gibiBytes(1)).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    // when
    try (Transaction tx = db.beginTx()) {
        tx.createNode();
        tx.commit();
    }
    // The scheduled job checking whether or not checkpoints are needed runs more frequently
    // now that we've set the time interval so low, so we can simply wait for it here
    long endTime = currentTimeMillis() + SECONDS.toMillis(30);
    while (checkPointInTxLog(db).isEmpty()) {
        Thread.sleep(millis);
        assertTrue(currentTimeMillis() < endTime, "Took too long to produce a checkpoint");
    }
    managementService.shutdown();
    managementService = builder.build();
    try {
        // then - 2 check points have been written in the log
        List<CheckpointInfo> checkPoints = checkPointsInTxLog(managementService.database(DEFAULT_DATABASE_NAME));
        assertTrue(checkPoints.size() >= 2, "Expected at least two (at least one for time interval and one for shutdown), was " + checkPoints.toString());
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) Test(org.junit.jupiter.api.Test)

Example 12 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class CheckPointerIntegrationTest method shouldNotCheckPointWhenThereAreNoCommits.

@Test
void shouldNotCheckPointWhenThereAreNoCommits() throws Throwable {
    // given
    DatabaseManagementService managementService = builder.setConfig(check_point_interval_time, Duration.ofSeconds(1)).setConfig(check_point_interval_tx, 10000).setConfig(logical_log_rotation_threshold, gibiBytes(1)).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    GraphDatabaseAPI databaseAPI = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    getCheckPointer(databaseAPI).forceCheckPoint(new SimpleTriggerInfo("given"));
    var checkPointsBefore = checkPointInTxLog(db).size();
    // when
    // nothing happens
    triggerCheckPointAttempt(db);
    assertThat(checkPointInTxLog(db)).hasSize(checkPointsBefore);
    managementService.shutdown();
    managementService = builder.build();
    try {
        // then - 1 check point has been written in the log
        var checkPoints = checkPointsInTxLog(managementService.database(DEFAULT_DATABASE_NAME));
        assertEquals(checkPointsBefore + 1, checkPoints.size());
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 13 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService 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 14 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService 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 15 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class HttpTransactionManagerTest method shouldGetEmptyTransactionFacadeOfDatabaseData.

@Test
void shouldGetEmptyTransactionFacadeOfDatabaseData() {
    DatabaseManagementService managementService = mock(DatabaseManagementService.class);
    var memoryPool = mock(MemoryPool.class);
    var manager = newTransactionManager(managementService, memoryPool);
    var graphDatabaseFacade = manager.getGraphDatabaseAPI("data");
    assertFalse(graphDatabaseFacade.isPresent());
    verify(managementService).database("data");
}
Also used : DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)155 Test (org.junit.jupiter.api.Test)100 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)79 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)61 Transaction (org.neo4j.graphdb.Transaction)60 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)56 Path (java.nio.file.Path)37 Node (org.neo4j.graphdb.Node)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Label (org.neo4j.graphdb.Label)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)9 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)8 Config (org.neo4j.configuration.Config)7 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 GBPTreeCountsStore (org.neo4j.internal.counts.GBPTreeCountsStore)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)6