use of org.neo4j.monitoring.Monitors 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.monitoring.Monitors in project neo4j by neo4j.
the class GenericIndexProviderCompatibilitySuiteTest method createIndexProvider.
@Override
protected IndexProvider createIndexProvider(PageCache pageCache, FileSystemAbstraction fs, Path graphDbDir, Config config) {
Monitors monitors = new Monitors();
String monitorTag = "";
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = RecoveryCleanupWorkCollector.immediate();
var readOnlyChecker = new DatabaseReadOnlyChecker.Default(config, DEFAULT_DATABASE_NAME);
return GenericNativeIndexProviderFactory.create(pageCache, graphDbDir, fs, monitors, monitorTag, config, readOnlyChecker, recoveryCleanupWorkCollector, PageCacheTracer.NULL, DEFAULT_DATABASE_NAME);
}
use of org.neo4j.monitoring.Monitors in project neo4j by neo4j.
the class IndexCleanupIT method mustClearIndexDirectoryOnDropWhilePopulating.
@ParameterizedTest
@EnumSource(SchemaIndex.class)
void mustClearIndexDirectoryOnDropWhilePopulating(SchemaIndex schemaIndex) throws InterruptedException, IOException {
// given
Barrier.Control midPopulation = new Barrier.Control();
IndexingService.MonitorAdapter trappingMonitor = new IndexingService.MonitorAdapter() {
@Override
public void indexPopulationScanStarting() {
midPopulation.reached();
}
};
configureDb(schemaIndex);
createSomeData();
Monitors monitors = db.getDependencyResolver().resolveDependency(Monitors.class);
monitors.addMonitorListener(trappingMonitor);
createIndex(db, false);
midPopulation.await();
Path[] providerDirectories = providerDirectories(fs, db);
for (Path providerDirectory : providerDirectories) {
assertTrue(fs.listFiles(providerDirectory).length > 0, "expected there to be at least one index per existing provider map");
}
// when
dropAllIndexes();
midPopulation.release();
assertNoIndexFilesExisting(providerDirectories);
}
use of org.neo4j.monitoring.Monitors in project neo4j by neo4j.
the class TokenIndexProviderCompatibilitySuiteTest method createIndexProvider.
@Override
protected IndexProvider createIndexProvider(PageCache pageCache, FileSystemAbstraction fs, Path graphDbDir, Config config) {
Monitors monitors = new Monitors();
String monitorTag = "";
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = RecoveryCleanupWorkCollector.immediate();
DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(graphDbDir);
var readOnlyChecker = new DatabaseReadOnlyChecker.Default(config, databaseLayout.getDatabaseName());
return TokenIndexProviderFactory.create(pageCache, graphDbDir, fs, monitors, monitorTag, config, readOnlyChecker, recoveryCleanupWorkCollector, databaseLayout, PageCacheTracer.NULL);
}
use of org.neo4j.monitoring.Monitors in project neo4j by neo4j.
the class StringLengthIndexValidationIT method configure.
@ExtensionCallback
void configure(TestDatabaseManagementServiceBuilder builder) {
Monitors monitors = new Monitors();
IndexingService.MonitorAdapter trappingMonitor = new IndexingService.MonitorAdapter() {
@Override
public void indexPopulationScanComplete() {
if (trapPopulation.get()) {
populationScanFinished.reached();
}
}
};
monitors.addMonitorListener(trappingMonitor);
builder.setMonitors(monitors);
builder.setConfig(default_schema_provider, schemaIndex.providerName());
}
Aggregations