Skip to content

Commit bd5fed8

Browse files
committed
Test status from local current info
1 parent e2c05f7 commit bd5fed8

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,14 @@ public String name() {
389389

390390
@Override
391391
public synchronized HealthIndicatorResult calculate(boolean verbose, int maxAffectedResourcesCount, HealthInfo healthInfo) {
392-
FileSettingsHealthInfo info = healthInfo.fileSettingsHealthInfo();
392+
return calculate(healthInfo.fileSettingsHealthInfo());
393+
}
394+
395+
public HealthIndicatorResult calculateFromCurrentInfo() {
396+
return calculate(currentInfo);
397+
}
398+
399+
private HealthIndicatorResult calculate(FileSettingsHealthInfo info) {
393400
if (info.isActive() == false) {
394401
return createIndicator(GREEN, INACTIVE_SYMPTOM, HealthIndicatorDetails.EMPTY, List.of(), List.of());
395402
}

server/src/test/java/org/elasticsearch/reservedstate/service/FileSettingsHealthIndicatorServiceTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public void testInitiallyGreen() {}
4848
public void testStartAndStop() {
4949
assertEquals(
5050
new HealthIndicatorResult("file_settings", GREEN, INACTIVE_SYMPTOM, HealthIndicatorDetails.EMPTY, List.of(), List.of()),
51-
healthIndicatorService.calculate(false, null)
51+
healthIndicatorService.calculateFromCurrentInfo()
5252
);
5353
healthIndicatorService.startOccurred();
5454
assertEquals(
5555
new HealthIndicatorResult("file_settings", GREEN, NO_CHANGES_SYMPTOM, HealthIndicatorDetails.EMPTY, List.of(), List.of()),
56-
healthIndicatorService.calculate(false, null)
56+
healthIndicatorService.calculateFromCurrentInfo()
5757
);
5858
healthIndicatorService.stopOccurred();
5959
assertEquals(
6060
new HealthIndicatorResult("file_settings", GREEN, INACTIVE_SYMPTOM, HealthIndicatorDetails.EMPTY, List.of(), List.of()),
61-
healthIndicatorService.calculate(false, null)
61+
healthIndicatorService.calculateFromCurrentInfo()
6262
);
6363
}
6464

@@ -69,7 +69,7 @@ public void testGreenYellowYellowGreen() {
6969
// While the change is still in progress, we don't change the status.
7070
assertEquals(
7171
new HealthIndicatorResult("file_settings", GREEN, SUCCESS_SYMPTOM, HealthIndicatorDetails.EMPTY, List.of(), List.of()),
72-
healthIndicatorService.calculate(false, null)
72+
healthIndicatorService.calculateFromCurrentInfo()
7373
);
7474

7575
healthIndicatorService.failureOccurred("whoopsie 1");
@@ -82,7 +82,7 @@ public void testGreenYellowYellowGreen() {
8282
STALE_SETTINGS_IMPACT,
8383
List.of()
8484
),
85-
healthIndicatorService.calculate(false, null)
85+
healthIndicatorService.calculateFromCurrentInfo()
8686
);
8787

8888
healthIndicatorService.failureOccurred("whoopsie #2");
@@ -95,13 +95,13 @@ public void testGreenYellowYellowGreen() {
9595
STALE_SETTINGS_IMPACT,
9696
List.of()
9797
),
98-
healthIndicatorService.calculate(false, null)
98+
healthIndicatorService.calculateFromCurrentInfo()
9999
);
100100

101101
healthIndicatorService.successOccurred();
102102
assertEquals(
103103
new HealthIndicatorResult("file_settings", GREEN, SUCCESS_SYMPTOM, HealthIndicatorDetails.EMPTY, List.of(), List.of()),
104-
healthIndicatorService.calculate(false, null)
104+
healthIndicatorService.calculateFromCurrentInfo()
105105
);
106106
}
107107

@@ -128,7 +128,7 @@ private void checkTruncatedDescription(int lengthLimit, String description, Stri
128128
STALE_SETTINGS_IMPACT,
129129
List.of()
130130
),
131-
service.calculate(false, null)
131+
service.calculateFromCurrentInfo()
132132
);
133133
}
134134
}

server/src/test/java/org/elasticsearch/reservedstate/service/FileSettingsServiceTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void testInitialFileError() throws Exception {
233233
verify(fileSettingsService, times(1)).processFile(eq(watchedFile), eq(true));
234234
verify(controller, times(1)).process(any(), any(XContentParser.class), eq(ReservedStateVersionCheck.HIGHER_OR_SAME_VERSION), any());
235235

236-
assertEquals(YELLOW, healthIndicatorService.calculate(false, null).status());
236+
assertEquals(YELLOW, healthIndicatorService.calculateFromCurrentInfo().status());
237237
verify(healthIndicatorService, times(1)).changeOccurred();
238238
verify(healthIndicatorService, times(1)).failureOccurred(argThat(s -> s.startsWith(IllegalStateException.class.getName())));
239239
}
@@ -268,7 +268,7 @@ public void testInitialFileWorks() throws Exception {
268268
verify(fileSettingsService, times(1)).processFile(eq(watchedFile), eq(true));
269269
verify(controller, times(1)).process(any(), any(XContentParser.class), eq(ReservedStateVersionCheck.HIGHER_OR_SAME_VERSION), any());
270270

271-
assertEquals(GREEN, healthIndicatorService.calculate(false, null).status());
271+
assertEquals(GREEN, healthIndicatorService.calculateFromCurrentInfo().status());
272272
verify(healthIndicatorService, times(1)).changeOccurred();
273273
verify(healthIndicatorService, times(1)).successOccurred();
274274
}
@@ -323,7 +323,7 @@ public void testProcessFileChanges() throws Exception {
323323
verify(fileSettingsService, times(1)).processFile(eq(watchedFile), eq(false));
324324
verify(controller, times(1)).process(any(), any(XContentParser.class), eq(ReservedStateVersionCheck.HIGHER_VERSION_ONLY), any());
325325

326-
assertEquals(GREEN, healthIndicatorService.calculate(false, null).status());
326+
assertEquals(GREEN, healthIndicatorService.calculateFromCurrentInfo().status());
327327
verify(healthIndicatorService, times(2)).changeOccurred();
328328
verify(healthIndicatorService, times(2)).successOccurred();
329329
}
@@ -367,7 +367,7 @@ public void testInvalidJSON() throws Exception {
367367
argThat(e -> unwrapException(e) instanceof XContentParseException)
368368
);
369369

370-
assertEquals(YELLOW, healthIndicatorService.calculate(false, null).status());
370+
assertEquals(YELLOW, healthIndicatorService.calculateFromCurrentInfo().status());
371371
verify(healthIndicatorService, Mockito.atLeast(1)).failureOccurred(contains(XContentParseException.class.getName()));
372372
}
373373

@@ -434,7 +434,7 @@ public void testStopWorksInMiddleOfProcessing() throws Exception {
434434
fileSettingsService.close();
435435

436436
// When the service is stopped, the health indicator should be green
437-
assertEquals(GREEN, healthIndicatorService.calculate(false, null).status());
437+
assertEquals(GREEN, healthIndicatorService.calculateFromCurrentInfo().status());
438438
verify(healthIndicatorService).stopOccurred();
439439

440440
// let the deadlocked thread end, so we can cleanly exit the test

0 commit comments

Comments
 (0)