Search in sources :

Example 1 with BatchSearchLoop

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();
}
Also used : Signal(sun.misc.Signal) BatchSearchLoop(org.icij.datashare.tasks.BatchSearchLoop) Test(org.junit.Test)

Example 2 with BatchSearchLoop

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);
}
Also used : Signal(sun.misc.Signal) BatchSearch(org.icij.datashare.batch.BatchSearch) BatchSearchLoop(org.icij.datashare.tasks.BatchSearchLoop) Test(org.junit.Test)

Example 3 with BatchSearchLoop

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);
}
Also used : Signal(sun.misc.Signal) BatchSearchLoop(org.icij.datashare.tasks.BatchSearchLoop) Test(org.junit.Test)

Example 4 with BatchSearchLoop

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);
}
Also used : Signal(sun.misc.Signal) BatchSearchLoop(org.icij.datashare.tasks.BatchSearchLoop) Date(java.util.Date) Test(org.junit.Test)

Example 5 with BatchSearchLoop

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));
}
Also used : SearchException(org.icij.datashare.batch.SearchException) BatchSearchLoop(org.icij.datashare.tasks.BatchSearchLoop) Test(org.junit.Test)

Aggregations

BatchSearchLoop (org.icij.datashare.tasks.BatchSearchLoop)8 Test (org.junit.Test)7 Signal (sun.misc.Signal)4 Guice.createInjector (com.google.inject.Guice.createInjector)1 Injector (com.google.inject.Injector)1 Date (java.util.Date)1 BatchSearch (org.icij.datashare.batch.BatchSearch)1 SearchException (org.icij.datashare.batch.SearchException)1 TaskFactory (org.icij.datashare.tasks.TaskFactory)1 Indexer (org.icij.datashare.text.indexing.Indexer)1