Search in sources :

Example 71 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class RecoverIndexDropIT method prepareDropTransaction.

private CommittedTransactionRepresentation prepareDropTransaction() throws IOException {
    DatabaseManagementService managementService = configure(new TestDatabaseManagementServiceBuilder(directory.directory("preparation"))).build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        // Create index
        IndexDefinition index;
        index = createIndex(db);
        try (Transaction tx = db.beginTx()) {
            tx.schema().getIndexByName(index.getName()).drop();
            tx.commit();
        }
        return extractLastTransaction(db);
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 72 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class ConstraintRecoveryIT method shouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails.

@Test
void shouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails() {
    // given
    Path pathToDb = testDirectory.homePath();
    TestDatabaseManagementServiceBuilder dbFactory = new TestDatabaseManagementServiceBuilder(pathToDb);
    dbFactory.setFileSystem(fs);
    final EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
    final AtomicBoolean monitorCalled = new AtomicBoolean(false);
    Monitors monitors = new Monitors();
    monitors.addMonitorListener(new IndexingService.MonitorAdapter() {

        @Override
        public void indexPopulationScanComplete() {
            monitorCalled.set(true);
            db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getSchemaStore().flush(NULL);
            storeInNeedOfRecovery[0] = fs.snapshot();
        }
    });
    dbFactory.setMonitors(monitors);
    // This test relies on behaviour that is specific to the Lucene populator, where uniqueness is controlled
    // after index has been populated, which is why we're using NATIVE20 and index booleans (they end up in Lucene)
    DatabaseManagementService managementService = configure(dbFactory.impermanent().setConfig(default_schema_provider, NATIVE30.providerName())).build();
    db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        for (int i = 0; i < 2; i++) {
            tx.createNode(LABEL).setProperty(KEY, "true");
        }
        tx.commit();
    }
    assertThrows(ConstraintViolationException.class, () -> {
        try (Transaction tx = db.beginTx()) {
            tx.schema().constraintFor(LABEL).assertPropertyIsUnique(KEY).create();
        }
    });
    managementService.shutdown();
    assertTrue(monitorCalled.get());
    // when
    dbFactory = new TestDatabaseManagementServiceBuilder(pathToDb);
    dbFactory.setFileSystem(storeInNeedOfRecovery[0]);
    DatabaseManagementService secondManagementService = configure(dbFactory.impermanent()).build();
    db = (GraphDatabaseAPI) secondManagementService.database(DEFAULT_DATABASE_NAME);
    // then
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(10, TimeUnit.MINUTES);
    }
    try (Transaction transaction = db.beginTx()) {
        assertEquals(2, Iterables.count(transaction.getAllNodes()));
    }
    try (Transaction tx = db.beginTx()) {
        assertEquals(0, Iterables.count(Iterables.asList(tx.schema().getConstraints())));
    }
    try (Transaction tx = db.beginTx()) {
        IndexDefinition orphanedConstraintIndex = single(tx.schema().getIndexes(LABEL));
        assertEquals(LABEL.name(), single(orphanedConstraintIndex.getLabels()).name());
        assertEquals(KEY, single(orphanedConstraintIndex.getPropertyKeys()));
    }
    secondManagementService.shutdown();
}
Also used : Path(java.nio.file.Path) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Monitors(org.neo4j.monitoring.Monitors) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 73 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class IndexingServiceIntegrationTest method setUp.

private void setUp(GraphDatabaseSettings.SchemaIndex schemaIndex) {
    managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setConfig(GraphDatabaseSettings.default_schema_provider, schemaIndex.providerName()).build();
    database = managementService.database(DEFAULT_DATABASE_NAME);
    createData(database);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder)

Example 74 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class IndexCleanupIT method configureDb.

private void configureDb(SchemaIndex schemaIndex) {
    managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setConfig(default_schema_provider, schemaIndex.providerName()).build();
    db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder)

Example 75 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class DatabaseRecoveryIT method shouldSeeTheSameRecordsAtCheckpointAsAfterReverseRecovery.

@Test
void shouldSeeTheSameRecordsAtCheckpointAsAfterReverseRecovery() throws Exception {
    // given
    EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setFileSystem(fs).impermanent().build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    produceRandomGraphUpdates(db, 100);
    checkPoint(db);
    EphemeralFileSystemAbstraction checkPointFs = fs.snapshot();
    // when
    produceRandomGraphUpdates(db, 100);
    flush(db);
    EphemeralFileSystemAbstraction crashedFs = fs.snapshot();
    managementService.shutdown();
    fs.close();
    Dependencies dependencies = new Dependencies();
    Monitors monitors;
    AtomicReference<EphemeralFileSystemAbstraction> reversedFs;
    try (PageCache pageCache = pageCacheExtension.getPageCache(crashedFs)) {
        dependencies.satisfyDependencies(pageCache);
        monitors = new Monitors();
        reversedFs = new AtomicReference<>();
        monitors.addMonitorListener(new RecoveryMonitor() {

            @Override
            public void reverseStoreRecoveryCompleted(long checkpointTxId) {
                try {
                    // Flush the page cache which will fished out of the GlobalModule at the point of constructing the database
                    pageCache.flushAndForce();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
                // The stores should now be equal in content to the db as it was right after the checkpoint.
                // Grab a snapshot so that we can compare later.
                reversedFs.set(crashedFs.snapshot());
            }
        });
        DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setFileSystem(crashedFs).setExternalDependencies(dependencies).setMonitors(monitors).impermanent().build();
        managementService.shutdown();
    }
    // then
    fs.close();
    try {
        // Here we verify that the neostore contents, record by record are exactly the same when comparing
        // the store as it was right after the checkpoint with the store as it was right after reverse recovery completed.
        assertSameStoreContents(checkPointFs, reversedFs.get(), databaseLayout);
    } finally {
        IOUtils.closeAll(checkPointFs, reversedFs.get());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Monitors(org.neo4j.monitoring.Monitors) Dependencies(org.neo4j.collection.Dependencies) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.jupiter.api.Test)

Aggregations

TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)135 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)74 Test (org.junit.jupiter.api.Test)48 Transaction (org.neo4j.graphdb.Transaction)42 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)38 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)30 Path (java.nio.file.Path)23 BeforeEach (org.junit.jupiter.api.BeforeEach)18 Node (org.neo4j.graphdb.Node)18 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)13 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)11 PageCache (org.neo4j.io.pagecache.PageCache)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)8 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 TokenIndexProviderFactory (org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Dependencies (org.neo4j.collection.Dependencies)6 Config (org.neo4j.configuration.Config)6 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)6