Skip to content

Commit

Permalink
fixed integration tests with indexAlias
Browse files Browse the repository at this point in the history
Signed-off-by: kranthikirang <[email protected]>
  • Loading branch information
kranthikirang committed Nov 15, 2024
1 parent d06fcb8 commit 6739a56
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void checkAndCreatePolicy_Normal() throws IOException {
defaultIndexManager = indexManagerFactory.getIndexManager(
IndexType.CUSTOM, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
assertEquals(Optional.empty(), defaultIndexManager.checkAndCreatePolicy());
assertEquals(Optional.empty(), defaultIndexManager.checkAndCreatePolicy(INDEX_ALIAS));
verify(restHighLevelClient).getLowLevelClient();
verify(restClient).performRequest(any());
verify(openSearchSinkConfiguration, times(4)).getIndexConfiguration();
Expand All @@ -428,7 +428,7 @@ void checkAndCreatePolicy_Exception() throws IOException {
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
when(restClient.performRequest(any())).thenThrow(responseException);
when(responseException.getMessage()).thenReturn("Invalid field: [ism_template]");
assertThrows(ResponseException.class, () -> defaultIndexManager.checkAndCreatePolicy());
assertThrows(ResponseException.class, () -> defaultIndexManager.checkAndCreatePolicy(INDEX_ALIAS));
verify(restHighLevelClient, times(2)).getLowLevelClient();
verify(restClient, times(2)).performRequest(any());
verify(openSearchSinkConfiguration, times(2)).getIndexConfiguration();
Expand All @@ -441,7 +441,7 @@ void checkAndCreatePolicy_Exception() throws IOException {
void checkAndCreatePolicy() throws IOException {
defaultIndexManager = indexManagerFactory.getIndexManager(
IndexType.CUSTOM, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
assertEquals(Optional.empty(), defaultIndexManager.checkAndCreatePolicy());
assertEquals(Optional.empty(), defaultIndexManager.checkAndCreatePolicy(INDEX_ALIAS));
verify(indexConfiguration).getIndexAlias();
verify(openSearchSinkConfiguration, times(2)).getIndexConfiguration();
verify(indexConfiguration).getIsmPolicyFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void constructor_NullRestClient() {
@Test
public void checkAndCreatePolicy_Normal() throws IOException {
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
assertEquals(Optional.empty(), ismPolicyManagementStrategy.checkAndCreatePolicy());
assertEquals(Optional.empty(), ismPolicyManagementStrategy.checkAndCreatePolicy(INDEX_ALIAS));
verify(restHighLevelClient).getLowLevelClient();
verify(restClient).performRequest(any());
}
Expand All @@ -114,7 +114,7 @@ public void checkAndCreatePolicy_OnlyOnePolicyFile_TwoExceptions() throws IOExce
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
when(restClient.performRequest(any())).thenThrow(responseException);
when(responseException.getMessage()).thenReturn("Invalid field: [ism_template]");
assertThrows(ResponseException.class, () -> ismPolicyManagementStrategy.checkAndCreatePolicy());
assertThrows(ResponseException.class, () -> ismPolicyManagementStrategy.checkAndCreatePolicy(INDEX_ALIAS));
verify(restHighLevelClient, times(2)).getLowLevelClient();
verify(restClient, times(2)).performRequest(any());
}
Expand All @@ -129,7 +129,7 @@ public void checkAndCreatePolicy_OnlyOnePolicyFile_FirstExceptionThenSucceeds()
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
when(restClient.performRequest(any())).thenThrow(responseException).thenReturn(null);
when(responseException.getMessage()).thenReturn("Invalid field: [ism_template]");
assertEquals(Optional.of(POLICY_NAME), ismPolicyManagementStrategy.checkAndCreatePolicy());
assertEquals(Optional.of(POLICY_NAME), ismPolicyManagementStrategy.checkAndCreatePolicy(INDEX_ALIAS));
verify(restHighLevelClient, times(2)).getLowLevelClient();
verify(restClient, times(2)).performRequest(any());
}
Expand All @@ -156,7 +156,7 @@ public void checkAndCreatePolicy_with_custom_ism_policy_from_s3() throws IOExcep
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
when(restClient.performRequest(any())).thenThrow(responseException).thenReturn(null);
when(responseException.getMessage()).thenReturn("Invalid field: [ism_template]");
assertEquals(Optional.of(POLICY_NAME), ismPolicyManagementStrategyWithTemplate.checkAndCreatePolicy());
assertEquals(Optional.of(POLICY_NAME), ismPolicyManagementStrategyWithTemplate.checkAndCreatePolicy(INDEX_ALIAS));
verify(restHighLevelClient, times(2)).getLowLevelClient();
verify(restClient, times(2)).performRequest(any());
}
Expand All @@ -166,7 +166,7 @@ public void checkAndCreatePolicy_ExceptionFirstThenSucceed() throws IOException
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
when(restClient.performRequest(any())).thenThrow(responseException).thenReturn(null);
when(responseException.getMessage()).thenReturn("Invalid field: [ism_template]");
assertEquals(Optional.of(POLICY_NAME), ismPolicyManagementStrategy.checkAndCreatePolicy());
assertEquals(Optional.of(POLICY_NAME), ismPolicyManagementStrategy.checkAndCreatePolicy(INDEX_ALIAS));
verify(restHighLevelClient, times(2)).getLowLevelClient();
verify(restClient, times(2)).performRequest(any());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void constructor_NullRestClient() {

@Test
public void checkAndCreatePolicy() throws IOException {
assertEquals(Optional.empty(), ismPolicyManagementStrategy.checkAndCreatePolicy());
assertEquals(Optional.empty(), ismPolicyManagementStrategy.checkAndCreatePolicy(INDEX_ALIAS));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void checkISMEnabled_False() throws IOException {
@Test
void checkAndCreatePolicy_Normal() throws IOException {
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
assertEquals(Optional.empty(), traceAnalyticsRawIndexManager.checkAndCreatePolicy());
assertEquals(Optional.empty(), traceAnalyticsRawIndexManager.checkAndCreatePolicy(INDEX_ALIAS));
verify(openSearchSinkConfiguration).getIndexConfiguration();
verify(indexConfiguration).getIndexAlias();
verify(restHighLevelClient).getLowLevelClient();
Expand All @@ -189,7 +189,7 @@ void checkAndCreatePolicy_ExceptionFirstThenSucceeds() throws IOException {
when(restHighLevelClient.getLowLevelClient()).thenReturn(restClient);
when(restClient.performRequest(any())).thenThrow(responseException).thenReturn(null);
when(responseException.getMessage()).thenReturn("Invalid field: [ism_template]");
assertEquals(Optional.of("raw-span-policy"), traceAnalyticsRawIndexManager.checkAndCreatePolicy());
assertEquals(Optional.of("raw-span-policy"), traceAnalyticsRawIndexManager.checkAndCreatePolicy(INDEX_ALIAS));
verify(restHighLevelClient, times(2)).getLowLevelClient();
verify(restClient, times(2)).performRequest(any());
verify(openSearchSinkConfiguration).getIndexConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void checkISMEnabledByDefault_False() throws IOException {

@Test
void checkAndCreatePolicy() throws IOException {
assertEquals(Optional.empty(), traceAnalyticsServiceMapIndexManager.checkAndCreatePolicy());
assertEquals(Optional.empty(), traceAnalyticsServiceMapIndexManager.checkAndCreatePolicy(INDEX_ALIAS));
verify(openSearchSinkConfiguration).getIndexConfiguration();
verify(indexConfiguration).getIndexAlias();
}
Expand Down

0 comments on commit 6739a56

Please sign in to comment.