use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.
the class HttpTransactionManagerTest method newTransactionManager.
private static HttpTransactionManager newTransactionManager(DatabaseManagementService managementService, MemoryPool memoryPool) {
JobScheduler jobScheduler = mock(JobScheduler.class);
AssertableLogProvider logProvider = new AssertableLogProvider(true);
var defaultDatabase = "neo4j";
when(managementService.database(any(String.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
String db = (String) args[0];
if (db.equals(defaultDatabase) || db.equals("system")) {
return graphWithName(db);
} else {
throw new DatabaseNotFoundException("Not found db named " + db);
}
});
return new HttpTransactionManager(managementService, memoryPool, jobScheduler, Clocks.systemClock(), Duration.ofMinutes(1), logProvider);
}
use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldDoNothingWhenUsedAfterBeingStopped.
@Test
void shouldDoNothingWhenUsedAfterBeingStopped() {
// Given
JobScheduler scheduler = mock(JobScheduler.class);
IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(scheduler, "test database");
jobTracker.stopAndAwaitAllJobs();
// When
jobTracker.scheduleSamplingJob(mock(IndexSamplingJob.class));
// Then
verifyNoInteractions(scheduler);
}
use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.
the class BlockBasedIndexPopulatorTest method shouldScheduleMergeOnJobSchedulerWithCorrectGroup.
@Test
void shouldScheduleMergeOnJobSchedulerWithCorrectGroup() throws IndexEntryConflictException, IOException {
// given
BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR);
boolean closed = false;
try {
populator.add(batchOfUpdates(), NULL);
// when
MutableBoolean called = new MutableBoolean();
JobScheduler trackingJobScheduler = new JobSchedulerAdapter() {
@Override
public <T> JobHandle<T> schedule(Group group, JobMonitoringParams jobMonitoringParams, Callable<T> job) {
called.setTrue();
assertThat(group).isSameAs(Group.INDEX_POPULATION_WORK);
return jobScheduler.schedule(group, jobMonitoringParams, job);
}
};
populator.scanCompleted(nullInstance, wrapScheduler(trackingJobScheduler), NULL);
assertTrue(called.booleanValue());
populator.close(true, NULL);
closed = true;
} finally {
if (!closed) {
populator.close(true, NULL);
}
}
}
use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.
the class BatchingNeoStoresTest method someDataInTheDatabase.
private void someDataInTheDatabase(Config config) throws Exception {
NullLog nullLog = NullLog.getInstance();
try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
PageCache pageCache = new ConfiguringPageCacheFactory(fileSystem, Config.defaults(), PageCacheTracer.NULL, nullLog, scheduler, Clocks.nanoClock(), new MemoryPools()).getOrCreatePageCache();
Lifespan life = new Lifespan()) {
// TODO this little dance with TokenHolders is really annoying and must be solved with a better abstraction
DeferredInitializedTokenCreator propertyKeyTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.propertyKeyDoCreateForName(name, internal, id);
}
};
DeferredInitializedTokenCreator labelTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.labelDoCreateForName(name, internal, id);
}
};
DeferredInitializedTokenCreator relationshipTypeTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.relationshipTypeDoCreateForName(name, internal, id);
}
};
TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(labelTokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(relationshipTypeTokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
IndexConfigCompleter indexConfigCompleter = index -> index;
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = immediate();
RecordStorageEngine storageEngine = life.add(new RecordStorageEngine(databaseLayout, Config.defaults(), pageCache, fileSystem, NullLogProvider.getInstance(), tokenHolders, new DatabaseSchemaState(NullLogProvider.getInstance()), new StandardConstraintSemantics(), indexConfigCompleter, LockService.NO_LOCK_SERVICE, new DatabaseHealth(PanicEventGenerator.NO_OP, nullLog), new DefaultIdGeneratorFactory(fileSystem, immediate(), DEFAULT_DATABASE_NAME), new DefaultIdController(), recoveryCleanupWorkCollector, PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE));
// Create the relationship type token
TxState txState = new TxState();
NeoStores neoStores = storageEngine.testAccessNeoStores();
CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE);
commandCreationContext.initialize(NULL);
propertyKeyTokenCreator.initialize(neoStores.getPropertyKeyTokenStore(), txState);
labelTokenCreator.initialize(neoStores.getLabelTokenStore(), txState);
relationshipTypeTokenCreator.initialize(neoStores.getRelationshipTypeTokenStore(), txState);
int relTypeId = tokenHolders.relationshipTypeTokens().getOrCreateId(RELTYPE.name());
apply(txState, commandCreationContext, storageEngine);
// Finally, we're initialized and ready to create two nodes and a relationship
txState = new TxState();
long node1 = commandCreationContext.reserveNode();
long node2 = commandCreationContext.reserveNode();
txState.nodeDoCreate(node1);
txState.nodeDoCreate(node2);
txState.relationshipDoCreate(commandCreationContext.reserveRelationship(), relTypeId, node1, node2);
apply(txState, commandCreationContext, storageEngine);
neoStores.flush(NULL);
}
}
use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.
the class HumanUnderstandableExecutionMonitorIT method shouldReportProgressOfNodeImport.
@Test
void shouldReportProgressOfNodeImport() throws Exception {
// given
CapturingMonitor progress = new CapturingMonitor();
HumanUnderstandableExecutionMonitor monitor = new HumanUnderstandableExecutionMonitor(progress);
IdType idType = IdType.INTEGER;
Input input = new DataGeneratorInput(NODE_COUNT, RELATIONSHIP_COUNT, idType, random.seed(), 0, bareboneNodeHeader(idType, new Extractors(';')), bareboneRelationshipHeader(idType, new Extractors(';')), 1, 1, 0, 0);
Configuration configuration = new Configuration.Overridden(Configuration.DEFAULT) {
@Override
public long pageCacheMemory() {
return mebiBytes(8);
}
};
// when
try (JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
new ParallelBatchImporter(databaseLayout, fileSystem, NULL, configuration, NullLogService.getInstance(), monitor, EMPTY, defaults(), LATEST_RECORD_FORMATS, ImportLogic.NO_MONITOR, jobScheduler, Collector.EMPTY, LogFilesInitializer.NULL, IndexImporterFactory.EMPTY, EmptyMemoryTracker.INSTANCE).doImport(input);
// then
progress.assertAllProgressReachedEnd();
}
}
Aggregations