Search in sources :

Example 6 with BatchSearch

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

the class BatchSearchRunnerTest method test_run_batch_search_with_throttle_should_not_last_more_than_max_time.

@Test
public void test_run_batch_search_with_throttle_should_not_last_more_than_max_time() throws Exception {
    mockSearch.willReturn(5, createDoc("doc").build());
    BatchSearch batchSearch = new BatchSearch("uuid1", project("test-datashare"), "name1", "desc1", asSet("query1", "query2"), new Date(), BatchSearch.State.QUEUED, local());
    Date beforeBatch = timeRule.now;
    SearchException searchException = assertThrows(SearchException.class, () -> new BatchSearchRunner(indexer, new PropertiesProvider(new HashMap<String, String>() {

        {
            put(BATCH_THROTTLE, "1000");
            put(BATCH_SEARCH_MAX_TIME, "1");
        }
    }), batchSearch, resultConsumer).call());
    assertThat(searchException.toString()).contains("Batch timed out after 1s");
    assertThat(timeRule.now().getTime() - beforeBatch.getTime()).isEqualTo(1000);
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchSearch(org.icij.datashare.batch.BatchSearch) HashMap(java.util.HashMap) SearchException(org.icij.datashare.batch.SearchException) Date(java.util.Date) Test(org.junit.Test)

Example 7 with BatchSearch

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

the class BatchSearchResourceTest method test_rerun_batch_search.

@Test
public void test_rerun_batch_search() throws InterruptedException {
    BatchSearch sourceSearch = new BatchSearch(project("prj"), "name", "description1", asSet("query 1", "query 2"), User.local());
    when(batchSearchRepository.get(User.local(), sourceSearch.uuid)).thenReturn(sourceSearch);
    when(batchSearchRepository.save(any())).thenReturn(true);
    post("/api/batch/search/copy/" + sourceSearch.uuid, "{\"project\":\"prj\", \"name\": \"test\", \"description\": \"test description\"}").should().respond(200);
    ArgumentCaptor<BatchSearch> argument = ArgumentCaptor.forClass(BatchSearch.class);
    verify(batchSearchRepository).save(argument.capture());
    assertThat(argument.getValue().name).isEqualTo("test");
    assertThat(argument.getValue().description).isEqualTo("test description");
    assertThat(argument.getValue().project.name).isEqualTo("prj");
    assertThat(argument.getValue().queries).isEqualTo(sourceSearch.queries);
    assertThat(argument.getValue().user).isEqualTo(sourceSearch.user);
    assertThat(argument.getValue().state).isEqualTo(BatchSearchRecord.State.QUEUED);
    assertThat(batchSearchQueue.take()).isEqualTo(argument.getValue().uuid);
}
Also used : BatchSearch(org.icij.datashare.batch.BatchSearch) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 8 with BatchSearch

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

the class BatchSearchResourceTest method test_upload_batch_search_csv_less_that_2chars_queries_are_filtered.

@Test
public void test_upload_batch_search_csv_less_that_2chars_queries_are_filtered() {
    when(batchSearchRepository.save(any())).thenReturn(true);
    Response response = postRaw("/api/batch/search/prj", "multipart/form-data;boundary=AaB03x", new MultipartContentBuilder("AaB03x").addField("name", "my batch search").addField("description", "search description").addFile(new FileUpload("csvFile").withFilename("search.csv").withContentType("text/csv").withContent("1\n" + "\n" + "query\r\n")).build()).response();
    assertThat(response.code()).isEqualTo(200);
    verify(batchSearchRepository).save(eq(new BatchSearch(response.content(), project("prj"), "my batch search", "search description", asSet("query"), new Date(), BatchSearch.State.RUNNING, User.local())));
}
Also used : Response(net.codestory.rest.Response) BatchSearch(org.icij.datashare.batch.BatchSearch) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 9 with BatchSearch

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

the class BatchSearchResourceTest method test_get_search_results_csv.

@Test
public void test_get_search_results_csv() {
    when(batchSearchRepository.get(User.local(), "batchSearchId")).thenReturn(new BatchSearch(project("prj"), "name", "desc", asSet("q1", "q2"), User.local()));
    when(batchSearchRepository.getResults(User.local(), "batchSearchId", new BatchSearchRepository.WebQuery())).thenReturn(asList(new SearchResult("q1", "docId1", "rootId1", Paths.get("/path/to/doc1"), new Date(), "content/type", 123L, 1), new SearchResult("q2", "docId2", "rootId2", Paths.get("/path/to/doc2"), new Date(), "content/type", 123L, 2)));
    get("/api/batch/search/result/csv/batchSearchId").should().respond(200).haveType("text/csv").haveHeader("Content-Disposition", "attachment;filename=\"batchSearchId.csv\"").contain(format("\"localhost:%d/#/d/prj/docId1/rootId1\",\"docId1\",\"rootId1\"", port())).contain(format("\"localhost:%d/#/d/prj/docId2/rootId2\",\"docId2\",\"rootId2\"", port()));
}
Also used : BatchSearch(org.icij.datashare.batch.BatchSearch) JooqBatchSearchRepository(org.icij.datashare.db.JooqBatchSearchRepository) BatchSearchRepository(org.icij.datashare.batch.BatchSearchRepository) SearchResult(org.icij.datashare.batch.SearchResult) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 10 with BatchSearch

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

the class BatchSearchResourceTest method test_get_queries_csv.

@Test
public void test_get_queries_csv() {
    when(batchSearchRepository.get(User.local(), "batchSearchId")).thenReturn(new BatchSearch(project("prj"), "name", "desc", asSet("q1", "q2"), User.local()));
    get("/api/batch/search/batchSearchId/queries?format=csv").should().respond(200).haveType("text/csv;charset=UTF-8").contain("q1\nq2");
}
Also used : BatchSearch(org.icij.datashare.batch.BatchSearch) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Aggregations

BatchSearch (org.icij.datashare.batch.BatchSearch)32 PropertiesProvider (org.icij.datashare.PropertiesProvider)18 Test (org.junit.Test)17 Document (org.icij.datashare.text.Document)15 AbstractProdWebServerTest (org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)9 Date (java.util.Date)6 Response (net.codestory.rest.Response)4 BatchSearchRepository (org.icij.datashare.batch.BatchSearchRepository)4 SearchException (org.icij.datashare.batch.SearchException)4 JooqBatchSearchRepository (org.icij.datashare.db.JooqBatchSearchRepository)4 User (org.icij.datashare.user.User)4 CollectionUtils.asSet (org.icij.datashare.CollectionUtils.asSet)3 SearchResult (org.icij.datashare.batch.SearchResult)3 Project.project (org.icij.datashare.text.Project.project)3 HashMap (java.util.HashMap)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 NotFoundException (net.codestory.http.errors.NotFoundException)2