use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.
the class ClientFacadeTest method testDeleteIndexNotAcknowledged.
@Test
void testDeleteIndexNotAcknowledged() throws IOException {
Index index = Index.create("index");
when(indicesClient.delete(any(DeleteIndexRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(deleteIndexResponse);
when(deleteIndexResponse.isAcknowledged()).thenReturn(false);
var exception = assertThrows(IndexDeleteException.class, () -> clientFacade.deleteIndex(index));
assertEquals(List.of("index"), exception.getIndices());
}
use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.
the class ClientFacadeTest method testAggregateResultHasShardFailures.
@Test
void testAggregateResultHasShardFailures() throws IOException {
Index index = Index.create("index");
when(client.search(any(SearchRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(searchResponse);
when(searchResponse.getFailedShards()).thenReturn(1);
when(searchResponse.getShardFailures()).thenReturn(singleShardSearchFailure);
var aggregations = List.of(aggregationBuilder);
var exception = assertThrows(AggregationException.class, () -> clientFacade.aggregate(aggregations, queryBuilder, index));
assertEquals(List.of("index"), exception.getIndices());
assertEquals("indices:index, detailMessage:{\"shard\":1,\"index\":\"cluster:index\",\"node\":\"node\",\"reason\":{\"type\":\"i_o_exception\",\"reason\":\"reason\"}}", exception.getMessage());
}
use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.
the class ClientFacadeTest method testAggregateThrowsResourceNotFoundException.
@Test
void testAggregateThrowsResourceNotFoundException() throws IOException {
Index index = Index.create("index");
when(client.search(any(SearchRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new ResourceNotFoundException("Exception"));
when(queryBuilder.toString()).thenReturn("a == b");
var aggregations = ImmutableList.of(aggregationBuilder);
var exception = assertThrows(UnknownIndexException.class, () -> clientFacade.aggregate(aggregations, queryBuilder, index));
assertEquals(List.of("index"), exception.getIndices());
}
use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.
the class ClientFacadeTest method testAggregateThrowsException.
@Test
void testAggregateThrowsException() throws IOException {
Index index = Index.create("index");
when(client.search(any(SearchRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new ElasticsearchException("Exception"));
when(queryBuilder.toString()).thenReturn("a == b");
var aggregations = List.of(aggregationBuilder);
var exception = assertThrows(AggregationException.class, () -> clientFacade.aggregate(aggregations, queryBuilder, index));
assertEquals(List.of("index"), exception.getIndices());
}
use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.
the class ClientFacadeTest method testCreateIndexAlreadyExists.
@Test
void testCreateIndexAlreadyExists() throws IOException {
Index index = Index.create("indexname");
IndexSettings indexSettings = IndexSettings.create(1, 1);
FieldMapping idField = FieldMapping.create("id", MappingType.TEXT, emptyList());
Mapping mapping = Mapping.create("type", ImmutableList.of(idField));
Stream<Mapping> mappings = Stream.of(mapping);
when(indicesClient.create(any(CreateIndexRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new ResourceAlreadyExistsException("Index already exists"));
var exception = assertThrows(IndexAlreadyExistsException.class, () -> clientFacade.createIndex(index, indexSettings, mappings));
assertEquals(List.of("indexname"), exception.getIndices());
}
Aggregations