Search in sources :

Example 46 with DatabaseManagementService

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

the class RecordFormatMigrationIT method skipMigrationIfFormatSpecifiedInConfig.

@Test
void skipMigrationIfFormatSpecifiedInConfig() {
    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(StandardV4_0.NAME);
    GraphDatabaseAPI nonUpgradedStore = getDefaultDatabase(managementService);
    RecordStorageEngine storageEngine = nonUpgradedStore.getDependencyResolver().resolveDependency(RecordStorageEngine.class);
    assertEquals(StandardV4_0.NAME, storageEngine.testAccessNeoStores().getRecordFormats().name());
    managementService.shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) Node(org.neo4j.graphdb.Node) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 47 with DatabaseManagementService

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

the class LabelsAcceptanceTest method oversteppingMaxNumberOfLabelsShouldFailGracefully.

@Test
void oversteppingMaxNumberOfLabelsShouldFailGracefully() throws IOException {
    JobScheduler scheduler = JobSchedulerFactory.createScheduler();
    try (EphemeralFileSystemAbstraction fileSystem = new EphemeralFileSystemAbstraction();
        Lifespan lifespan = new Lifespan(scheduler);
        PageCache pageCache = new MuninnPageCache(swapper(fileSystem), scheduler, MuninnPageCache.config(1_000))) {
        // Given
        Dependencies dependencies = new Dependencies();
        dependencies.satisfyDependencies(createIdContextFactoryWithMaxedOutLabelTokenIds(fileSystem, scheduler));
        DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(fileSystem).noOpSystemGraphInitializer().setExternalDependencies(dependencies).impermanent().build();
        GraphDatabaseService graphDatabase = managementService.database(DEFAULT_DATABASE_NAME);
        // When
        try (Transaction tx = graphDatabase.beginTx()) {
            assertThrows(ConstraintViolationException.class, () -> tx.createNode().addLabel(Labels.MY_LABEL));
        }
        managementService.shutdown();
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) Dependencies(org.neo4j.collection.Dependencies) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) PageCache(org.neo4j.io.pagecache.PageCache) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) Test(org.junit.jupiter.api.Test)

Example 48 with DatabaseManagementService

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

the class GraphDatabaseInternalLogIT method shouldWriteToInternalDiagnosticsLog.

@Test
void shouldWriteToInternalDiagnosticsLog() throws Exception {
    // Given
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDir.homePath()).setConfig(GraphDatabaseSettings.logs_directory, testDir.directory("logs").toAbsolutePath()).build();
    var databaseId = ((GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME)).databaseId();
    managementService.shutdown();
    Path internalLog = testDir.directory("logs").resolve(INTERNAL_LOG_FILE);
    // Then
    assertThat(Files.isRegularFile(internalLog)).isEqualTo(true);
    assertThat(Files.size(internalLog)).isGreaterThan(0L);
    assertEquals(1, countOccurrences(internalLog, databaseId + " is ready."));
    assertEquals(2, countOccurrences(internalLog, databaseId + " is unavailable."));
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 49 with DatabaseManagementService

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

the class GraphDatabaseInternalLogIT method shouldNotWriteDebugToInternalDiagnosticsLogByDefault.

@Test
void shouldNotWriteDebugToInternalDiagnosticsLogByDefault() throws Exception {
    // Given
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDir.homePath()).setConfig(GraphDatabaseSettings.logs_directory, testDir.directory("logs").toAbsolutePath()).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    // When
    LogService logService = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(LogService.class);
    logService.getInternalLog(getClass()).debug("A debug entry");
    managementService.shutdown();
    Path internalLog = testDir.directory("logs").resolve(INTERNAL_LOG_FILE);
    // Then
    assertThat(Files.isRegularFile(internalLog)).isEqualTo(true);
    assertThat(Files.size(internalLog)).isGreaterThan(0L);
    assertEquals(0, countOccurrences(internalLog, "A debug entry"));
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) LogService(org.neo4j.logging.internal.LogService) Test(org.junit.jupiter.api.Test)

Example 50 with DatabaseManagementService

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

the class CancelIndexPopulationIT method shouldKeepIndexInPopulatingStateBetweenRestarts.

@Test
void shouldKeepIndexInPopulatingStateBetweenRestarts() throws InterruptedException {
    DatabaseManagementService dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).build();
    try {
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        // given
        Monitors monitors = db.getDependencyResolver().resolveDependency(Monitors.class);
        Barrier.Control barrier = new Barrier.Control();
        monitors.addMonitorListener(populationCompletionBlocker(barrier));
        // when
        createRelevantNode(db);
        createIndex(db);
        barrier.await();
    } finally {
        // This call to shutdown will eventually make a call to populationCancelled on the monitor below
        dbms.shutdown();
    }
    dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).build();
    try {
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        // then
        assertEquals(Schema.IndexState.ONLINE, awaitAndGetIndexState(db));
    } finally {
        dbms.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Monitors(org.neo4j.monitoring.Monitors) Barrier(org.neo4j.test.Barrier) 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