Skip to content

Commit

Permalink
Update unit tests to address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Hai Yan <[email protected]>
  • Loading branch information
oeyh committed Jan 23, 2024
1 parent 14e2747 commit 6223ef5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,28 @@ void setup() throws IOException {
}

@Test
void getIndexAlias_IndexWithTimePattern(){
void getIndexAlias_IndexWithTimePattern() throws IOException {
when(indexConfiguration.getIndexAlias()).thenReturn(INDEX_ALIAS_WITH_TIME_PATTERN);
defaultIndexManager = indexManagerFactory.getIndexManager(
IndexType.CUSTOM, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
try {
final String indexAlias = defaultIndexManager.getIndexName(null);
assertThat(indexAlias, matchesPattern(EXPECTED_INDEX_PATTERN));
} catch (IOException e){}

final String indexAlias = defaultIndexManager.getIndexName(null);
assertThat(indexAlias, matchesPattern(EXPECTED_INDEX_PATTERN));

verify(openSearchSinkConfiguration, times(2)).getIndexConfiguration();
verify(indexConfiguration).getIndexAlias();
verify(indexConfiguration).getIsmPolicyFile();
}

@Test
void getIndexAlias_IndexWithTimePattern_NotAsSuffix() {
void getIndexAlias_IndexWithTimePattern_NotAsSuffix() throws IOException {
when(indexConfiguration.getIndexAlias()).thenReturn(INDEX_ALIAS_WITH_TIME_PATTERN + "-randomtext");
defaultIndexManager = indexManagerFactory.getIndexManager(
IndexType.CUSTOM, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
try {
final String indexAlias = defaultIndexManager.getIndexName(null);
assertThat(indexAlias, matchesPattern(Pattern.compile(INDEX_ALIAS + "-\\d{4}.\\d{2}.\\d{2}.\\d{2}-randomtext")));
} catch (IOException e){}

final String indexAlias = defaultIndexManager.getIndexName(null);
assertThat(indexAlias, matchesPattern(Pattern.compile(INDEX_ALIAS + "-\\d{4}.\\d{2}.\\d{2}.\\d{2}-randomtext")));

verify(openSearchSinkConfiguration, times(2)).getIndexConfiguration();
verify(indexConfiguration).getIndexAlias();
verify(indexConfiguration).getIsmPolicyFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,29 @@ void verifyMocksHaveNoUnnecessaryInteractions() {
}

@Test
void getIndexAlias_IndexWithTimePattern() {
void getIndexAlias_IndexWithTimePattern() throws IOException {
when(indexConfiguration.getIndexAlias()).thenReturn(indexAliasWithTimePattern);
final IndexManager objectUnderTest = indexManagerFactory.getIndexManager(
IndexType.MANAGEMENT_DISABLED, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
final Pattern expectedIndexPattern = Pattern.compile(baseIndexAlias + "-\\d{4}.\\d{2}.\\d{2}.\\d{2}");
try {
final String actualIndexPattern = objectUnderTest.getIndexName(null);
assertThat(actualIndexPattern, matchesPattern(expectedIndexPattern));
} catch (IOException e){}

final String actualIndexPattern = objectUnderTest.getIndexName(null);
assertThat(actualIndexPattern, matchesPattern(expectedIndexPattern));

verify(openSearchSinkConfiguration).getIndexConfiguration();
verify(indexConfiguration).getIndexAlias();
}

@Test
void getIndexAlias_IndexWithTimePattern_Exceptional_NotAsSuffix() {
void getIndexAlias_IndexWithTimePattern_Exceptional_NotAsSuffix() throws IOException {
when(indexConfiguration.getIndexAlias()).thenReturn(indexAliasWithTimePattern + "-randomtext");
final IndexManager objectUnderTest = indexManagerFactory.getIndexManager(
IndexType.MANAGEMENT_DISABLED, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
final Pattern expectedIndexPattern = Pattern.compile(baseIndexAlias + "-\\d{4}.\\d{2}.\\d{2}.\\d{2}-randomtext");
try {
final String actualIndexPattern = objectUnderTest.getIndexName(null);
assertThat(actualIndexPattern, matchesPattern(expectedIndexPattern));
} catch (IOException e){}

final String actualIndexPattern = objectUnderTest.getIndexName(null);
assertThat(actualIndexPattern, matchesPattern(expectedIndexPattern));

verify(openSearchSinkConfiguration).getIndexConfiguration();
verify(indexConfiguration).getIndexAlias();
}
Expand Down

0 comments on commit 6223ef5

Please sign in to comment.