use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.
the class CrashGenerationCleanerCrashTest method mustNotLeakTasksOnCrash.
@Test
void mustNotLeakTasksOnCrash() {
// Given
String exceptionMessage = "When there's no more room in hell, the dead will walk the earth";
CrashGenerationCleaner cleaner = newCrashingCrashGenerationCleaner(exceptionMessage);
ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
ThreadPoolJobScheduler threadPoolJobScheduler = new ThreadPoolJobScheduler(executorService);
try {
var executor = new CleanupJob.Executor() {
@Override
public <T> CleanupJob.JobResult<T> submit(String jobDescription, Callable<T> job) {
var jobHandle = threadPoolJobScheduler.schedule(Group.TESTING, JobMonitoringParams.NOT_MONITORED, job);
return jobHandle::get;
}
};
Throwable exception = assertThrows(Throwable.class, () -> cleaner.clean(executor));
Throwable rootCause = getRootCause(exception);
assertTrue(rootCause instanceof IOException);
assertEquals(exceptionMessage, rootCause.getMessage());
} finally {
List<Runnable> tasks = executorService.shutdownNow();
assertEquals(0, tasks.size());
}
}
use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed.
@Test
void startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed() throws Throwable {
// given
// create a store
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
managementService.shutdown();
// mess up the version in the metadatastore
String badStoreVersion = "bad";
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong(badStoreVersion), databaseLayout.getDatabaseName(), NULL);
}
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setConfig(GraphDatabaseSettings.allow_upgrade, true).build();
GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
assertThrows(DatabaseShutdownException.class, databaseService::beginTx);
DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
Optional<Throwable> upgradeException = findCauseOrSuppressed(dbStateService.causeOfFailure(databaseService.databaseId()).get(), e -> e instanceof StoreUpgrader.UnexpectedUpgradingStoreVersionException);
assertTrue(upgradeException.isPresent());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.
the class DatabaseStartupTest method startDatabaseWithWrongTransactionFilesShouldFail.
@Test
void startDatabaseWithWrongTransactionFilesShouldFail() throws IOException {
// Create a store
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
DatabaseLayout databaseLayout = db.databaseLayout();
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
managementService.shutdown();
// Change store id component
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
long newTime = System.currentTimeMillis() + 1;
MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.TIME, newTime, databaseLayout.getDatabaseName(), NULL);
}
// Try to start
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
try {
db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
assertFalse(db.isAvailable(10));
DatabaseStateService dbStateService = db.getDependencyResolver().resolveDependency(DatabaseStateService.class);
Optional<Throwable> cause = dbStateService.causeOfFailure(db.databaseId());
assertTrue(cause.isPresent());
assertTrue(cause.get().getCause().getMessage().contains("Mismatching store id"));
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.
@Test
void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
// given
// create a store
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
managementService.shutdown();
// mess up the version in the metadatastore
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"), databaseLayout.getDatabaseName(), NULL);
}
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
assertThrows(DatabaseShutdownException.class, databaseService::beginTx);
DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
Throwable throwable = findCauseOrSuppressed(dbStateService.causeOfFailure(databaseService.databaseId()).get(), e -> e instanceof IllegalArgumentException).get();
assertEquals("Unknown store version 'bad'", throwable.getMessage());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.
the class ParallelBatchImporterTest method shouldImportCsvData.
@ParameterizedTest
@MethodSource("params")
void shouldImportCsvData(InputIdGenerator inputIdGenerator, IdType idType) throws Exception {
this.inputIdGenerator = inputIdGenerator;
// GIVEN
ExecutionMonitor processorAssigner = ProcessorAssignmentStrategies.eagerRandomSaturation(config.maxNumberOfProcessors());
CapturingMonitor monitor = new CapturingMonitor(processorAssigner);
boolean successful = false;
Groups groups = new Groups();
IdGroupDistribution groupDistribution = new IdGroupDistribution(NODE_COUNT, NUMBER_OF_ID_GROUPS, random.random(), groups);
long nodeRandomSeed = random.nextLong();
long relationshipRandomSeed = random.nextLong();
var pageCacheTracer = new DefaultPageCacheTracer();
JobScheduler jobScheduler = new ThreadPoolJobScheduler();
// This will have statistically half the nodes be considered dense
Config dbConfig = Config.defaults(GraphDatabaseSettings.dense_node_threshold, RELATIONSHIPS_PER_NODE * 2);
IndexImporterFactoryImpl indexImporterFactory = new IndexImporterFactoryImpl(dbConfig);
final BatchImporter inserter = new ParallelBatchImporter(databaseLayout, fs, pageCacheTracer, config, NullLogService.getInstance(), monitor, EMPTY, dbConfig, getFormat(), ImportLogic.NO_MONITOR, jobScheduler, Collector.EMPTY, TransactionLogInitializer.getLogFilesInitializer(), indexImporterFactory, INSTANCE);
LongAdder propertyCount = new LongAdder();
LongAdder relationshipCount = new LongAdder();
try {
// WHEN
inserter.doImport(Input.input(nodes(nodeRandomSeed, NODE_COUNT, config.batchSize(), inputIdGenerator, groupDistribution, propertyCount), relationships(relationshipRandomSeed, RELATIONSHIP_COUNT, config.batchSize(), inputIdGenerator, groupDistribution, propertyCount, relationshipCount), idType, knownEstimates(NODE_COUNT, RELATIONSHIP_COUNT, NODE_COUNT * TOKENS.length / 2, RELATIONSHIP_COUNT * TOKENS.length / 2, NODE_COUNT * TOKENS.length / 2 * Long.BYTES, RELATIONSHIP_COUNT * TOKENS.length / 2 * Long.BYTES, NODE_COUNT * TOKENS.length / 2), groups));
assertThat(pageCacheTracer.pins()).isGreaterThan(0);
assertThat(pageCacheTracer.pins()).isEqualTo(pageCacheTracer.unpins());
assertThat(pageCacheTracer.pins()).isEqualTo(Math.addExact(pageCacheTracer.faults(), pageCacheTracer.hits()));
// THEN
DatabaseManagementService managementService = getDBMSBuilder(databaseLayout).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
inputIdGenerator.reset();
verifyData(NODE_COUNT, RELATIONSHIP_COUNT, db, tx, groupDistribution, nodeRandomSeed, relationshipRandomSeed);
tx.commit();
} finally {
managementService.shutdown();
}
assertConsistent(databaseLayout);
successful = true;
} finally {
jobScheduler.close();
if (!successful) {
Path failureFile = databaseLayout.databaseDirectory().resolve("input");
try (PrintStream out = new PrintStream(Files.newOutputStream(failureFile))) {
out.println("Seed used in this failing run: " + random.seed());
out.println(inputIdGenerator);
inputIdGenerator.reset();
out.println();
out.println("Processor assignments");
out.println(processorAssigner.toString());
}
System.err.println("Additional debug information stored in " + failureFile);
}
}
}
Aggregations