Search in sources :

Example 11 with Index

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());
}
Also used : DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) Index(org.molgenis.data.elasticsearch.generator.model.Index) Test(org.junit.jupiter.api.Test)

Example 12 with Index

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());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Index(org.molgenis.data.elasticsearch.generator.model.Index) Test(org.junit.jupiter.api.Test)

Example 13 with Index

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());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Index(org.molgenis.data.elasticsearch.generator.model.Index) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) Test(org.junit.jupiter.api.Test)

Example 14 with Index

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());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Index(org.molgenis.data.elasticsearch.generator.model.Index) ElasticsearchException(org.elasticsearch.ElasticsearchException) Test(org.junit.jupiter.api.Test)

Example 15 with Index

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());
}
Also used : IndexSettings(org.molgenis.data.elasticsearch.generator.model.IndexSettings) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) Index(org.molgenis.data.elasticsearch.generator.model.Index) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Index (org.molgenis.data.elasticsearch.generator.model.Index)37 Test (org.junit.jupiter.api.Test)23 ElasticsearchException (org.elasticsearch.ElasticsearchException)13 SearchRequest (org.elasticsearch.action.search.SearchRequest)10 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)6 IOException (java.io.IOException)5 CountRequest (org.elasticsearch.client.core.CountRequest)5 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)5 IndexSettings (org.molgenis.data.elasticsearch.generator.model.IndexSettings)5 Mapping (org.molgenis.data.elasticsearch.generator.model.Mapping)5 UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)5 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)4 GetIndexRequest (org.elasticsearch.client.indices.GetIndexRequest)4 IndexRequest (org.elasticsearch.action.index.IndexRequest)3 Document (org.molgenis.data.elasticsearch.generator.model.Document)3 FieldMapping (org.molgenis.data.elasticsearch.generator.model.FieldMapping)3 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)2 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2