use of org.icij.datashare.tasks.BatchSearchLoop in project datashare by ICIJ.
the class BatchSearchLoopTestInt method test_main_loop_exit_with_sigterm_when_empty_batch_queue.
@Test
public void test_main_loop_exit_with_sigterm_when_empty_batch_queue() throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
BatchSearchLoop app = new BatchSearchLoop(repository, batchSearchQueue, factory, countDownLatch);
executor.submit(app::run);
countDownLatch.await();
Signal term = new Signal("TERM");
Signal.raise(term);
executor.shutdown();
assertThat(executor.awaitTermination(1, TimeUnit.SECONDS)).isTrue();
}
use of org.icij.datashare.tasks.BatchSearchLoop in project datashare by ICIJ.
the class BatchSearchLoopTestInt method test_main_loop_exit_with_sigterm_and_queued_batches.
@Test
public void test_main_loop_exit_with_sigterm_and_queued_batches() throws InterruptedException {
SleepingBatchSearchRunner batchSearchRunner = new SleepingBatchSearchRunner(100);
when(factory.createBatchSearchRunner(any(), any())).thenReturn(batchSearchRunner);
BatchSearch bs1 = new BatchSearch(Project.project("prj"), "name1", "desc", CollectionUtils.asSet("query1"), local());
BatchSearch bs2 = new BatchSearch(Project.project("prj"), "name2", "desc", CollectionUtils.asSet("query2"), local());
BatchSearchLoop app = new BatchSearchLoop(repository, batchSearchQueue, factory);
batchSearchQueue.add(bs1.uuid);
batchSearchQueue.add(bs2.uuid);
when(repository.get(bs1.uuid)).thenReturn(bs1);
when(repository.get(bs2.uuid)).thenReturn(bs2);
executor.submit(app::run);
waitQueueToHaveSize(1);
Signal term = new Signal("TERM");
Signal.raise(term);
executor.shutdown();
assertThat(executor.awaitTermination(2, TimeUnit.SECONDS)).isTrue();
assertThat(batchSearchQueue).excludes("poison");
assertThat(batchSearchQueue).containsOnly(bs1.uuid, bs2.uuid);
}
use of org.icij.datashare.tasks.BatchSearchLoop in project datashare by ICIJ.
the class BatchSearchLoopTestInt method test_main_loop_exit_with_sigterm_when_running_batch.
@Test
public void test_main_loop_exit_with_sigterm_when_running_batch() throws InterruptedException {
SleepingBatchSearchRunner batchSearchRunner = new SleepingBatchSearchRunner(100);
when(factory.createBatchSearchRunner(any(), any())).thenReturn(batchSearchRunner);
BatchSearchLoop app = new BatchSearchLoop(repository, batchSearchQueue, factory);
batchSearchQueue.add(batchSearch.uuid);
executor.submit(app::run);
waitQueueToBeEmpty();
Signal term = new Signal("TERM");
Signal.raise(term);
executor.shutdown();
assertThat(executor.awaitTermination(2, TimeUnit.SECONDS)).isTrue();
assertThat(batchSearchRunner.cancelAsked).isTrue();
verify(repository).reset(batchSearch.uuid);
}
use of org.icij.datashare.tasks.BatchSearchLoop in project datashare by ICIJ.
the class BatchSearchLoopTestInt method test_main_loop_exit_with_sigterm_and_wait_for_cancellation_to_terminate.
@Test
public void test_main_loop_exit_with_sigterm_and_wait_for_cancellation_to_terminate() throws InterruptedException {
DatashareTime.setMockTime(true);
Date beforeTest = DatashareTime.getInstance().now();
CountDownLatch countDownLatch = new CountDownLatch(1);
SleepingBatchSearchRunner batchSearchRunner = new SleepingBatchSearchRunner(100, countDownLatch);
when(factory.createBatchSearchRunner(any(), any())).thenReturn(batchSearchRunner);
batchSearchQueue.add(batchSearch.uuid);
BatchSearchLoop app = new BatchSearchLoop(repository, batchSearchQueue, factory);
executor.submit(app::run);
countDownLatch.await();
Signal term = new Signal("TERM");
Signal.raise(term);
executor.shutdown();
assertThat(executor.awaitTermination(1, TimeUnit.SECONDS)).isTrue();
assertThat(DatashareTime.getInstance().now().getTime() - beforeTest.getTime()).isEqualTo(100);
assertThat(batchSearchQueue).containsOnly(batchSearch.uuid);
verify(repository).reset(batchSearch.uuid);
}
use of org.icij.datashare.tasks.BatchSearchLoop in project datashare by ICIJ.
the class BatchSearchLoopTestInt method test_run_batch_search_failure.
@Test
public void test_run_batch_search_failure() throws Exception {
when(factory.createBatchSearchRunner(any(), any())).thenThrow(new SearchException("query", new RuntimeException()));
BatchSearchLoop app = new BatchSearchLoop(repository, batchSearchQueue, factory);
batchSearchQueue.add(batchSearch.uuid);
app.enqueuePoison();
app.run();
verify(repository).setState(batchSearch.uuid, BatchSearch.State.RUNNING);
verify(repository).setState(eq(batchSearch.uuid), any(SearchException.class));
}
Aggregations