Search in sources :

Example 41 with DatabaseManagementService

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

the class DatabaseManagementServiceBuilderIT method startSystemAndDefaultDatabase.

@Test
void startSystemAndDefaultDatabase() {
    DatabaseManagementService managementService = getDbmsBuilderWithLimitedTxLogSize(testDirectory.homePath()).build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        DependencyResolver dependencyResolver = database.getDependencyResolver();
        DatabaseManager<?> databaseManager = dependencyResolver.resolveDependency(DatabaseManager.class);
        assertThat(databaseManager.getDatabaseContext(DEFAULT_DATABASE_NAME)).isNotEmpty();
        assertThat(databaseManager.getDatabaseContext(NAMED_SYSTEM_DATABASE_ID)).isNotEmpty();
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) DependencyResolver(org.neo4j.common.DependencyResolver) Test(org.junit.jupiter.api.Test)

Example 42 with DatabaseManagementService

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

the class ConsistencyCheckWithCorruptGBPTreeIT method dbmsAction.

/**
 * Open dbms with schemaIndex as default index provider on provided file system abstraction and apply dbSetup to DEFAULT_DATABASE.
 */
private void dbmsAction(Path neo4jHome, FileSystemAbstraction fs, GraphDatabaseSettings.SchemaIndex schemaIndex, Consumer<GraphDatabaseService> dbSetup, Consumer<DatabaseManagementServiceBuilder> dbConfiguration) {
    TestDatabaseManagementServiceBuilder builder = new TestDatabaseManagementServiceBuilder(neo4jHome).setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs));
    dbConfiguration.accept(builder);
    final DatabaseManagementService dbms = builder.setConfig(GraphDatabaseSettings.default_schema_provider, schemaIndex.providerName()).build();
    try {
        final GraphDatabaseService db = dbms.database(DEFAULT_DATABASE_NAME);
        dbSetup.accept(db);
    } finally {
        dbms.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) UncloseableDelegatingFileSystemAbstraction(org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 43 with DatabaseManagementService

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

the class FirstStartupIT method shouldBeEmptyWhenFirstStarted.

@Test
void shouldBeEmptyWhenFirstStarted() {
    // When
    var storeDir = testDir.absolutePath();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    // Then
    try (Transaction transaction = db.beginTx()) {
        assertEquals(0, count(transaction.getAllNodes()));
        assertEquals(0, count(transaction.getAllRelationships()));
        assertEquals(0, count(transaction.getAllRelationshipTypes()));
        assertEquals(0, count(transaction.getAllLabels()));
        assertEquals(0, count(transaction.getAllPropertyKeys()));
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 44 with DatabaseManagementService

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

the class RecordFormatMigrationIT method failToDowngradeFormatWhenUpgradeNotAllowed.

@Test
void failToDowngradeFormatWhenUpgradeNotAllowed() {
    DatabaseManagementService managementService = startManagementService(StandardV4_3.NAME);
    GraphDatabaseAPI database = getDefaultDatabase(managementService);
    try (Transaction transaction = database.beginTx()) {
        Node node = transaction.createNode();
        node.setProperty("a", "b");
        transaction.commit();
    }
    managementService.shutdown();
    managementService = startManagementService(StandardV4_0.NAME);
    database = getDefaultDatabase(managementService);
    try {
        Throwable throwable = assertDefaultDatabaseFailed(database);
        assertSame(UpgradeNotAllowedException.class, getRootCause(throwable).getClass());
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 45 with DatabaseManagementService

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

the class RecordFormatMigrationIT method latestRecordNotMigratedWhenFormatBumped.

@Test
void latestRecordNotMigratedWhenFormatBumped() {
    DatabaseManagementService managementService = startManagementService(StandardV4_0.NAME);
    GraphDatabaseAPI database = getDefaultDatabase(managementService);
    try (Transaction transaction = database.beginTx()) {
        Node node = transaction.createNode();
        node.setProperty("a", "b");
        transaction.commit();
    }
    managementService.shutdown();
    managementService = startManagementService(Standard.LATEST_NAME);
    database = getDefaultDatabase(managementService);
    try {
        Throwable exception = assertDefaultDatabaseFailed(database);
        assertSame(UpgradeNotAllowedException.class, getRootCause(exception).getClass());
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) 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