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