Search in sources :

Example 26 with DatabaseManagementService

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

the class DatabaseStartupTest method dumpSystemDiagnosticLoggingOnStartup.

@Test
void dumpSystemDiagnosticLoggingOnStartup() {
    AssertableLogProvider logProvider = new AssertableLogProvider();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setInternalLogProvider(logProvider).setConfig(GraphDatabaseInternalSettings.dump_diagnostics, true).build();
    managementService.database(DEFAULT_DATABASE_NAME);
    try {
        assertThat(logProvider).containsMessages("System diagnostics", "System memory information", "JVM memory information", "Operating system information", "JVM information", "Java classpath", "Library path", "System properties", "(IANA) TimeZone database version", "Network information", "DBMS config");
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 27 with DatabaseManagementService

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

the class DatabaseStartupTest method startDatabaseWithoutStoreFilesAndWithTransactionLogFilesFailure.

@Test
void startDatabaseWithoutStoreFilesAndWithTransactionLogFilesFailure() throws IOException {
    // Create a store
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    DatabaseLayout databaseLayout = db.databaseLayout();
    try (Transaction tx = db.beginTx()) {
        tx.createNode();
        tx.commit();
    }
    managementService.shutdown();
    fs.deleteRecursively(databaseLayout.databaseDirectory());
    // Try to start
    managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    try {
        db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
        assertFalse(db.isAvailable(10));
        DatabaseStateService dbStateService = db.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        Optional<Throwable> cause = dbStateService.causeOfFailure(db.databaseId());
        assertTrue(cause.isPresent());
        assertThat(cause.get()).hasStackTraceContaining("Fail to start '" + db.databaseId() + "' since transaction logs were found, while database ");
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 28 with DatabaseManagementService

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

the class DatabaseShutdownTest method invokeDatabaseShutdownListenersOnShutdown.

@Test
void invokeDatabaseShutdownListenersOnShutdown() {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setFileSystem(fs).build();
    ShutdownListenerDatabaseEventListener shutdownHandler = new ShutdownListenerDatabaseEventListener();
    managementService.registerDatabaseEventListener(shutdownHandler);
    managementService.shutdown();
    assertEquals(2, shutdownHandler.shutdownCounter());
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 29 with DatabaseManagementService

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

the class DatabaseShutdownTest method shouldShutdownCorrectlyWhenCheckPointingOnShutdownFails.

@Test
void shouldShutdownCorrectlyWhenCheckPointingOnShutdownFails() {
    TestDatabaseManagementServiceBuilderWithFailingPageCacheFlush factory = new TestDatabaseManagementServiceBuilderWithFailingPageCacheFlush(databaseLayout.databaseDirectory(), fs);
    DatabaseManagementService managementService = factory.build();
    GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
    factory.setFailFlush(true);
    managementService.shutdown();
    assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
    assertEquals(LifecycleStatus.SHUTDOWN, factory.getDatabaseStatus());
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 30 with DatabaseManagementService

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

the class RecoveryRequiredCheckerTest method startStopAndCreateDefaultData.

private void startStopAndCreateDefaultData() {
    DatabaseManagementService managementService = startDatabase(fileSystem, storeDir);
    try {
        GraphDatabaseService database = managementService.database(DEFAULT_DATABASE_NAME);
        try (Transaction transaction = database.beginTx()) {
            transaction.createNode();
            transaction.commit();
        }
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) 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