use of org.molgenis.data.elasticsearch.generator.model.IndexSettings 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());
}
use of org.molgenis.data.elasticsearch.generator.model.IndexSettings 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'."));
}
use of org.molgenis.data.elasticsearch.generator.model.IndexSettings in project molgenis by molgenis.
the class ClientFacadeTest method testCreateIndexThrowsElasticsearchException.
@Test
void testCreateIndexThrowsElasticsearchException() 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 ElasticsearchException("error creating index"));
var exception = assertThrows(IndexCreateException.class, () -> clientFacade.createIndex(index, indexSettings, mappings));
assertEquals(List.of("indexname"), exception.getIndices());
}
use of org.molgenis.data.elasticsearch.generator.model.IndexSettings in project molgenis by molgenis.
the class ElasticsearchService method createIndex.
@Override
public void createIndex(EntityType entityType) {
Index index = contentGenerators.createIndex(entityType);
IndexSettings indexSettings = IndexSettings.create();
Mapping mapping = contentGenerators.createMapping(entityType);
clientFacade.createIndex(index, indexSettings, Stream.of(mapping));
}
Aggregations