Skip to content
Snippets Groups Projects
Commit 98038167 authored by Zhibin Mai's avatar Zhibin Mai
Browse files

Fix unit test

parent 98f5af45
No related branches found
No related tags found
1 merge request!496Provide an endpoint to create aliases for all existing indices that do not have aliases
Pipeline #171486 failed
...@@ -77,6 +77,8 @@ public class IndicesServiceTest { ...@@ -77,6 +77,8 @@ public class IndicesServiceTest {
private Response response; private Response response;
@Mock @Mock
private HttpEntity httpEntity; private HttpEntity httpEntity;
@Mock
private IndexAliasService indexAliasService;
@InjectMocks @InjectMocks
private IndicesServiceImpl sut; private IndicesServiceImpl sut;
...@@ -94,22 +96,19 @@ public class IndicesServiceTest { ...@@ -94,22 +96,19 @@ public class IndicesServiceTest {
@Test @Test
public void create_elasticIndex() throws Exception { public void create_elasticIndex() throws Exception {
String kind = "common:welldb:wellbore:1.2.0";
String index = "common-welldb-wellbore-1.2.0"; String index = "common-welldb-wellbore-1.2.0";
CreateIndexResponse indexResponse = new CreateIndexResponse(true, true, index); CreateIndexResponse indexResponse = new CreateIndexResponse(true, true, index);
AcknowledgedResponse acknowledgedResponse = new AcknowledgedResponse(true); AcknowledgedResponse acknowledgedResponse = new AcknowledgedResponse(true);
when(elasticIndexNameResolver.getKindFromIndexName(any())).thenReturn(kind);
when(elasticIndexNameResolver.getIndexNameFromKind(any())).thenReturn(index); when(elasticIndexNameResolver.getIndexNameFromKind(any())).thenReturn(index);
when(elasticIndexNameResolver.getIndexAliasFromKind(any())).thenReturn("a12345678");
when(elasticIndexNameResolver.isIndexAliasSupported(any())).thenReturn(true);
when(restHighLevelClient.indices()).thenReturn(indicesClient); when(restHighLevelClient.indices()).thenReturn(indicesClient);
when(indicesClient.create(any(CreateIndexRequest.class), any(RequestOptions.class))).thenReturn(indexResponse); when(indicesClient.create(any(CreateIndexRequest.class), any(RequestOptions.class))).thenReturn(indexResponse);
when(indicesClient.updateAliases(any(IndicesAliasesRequest.class), any(RequestOptions.class))).thenReturn(acknowledgedResponse); when(indicesClient.updateAliases(any(IndicesAliasesRequest.class), any(RequestOptions.class))).thenReturn(acknowledgedResponse);
boolean response = this.sut.createIndex(restHighLevelClient, index, null, "anytype", new HashMap<>()); boolean response = this.sut.createIndex(restHighLevelClient, index, null, "anytype", new HashMap<>());
assertTrue(response); assertTrue(response);
when(this.indicesExistCache.get(index)).thenReturn(true); when(this.indicesExistCache.get(index)).thenReturn(true);
verify(this.indicesClient, times(2)).updateAliases(any(IndicesAliasesRequest.class), any(RequestOptions.class)); verify(this.indexAliasService, times(1)).createIndexAlias(any(), any());
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment