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);
}
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);
}
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())));
}
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()));
}
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");
}
Aggregations