use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldDoNothingWhenUsedAfterBeingStopped.
@Test(timeout = 5_000)
public void shouldDoNothingWhenUsedAfterBeingStopped() {
// Given
JobScheduler scheduler = mock(JobScheduler.class);
IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, scheduler);
jobTracker.stopAndAwaitAllJobs();
// When
jobTracker.scheduleSamplingJob(mock(IndexSamplingJob.class));
// Then
verifyZeroInteractions(scheduler);
}
use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldWaitForAllJobsToFinish.
@Test(timeout = 5_000)
public void shouldWaitForAllJobsToFinish() throws Throwable {
// Given
when(config.jobLimit()).thenReturn(2);
JobScheduler jobScheduler = new Neo4jJobScheduler();
jobScheduler.init();
final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
WaitingIndexSamplingJob job1 = new WaitingIndexSamplingJob(indexId11, latch1);
WaitingIndexSamplingJob job2 = new WaitingIndexSamplingJob(indexId22, latch1);
jobTracker.scheduleSamplingJob(job1);
jobTracker.scheduleSamplingJob(job2);
Future<?> stopping = Executors.newSingleThreadExecutor().submit(() -> {
latch2.countDown();
try {
jobTracker.awaitAllJobs(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
// When
latch2.await();
assertFalse(stopping.isDone());
latch1.countDown();
stopping.get(10, SECONDS);
// Then
assertTrue(stopping.isDone());
assertNull(stopping.get());
assertTrue(job1.executed);
assertTrue(job2.executed);
}
use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldStopAndWaitForAllJobsToFinish.
@Test(timeout = 5_000)
public void shouldStopAndWaitForAllJobsToFinish() throws Throwable {
// Given
when(config.jobLimit()).thenReturn(2);
JobScheduler jobScheduler = new Neo4jJobScheduler();
jobScheduler.init();
final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
WaitingIndexSamplingJob job1 = new WaitingIndexSamplingJob(indexId11, latch1);
WaitingIndexSamplingJob job2 = new WaitingIndexSamplingJob(indexId22, latch1);
jobTracker.scheduleSamplingJob(job1);
jobTracker.scheduleSamplingJob(job2);
Future<?> stopping = Executors.newSingleThreadExecutor().submit(() -> {
latch2.countDown();
jobTracker.stopAndAwaitAllJobs();
});
// When
latch2.await();
assertFalse(stopping.isDone());
latch1.countDown();
stopping.get(10, SECONDS);
// Then
assertTrue(stopping.isDone());
assertNull(stopping.get());
assertTrue(job1.executed);
assertTrue(job2.executed);
}
use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldNotAcceptMoreJobsThanAllowed.
@Test
public void shouldNotAcceptMoreJobsThanAllowed() throws Throwable {
// given
when(config.jobLimit()).thenReturn(1);
JobScheduler jobScheduler = new Neo4jJobScheduler();
jobScheduler.init();
final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
final DoubleLatch latch = new DoubleLatch();
final DoubleLatch waitingLatch = new DoubleLatch();
// when
assertTrue(jobTracker.canExecuteMoreSamplingJobs());
jobTracker.scheduleSamplingJob(new IndexSamplingJob() {
@Override
public void run() {
latch.startAndWaitForAllToStart();
latch.waitForAllToFinish();
}
@Override
public long indexId() {
return indexId12;
}
});
// then
latch.waitForAllToStart();
assertFalse(jobTracker.canExecuteMoreSamplingJobs());
final AtomicBoolean waiting = new AtomicBoolean(false);
new Thread(() -> {
waiting.set(true);
waitingLatch.startAndWaitForAllToStart();
jobTracker.waitUntilCanExecuteMoreSamplingJobs();
waiting.set(false);
waitingLatch.finish();
}).start();
waitingLatch.waitForAllToStart();
assertTrue(waiting.get());
latch.finish();
waitingLatch.waitForAllToFinish();
assertFalse(waiting.get());
// eventually we accept new jobs
while (!jobTracker.canExecuteMoreSamplingJobs()) {
Thread.yield();
}
}
use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class QueryLoggerKernelExtension method newInstance.
@Override
public Lifecycle newInstance(@SuppressWarnings("unused") KernelContext context, final Dependencies dependencies) throws Throwable {
final Config config = dependencies.config();
boolean queryLogEnabled = config.get(GraphDatabaseSettings.log_queries);
final File queryLogFile = config.get(GraphDatabaseSettings.log_queries_filename);
final FileSystemAbstraction fileSystem = dependencies.fileSystem();
final JobScheduler jobScheduler = dependencies.jobScheduler();
final Monitors monitoring = dependencies.monitoring();
if (!queryLogEnabled) {
return createEmptyAdapter();
}
return new LifecycleAdapter() {
Closeable closable;
@Override
public void init() throws Throwable {
Long thresholdMillis = config.get(GraphDatabaseSettings.log_queries_threshold);
Long rotationThreshold = config.get(GraphDatabaseSettings.log_queries_rotation_threshold);
int maxArchives = config.get(GraphDatabaseSettings.log_queries_max_archives);
boolean logQueryParameters = config.get(GraphDatabaseSettings.log_queries_parameter_logging_enabled);
FormattedLog.Builder logBuilder = FormattedLog.withUTCTimeZone();
Log log;
if (rotationThreshold == 0) {
OutputStream logOutputStream = createOrOpenAsOuputStream(fileSystem, queryLogFile, true);
log = logBuilder.toOutputStream(logOutputStream);
closable = logOutputStream;
} else {
RotatingFileOutputStreamSupplier rotatingSupplier = new RotatingFileOutputStreamSupplier(fileSystem, queryLogFile, rotationThreshold, 0, maxArchives, jobScheduler.executor(JobScheduler.Groups.queryLogRotation));
log = logBuilder.toOutputStream(rotatingSupplier);
closable = rotatingSupplier;
}
QueryLogger logger = new QueryLogger(Clocks.systemClock(), log, thresholdMillis, logQueryParameters);
monitoring.addMonitorListener(logger);
}
@Override
public void shutdown() throws Throwable {
closable.close();
}
};
}
Aggregations