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);
}
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);
}
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));
}
}
}
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));
}
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();
}
}
Aggregations