AcsHealthAggregator implements HealthAggregator { @Override public final Health aggregate(final Map<String, Health> healths) { List<Status> statusCandidates = new ArrayList<>(); for (Map.Entry<String, Health> entry : healths.entrySet()) { Status status = entry.getValue().getStatus(); if (entry.getKey().toLowerCase().contains("cache")) { if (status.equals(Status.DOWN)) { statusCandidates.add(DEGRADED_STATUS); } else if (status.equals(Status.UNKNOWN)) { statusCandidates.add(Status.UP); } } else { statusCandidates.add(entry.getValue().getStatus()); } } Status status = this.aggregateStatus(statusCandidates); Map<String, Object> details = aggregateDetails(healths); return new Health.Builder(status, details).build(); } AcsHealthAggregator(); @Override final Health aggregate(final Map<String, Health> healths);  }
@Test public void defaultOrder() { Map<String, Health> healths = new HashMap<>(); healths.put("h1", new Health.Builder().status(Status.DOWN).build()); healths.put("h2", new Health.Builder().status(Status.UP).build()); healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), Status.DOWN); }
@Test public void defaultOrderWithCustomStatus() { Map<String, Health> healths = new HashMap<>(); healths.put("h1", new Health.Builder().status(Status.DOWN).build()); healths.put("h2", new Health.Builder().status(Status.UP).build()); healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build()); Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), Status.DOWN); }
@Test(dataProvider = "statuses") public void defaultOrderWithDegradedStatus(final Status expectedStatus, final List<Status> actualStatuses) { Map<String, Health> healths = new HashMap<>(); healths.put("h1", new Health.Builder().status(actualStatuses.get(0)).build()); healths.put("h2", new Health.Builder().status(actualStatuses.get(1)).build()); healths.put("h3", new Health.Builder().status(actualStatuses.get(2)).build()); Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), expectedStatus); }
@Test(dataProvider = "singleStatuses") public void customOrderWithSingleStatus(final String key, final Health health, final Status expectedStatus) { Map<String, Health> healths = new HashMap<>(); healths.put(key, health); Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), expectedStatus); }
@Test public void noStatuses() throws Exception { Map<String, Health> healths = new HashMap<>(); Assert.assertEquals(this.healthAggregator.aggregate(healths).getStatus(), Status.UNKNOWN); }