Search in sources :

Example 16 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class TaskManagerRedisTest method test_start_task.

@Test
public void test_start_task() {
    BatchDownload batchDownload = new BatchDownload(project("prj"), User.local(), "foo", Paths.get("dir"), false);
    BatchDownloadRunner downloadTask = new BatchDownloadRunner(mock(Indexer.class), propertiesProvider, batchDownload, t -> null);
    assertThat(taskManager.startTask(downloadTask, new HashMap<String, Object>() {

        {
            put("batchDownload", batchDownload);
        }
    })).isNotNull();
    assertThat(taskManager.get()).hasSize(1);
    assertThat(batchDownloadQueue).hasSize(1);
    assertThat(redis.hlen("test:task:manager")).isEqualTo(1);
}
Also used : BatchDownload(org.icij.datashare.batch.BatchDownload) Indexer(org.icij.datashare.text.indexing.Indexer) Test(org.junit.Test)

Example 17 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadLoopTest method test_loop.

@Test
public void test_loop() throws Exception {
    BatchDownloadCleaner batchDownloadCleaner = mock(BatchDownloadCleaner.class);
    BatchDownloadLoop app = new BatchDownloadLoop(new PropertiesProvider(), batchDownloadQueue, factory, manager) {

        @Override
        public BatchDownloadCleaner createDownloadCleaner(Path downloadDir, int ttlHour) {
            return batchDownloadCleaner;
        }
    };
    batchDownloadQueue.add(new BatchDownload(project("prj"), User.local(), "query"));
    app.enqueuePoison();
    app.run();
    verify(batchRunner).call();
    verify(manager).save(argCaptor.capture());
    verify(batchDownloadCleaner, times(2)).run();
    assertThat(argCaptor.getValue().getState()).isEqualTo(TaskView.State.DONE);
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Path(java.nio.file.Path) BatchDownload(org.icij.datashare.batch.BatchDownload) Test(org.junit.Test)

Example 18 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadLoopTest method test_elasticsearch_exception__should_not_be_serialized.

@Test
public void test_elasticsearch_exception__should_not_be_serialized() throws Exception {
    when(batchRunner.call()).thenThrow(new ElasticsearchStatusException("error", RestStatus.BAD_REQUEST, new RuntimeException()));
    BatchDownloadCleaner batchDownloadCleaner = mock(BatchDownloadCleaner.class);
    BatchDownloadLoop app = new BatchDownloadLoop(new PropertiesProvider(), batchDownloadQueue, factory, manager) {

        @Override
        public BatchDownloadCleaner createDownloadCleaner(Path downloadDir, int ttlHour) {
            return batchDownloadCleaner;
        }
    };
    batchDownloadQueue.add(new BatchDownload(project("prj"), User.local(), "query"));
    app.enqueuePoison();
    app.run();
    verify(manager).save(argCaptor.capture());
    assertThat(argCaptor.getValue().getState()).isEqualTo(TaskView.State.ERROR);
    assertThat(argCaptor.getValue().error.getClass()).isNotEqualTo(ElasticsearchStatusException.class);
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Path(java.nio.file.Path) BatchDownload(org.icij.datashare.batch.BatchDownload) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) Test(org.junit.Test)

Example 19 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadRunnerTest method test_elasticsearch_status_exception__should_be_sent.

@Test(expected = ElasticsearchStatusException.class)
public void test_elasticsearch_status_exception__should_be_sent() throws Exception {
    mockSearch.willThrow(new ElasticsearchStatusException("error", RestStatus.BAD_REQUEST, new RuntimeException()));
    new BatchDownloadRunner(indexer, new PropertiesProvider(), new BatchDownload(project("test-datashare"), User.local(), "query"), updater).call();
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchDownload(org.icij.datashare.batch.BatchDownload) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) Test(org.junit.Test)

Example 20 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadRunnerTest method test_max_zip_size.

@Test
public void test_max_zip_size() throws Exception {
    Document[] documents = IntStream.range(0, 3).mapToObj(i -> createDoc("doc" + i).with(createFile(i)).with("hello world " + i).build()).toArray(Document[]::new);
    mockSearch.willReturn(2, documents);
    File zip = new BatchDownloadRunner(indexer, new PropertiesProvider(new HashMap<String, String>() {

        {
            put(BATCH_DOWNLOAD_MAX_SIZE, valueOf("hello world 1".getBytes(StandardCharsets.UTF_8).length * 3));
            put(SCROLL_SIZE, "3");
        }
    }), new BatchDownload(project("test-datashare"), User.local(), "query"), updater).call();
    assertThat(new ZipFile(zip).size()).isEqualTo(4);
}
Also used : IntStream(java.util.stream.IntStream) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Mock(org.mockito.Mock) HashMap(java.util.HashMap) Function(java.util.function.Function) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) DatashareCliOptions(org.icij.datashare.cli.DatashareCliOptions) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) User(org.icij.datashare.user.User) ZipFile(java.util.zip.ZipFile) Project.project(org.icij.datashare.text.Project.project) BatchDownload(org.icij.datashare.batch.BatchDownload) Path(java.nio.file.Path) Before(org.junit.Before) PropertiesProvider(org.icij.datashare.PropertiesProvider) Files(java.nio.file.Files) DocumentBuilder.createDoc(org.icij.datashare.text.DocumentBuilder.createDoc) Indexer(org.icij.datashare.text.indexing.Indexer) Test(org.junit.Test) IOException(java.io.IOException) Document(org.icij.datashare.text.Document) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Rule(org.junit.Rule) String.valueOf(java.lang.String.valueOf) RestStatus(org.elasticsearch.rest.RestStatus) TemporaryFolder(org.junit.rules.TemporaryFolder) PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchDownload(org.icij.datashare.batch.BatchDownload) ZipFile(java.util.zip.ZipFile) Document(org.icij.datashare.text.Document) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Aggregations

BatchDownload (org.icij.datashare.batch.BatchDownload)21 ZipFile (java.util.zip.ZipFile)9 PropertiesProvider (org.icij.datashare.PropertiesProvider)8 File (java.io.File)7 Test (org.junit.Test)7 Path (java.nio.file.Path)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)4 Function (java.util.function.Function)3 Assertions.assertThat (org.fest.assertions.Assertions.assertThat)3 Project.project (org.icij.datashare.text.Project.project)3 Indexer (org.icij.datashare.text.indexing.Indexer)3 User (org.icij.datashare.user.User)3 TemporaryFolder (org.junit.rules.TemporaryFolder)3 Mock (org.mockito.Mock)3 MockitoAnnotations.initMocks (org.mockito.MockitoAnnotations.initMocks)3 String.valueOf (java.lang.String.valueOf)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2