Skip to content

Commit cc0080c

Browse files
author
jaserud
authored
short circuit empty Map if no index (#49)
* short circuit empty Map if no index * add test to check single index create and release with release rotation * rename for more clarity * fix comment
1 parent dc433a9 commit cc0080c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/java/bio/overture/rollcall/repository/IndexRepository.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ public boolean deleteIndices(@NonNull String... indices) {
140140
}
141141

142142
@SneakyThrows
143-
public Map<String, Date> getIndicesMappedToCreationDate(String... indices) {
143+
public Map<String, Date> getIndicesMappedToCreationDate(@NonNull String... indices) {
144+
if (indices.length == 0) {
145+
return Map.of();
146+
}
147+
144148
val response = client.indices().get(new GetIndexRequest(indices).indicesOptions(IndicesOptions.lenientExpand()), RequestOptions.DEFAULT);
145149

146150
val indicesSettings = response.getSettings();

src/test/java/bio/overture/rollcall/service/AliasServiceTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ public void testReleaseNonDestructiveFailurePreFlight() {
126126
assertThat(state2.get(INDEX2).get(0).alias()).isEqualTo("file_centric");
127127
}
128128

129+
@Test
130+
@SneakyThrows
131+
public void testReleaseNewIndexWithRotationOn() {
132+
val NEW_INDEX = "file_centric_sd_asdfca_re_1";
133+
client.indices().create(new CreateIndexRequest(NEW_INDEX), RequestOptions.DEFAULT);
134+
135+
// release re_1 for index shard sd_asdfca
136+
val request1 = new AliasRequest("file_centric", "re_1", Lists.list( "sd_asdfca"));
137+
service.release(request1);
138+
139+
// verify aliases assigned to indices
140+
val state1 = repository.getAliasState();
141+
assertThat(state1.get(NEW_INDEX).get(0).alias()).isEqualTo("file_centric");
142+
}
143+
129144
@Test
130145
@SneakyThrows
131146
public void testReleaseAndDeleteOldIndices() {

0 commit comments

Comments
 (0)