Search in sources :

Example 36 with DatabaseManagementService

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

the class MultipleIndexPopulationStressIT method populateDbAndIndexes.

private void populateDbAndIndexes(long nodeCount, long relCount) throws InterruptedException {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).build();
    final GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try {
        try (var tx = db.beginTx();
            var softly = new AutoCloseableSoftAssertions()) {
            softly.assertThat(tx.getAllNodes().stream().count()).as("Number of nodes").isEqualTo(nodeCount);
            softly.assertThat(tx.getAllRelationships().stream().count()).as("Number of relationships").isEqualTo(relCount);
        }
        createIndexes(db);
        final AtomicBoolean end = new AtomicBoolean();
        executor = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            executor.submit(() -> {
                ChangeRandomEntities changeRandomEntities = new ChangeRandomEntities(db, RandomValues.create(), nodeCount, relCount);
                while (!end.get()) {
                    changeRandomEntities.node();
                    changeRandomEntities.relationship();
                }
            });
        }
        while (!indexesAreOnline(db)) {
            Thread.sleep(100);
        }
        end.set(true);
        executor.shutdown();
        executor.awaitTermination(10, SECONDS);
        executor = null;
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) AutoCloseableSoftAssertions(org.assertj.core.api.AutoCloseableSoftAssertions) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 37 with DatabaseManagementService

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

the class MultipleIndexPopulationStressIT method dropIndexes.

private void dropIndexes() {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setConfig(GraphDatabaseSettings.pagecache_memory, "8m").build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        tx.schema().getIndexes().forEach(IndexDefinition::drop);
        tx.commit();
    } finally {
        managementService.shutdown();
    }
    expectingNLI = false;
    expectingRTI = false;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 38 with DatabaseManagementService

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

the class TestDatabaseManagementServiceBuilderTest method databaseStartsWithSystemAndDefaultDatabase.

@Test
void databaseStartsWithSystemAndDefaultDatabase() {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        checkAvailableDatabases(database);
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 39 with DatabaseManagementService

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

the class DbRepresentation method of.

public static DbRepresentation of(Path storeDirectory, String databaseName, Config config) {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDirectory).setConfig(config).noOpSystemGraphInitializer().build();
    GraphDatabaseService db = managementService.database(databaseName);
    try {
        return of(db);
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 40 with DatabaseManagementService

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

the class SystemTimeZoneLoggingIT method checkStartLogLine.

private void checkStartLogLine(int hoursShift, String timeZoneSuffix) throws IOException {
    TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.ofHours(hoursShift)));
    Path storeDir = testDirectory.homePath(String.valueOf(hoursShift));
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setConfig(GraphDatabaseSettings.db_timezone, LogTimeZone.SYSTEM).build();
    managementService.database(DEFAULT_DATABASE_NAME);
    managementService.shutdown();
    Path debugLog = Paths.get("logs", "debug.log");
    String debugLogLine = getLogLine(storeDir, debugLog);
    assertTrue(debugLogLine.contains(timeZoneSuffix), debugLogLine);
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

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