Search in sources :

Example 91 with TestDatabaseManagementServiceBuilder

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

the class AbstractNeo4jTestCase method startDb.

protected static void startDb() {
    managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
    graphDb = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder)

Example 92 with TestDatabaseManagementServiceBuilder

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

the class PropertyTransactionStateTest method setUp.

@BeforeEach
void setUp() {
    managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 93 with TestDatabaseManagementServiceBuilder

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

the class LabelRecoveryTest method shouldRecoverNodeWithDynamicLabelRecords.

/**
 * Reading a node command might leave a node record which referred to
 * labels in one or more dynamic records as marked as heavy even if that
 * node already had references to dynamic records, changed in a transaction,
 * but had no labels on that node changed within that same transaction.
 * Now defensively only marks as heavy if there were one or more dynamic
 * records provided when providing the record object with the label field
 * value. This would give the opportunity to load the dynamic records the
 * next time that record would be ensured heavy.
 */
@Test
void shouldRecoverNodeWithDynamicLabelRecords() {
    // GIVEN
    managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(filesystem).impermanent().build();
    database = managementService.database(DEFAULT_DATABASE_NAME);
    Node node;
    Label[] labels = new Label[] { label("a"), label("b"), label("c"), label("d"), label("e"), label("f"), label("g"), label("h"), label("i"), label("j"), label("k") };
    try (Transaction tx = database.beginTx()) {
        node = tx.createNode(labels);
        tx.commit();
    }
    // WHEN
    try (Transaction tx = database.beginTx()) {
        node = tx.getNodeById(node.getId());
        node.setProperty("prop", "value");
        tx.commit();
    }
    EphemeralFileSystemAbstraction snapshot = filesystem.snapshot();
    managementService.shutdown();
    managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(snapshot).impermanent().build();
    database = managementService.database(DEFAULT_DATABASE_NAME);
    // THEN
    try (Transaction tx = database.beginTx()) {
        node = tx.getNodeById(node.getId());
        for (Label label : labels) {
            assertTrue(node.hasLabel(label));
        }
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) Test(org.junit.jupiter.api.Test)

Example 94 with TestDatabaseManagementServiceBuilder

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

the class RecoveryIT method recoverEmptyDatabase.

@Test
void recoverEmptyDatabase() throws Throwable {
    // The database is only completely empty if we skip the creation of the default indexes initially.
    // Without skipping there will be entries in the transaction logs for the default token indexes, so recovery is required if we remove the checkpoint.
    Config config = Config.newBuilder().set(GraphDatabaseInternalSettings.skip_default_indexes_on_creation, true).set(preallocate_logical_logs, false).build();
    managementService = new TestDatabaseManagementServiceBuilder(neo4jLayout).setConfig(config).build();
    managementService.database(databaseLayout.getDatabaseName());
    managementService.shutdown();
    RecoveryHelpers.removeLastCheckpointRecordFromLastLogFile(databaseLayout, fileSystem);
    assertFalse(isRecoveryRequired(databaseLayout, config));
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Config(org.neo4j.configuration.Config) Test(org.junit.jupiter.api.Test)

Example 95 with TestDatabaseManagementServiceBuilder

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

the class RecoveryIT method cancelRecoveryInTheMiddle.

@Test
void cancelRecoveryInTheMiddle() throws Throwable {
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    RecoveryHelpers.removeLastCheckpointRecordFromLastLogFile(databaseLayout, fileSystem);
    assertTrue(isRecoveryRequired(layout));
    Monitors monitors = new Monitors();
    var guardExtensionFactory = new GlobalGuardConsumerTestExtensionFactory();
    var recoveryMonitor = new RecoveryMonitor() {

        private final AtomicBoolean reverseCompleted = new AtomicBoolean();

        private final AtomicBoolean recoveryCompleted = new AtomicBoolean();

        @Override
        public void reverseStoreRecoveryCompleted(long lowestRecoveredTxId) {
            try {
                guardExtensionFactory.getProvidedGuardConsumer().globalGuard.stop();
            } catch (Exception e) {
            // do nothing
            }
            reverseCompleted.set(true);
        }

        @Override
        public void recoveryCompleted(int numberOfRecoveredTransactions, long recoveryTimeInMilliseconds) {
            recoveryCompleted.set(true);
        }

        public boolean isReverseCompleted() {
            return reverseCompleted.get();
        }

        public boolean isRecoveryCompleted() {
            return recoveryCompleted.get();
        }
    };
    monitors.addMonitorListener(recoveryMonitor);
    var service = new TestDatabaseManagementServiceBuilder(layout.getNeo4jLayout()).addExtension(guardExtensionFactory).setMonitors(monitors).build();
    try {
        var database = service.database(layout.getDatabaseName());
        assertTrue(recoveryMonitor.isReverseCompleted());
        assertFalse(recoveryMonitor.isRecoveryCompleted());
        assertFalse(guardExtensionFactory.getProvidedGuardConsumer().globalGuard.isAvailable());
        assertFalse(database.isAvailable(0));
        var e = assertThrows(Exception.class, database::beginTx);
        assertThat(getRootCause(e)).isInstanceOf(DatabaseStartAbortedException.class);
    } finally {
        service.shutdown();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Monitors(org.neo4j.monitoring.Monitors) DatabaseStartAbortedException(org.neo4j.dbms.database.DatabaseStartAbortedException) IOException(java.io.IOException) 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