use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class IndexSamplingIntegrationTest method shouldSampleUniqueIndex.
@ParameterizedTest
@EnumSource(value = Entity.class, names = { "NODE" })
void shouldSampleUniqueIndex(Entity entity) throws Throwable {
GraphDatabaseService db = null;
DatabaseManagementService managementService = null;
long deletedNodes = 0;
try {
// Given
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
entity.createConstraint(tx, schemaName, TOKEN, property);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < entities; i++) {
entity.createEntity(tx, TOKEN, property, "" + i);
}
tx.commit();
}
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < entities; i++) {
if (i % 10 == 0) {
entity.deleteFirstFound(tx, TOKEN, property, "" + i);
deletedNodes++;
}
}
tx.commit();
}
} finally {
if (db != null) {
managementService.shutdown();
}
}
// When
triggerIndexResamplingOnNextStartup();
// Then
var indexSample = fetchIndexSamplingValues();
assertThat(indexSample.uniqueValues()).as("Unique values").isEqualTo(entities - deletedNodes);
assertThat(indexSample.sampleSize()).as("Sample size").isEqualTo(entities - deletedNodes);
assertThat(indexSample.updates()).as("Updates").isEqualTo(0);
assertThat(indexSample.indexSize()).as("Index size").isEqualTo(entities - deletedNodes);
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class NonUniqueIndexTest method newEmbeddedGraphDatabaseWithSlowJobScheduler.
private GraphDatabaseService newEmbeddedGraphDatabaseWithSlowJobScheduler() {
// Inject JobScheduler
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies(createJobScheduler());
managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setExternalDependencies(dependencies).build();
return managementService.database(GraphDatabaseSettings.DEFAULT_DATABASE_NAME);
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class ConstraintIndexFailureIT method shouldFailToValidateConstraintsIfUnderlyingIndexIsFailed.
@Test
void shouldFailToValidateConstraintsIfUnderlyingIndexIsFailed() throws Exception {
// given a perfectly normal constraint
Path dir = directory.homePath();
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(dir).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(label("Label1")).assertPropertyIsUnique("key1").create();
tx.commit();
} finally {
managementService.shutdown();
}
// Remove the indexes offline and start up with an index provider which reports FAILED as initial state. An ordeal, I know right...
FileUtils.deleteDirectory(IndexDirectoryStructure.baseSchemaIndexFolder(dir));
managementService = new TestDatabaseManagementServiceBuilder(dir).removeExtensions(INDEX_PROVIDERS_FILTER).addExtension(new FailingGenericNativeIndexProviderFactory(INITIAL_STATE)).addExtension(new TokenIndexProviderFactory()).noOpSystemGraphInitializer().build();
db = managementService.database(DEFAULT_DATABASE_NAME);
// when
try (Transaction tx = db.beginTx()) {
var e = assertThrows(ConstraintViolationException.class, () -> tx.createNode(label("Label1")).setProperty("key1", "value1"));
assertThat(e.getCause()).isInstanceOf(UnableToValidateConstraintException.class);
assertThat(e.getCause().getCause().getMessage()).contains("The index is in a failed state:").contains(INITIAL_STATE_FAILURE_MESSAGE);
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method setupDb.
private DatabaseManagementService setupDb(Path storeDir, IndexRecoveryTracker indexRecoveryTracker) {
Monitors monitors = new Monitors();
monitors.addMonitorListener(indexRecoveryTracker);
return new TestDatabaseManagementServiceBuilder(storeDir).setMonitors(monitors).setConfig(GraphDatabaseSettings.allow_upgrade, true).build();
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class RecoverIndexDropIT method shouldDropIndexOnRecovery.
@Test
void shouldDropIndexOnRecovery() throws IOException {
// given a transaction stream ending in an INDEX DROP command.
CommittedTransactionRepresentation dropTransaction = prepareDropTransaction();
DatabaseManagementService managementService = configure(new TestDatabaseManagementServiceBuilder(databaseLayout)).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
long initialIndexCount = currentIndexCount(db);
createIndex(db);
StorageEngineFactory storageEngineFactory = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(StorageEngineFactory.class);
managementService.shutdown();
appendDropTransactionToTransactionLog(databaseLayout.getTransactionLogsDirectory(), dropTransaction, storageEngineFactory);
// when recovering this (the drop transaction with the index file intact)
Monitors monitors = new Monitors();
AssertRecoveryIsPerformed recoveryMonitor = new AssertRecoveryIsPerformed();
monitors.addMonitorListener(recoveryMonitor);
managementService = configure(new TestDatabaseManagementServiceBuilder(databaseLayout).setMonitors(monitors)).build();
db = managementService.database(DEFAULT_DATABASE_NAME);
try {
assertTrue(recoveryMonitor.recoveryWasRequired);
// then
assertEquals(initialIndexCount, currentIndexCount(db));
} finally {
// and the ability to shut down w/o failing on still open files
managementService.shutdown();
}
}
Aggregations