Search in sources :

Example 16 with Index

use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.

the class ClientFacadeTest method testGetGetCountTimeout.

@Test
void testGetGetCountTimeout() throws IOException {
    Index index = Index.create("index");
    when(client.count(any(CountRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(countResponse);
    when(countResponse.getFailedShards()).thenReturn(0);
    when(countResponse.isTerminatedEarly()).thenReturn(true);
    var exception = assertThrows(IndexCountException.class, () -> clientFacade.getCount(index));
    assertEquals(List.of("index"), exception.getIndices());
}
Also used : CountRequest(org.elasticsearch.client.core.CountRequest) Index(org.molgenis.data.elasticsearch.generator.model.Index) Test(org.junit.jupiter.api.Test)

Example 17 with Index

use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.

the class ClientFacadeTest method testDeleteIndexThrowsException.

@Test
void testDeleteIndexThrowsException() throws IOException {
    Index index = Index.create("index");
    when(indicesClient.delete(any(DeleteIndexRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new ElasticsearchException("exception"));
    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) ElasticsearchException(org.elasticsearch.ElasticsearchException) Test(org.junit.jupiter.api.Test)

Example 18 with Index

use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.

the class ClientFacadeTest method testGetCountThrowsException.

@Test
void testGetCountThrowsException() throws IOException {
    Index index = Index.create("index");
    when(client.count(any(CountRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new ElasticsearchException("exception"));
    var exception = assertThrows(IndexCountException.class, () -> clientFacade.getCount(index));
    assertEquals(List.of("index"), exception.getIndices());
}
Also used : CountRequest(org.elasticsearch.client.core.CountRequest) Index(org.molgenis.data.elasticsearch.generator.model.Index) ElasticsearchException(org.elasticsearch.ElasticsearchException) Test(org.junit.jupiter.api.Test)

Example 19 with Index

use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.

the class ClientFacadeTest method testGetGetCountFailedShards.

@Test
void testGetGetCountFailedShards() throws IOException {
    Index index = Index.create("index");
    when(client.count(any(CountRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(countResponse);
    when(countResponse.getFailedShards()).thenReturn(1);
    when(countResponse.getShardFailures()).thenReturn(singleShardSearchFailure);
    var exception = assertThrows(IndexCountException.class, () -> clientFacade.getCount(index));
    assertEquals(List.of("index"), exception.getIndices());
}
Also used : CountRequest(org.elasticsearch.client.core.CountRequest) Index(org.molgenis.data.elasticsearch.generator.model.Index) Test(org.junit.jupiter.api.Test)

Example 20 with Index

use of org.molgenis.data.elasticsearch.generator.model.Index in project molgenis by molgenis.

the class ClientFacadeTest method testCreateIndexResponseNotAcknowledgedNoExceptions.

@Test
void testCreateIndexResponseNotAcknowledgedNoExceptions() 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))).thenReturn(createIndexResponse);
    when(createIndexResponse.isAcknowledged()).thenReturn(false);
    when(createIndexResponse.isShardsAcknowledged()).thenReturn(false);
    clientFacade.createIndex(index, indexSettings, mappings);
    verify(mockAppender).doAppend(matcher(TRACE, "Creating index 'indexname' ..."));
    verify(mockAppender).doAppend(matcher(WARN, "Index 'indexname' creation possibly failed (acknowledged=false)"));
    verify(mockAppender).doAppend(matcher(WARN, "Index 'indexname' creation possibly failed (shards_acknowledged=false)"));
    verify(mockAppender).doAppend(matcher(DEBUG, "Created index 'indexname'."));
}
Also used : IndexSettings(org.molgenis.data.elasticsearch.generator.model.IndexSettings) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) 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