RolledUpMonitoredService implements MonitoredService { public ServiceStatus getServiceStatus() { List<String> reasons = new ArrayList<String>(); Status criticalStatus = Status.UP; for (MonitoredService m : criticals) { ServiceStatus serviceStatus = m.getServiceStatus(); Status status = serviceStatus.getStatus(); if (statusIsNotUp(status)) { for (String reason : serviceStatus.getReasons()) { reasons.add(serviceStatus.getName() + ":" + reason); } } if (status.getValue() < criticalStatus.getValue()) { criticalStatus = status; } } Status result = Status.UP; for (MonitoredService m : noncriticals) { ServiceStatus serviceStatus = m.getServiceStatus(); Status status = serviceStatus.getStatus(); if (statusIsNotUp(status)) { for (String reason : serviceStatus.getReasons()) { reasons.add(serviceStatus.getName() + ":" + reason); } result = Status.DEGRADED; } } if (criticalStatus.getValue() < result.getValue()) { result = criticalStatus; } return new ServiceStatus(name, result, reasons); } RolledUpMonitoredService(String name,
            Collection<? extends MonitoredService> criticals,
            Collection<? extends MonitoredService> noncriticals); ServiceStatus getServiceStatus(); List<ServiceStatus> getAllStatuses(); List<ServiceStatus> getCriticalStatuses(); List<ServiceStatus> getNonCriticalStatuses();  }
@Test public void testAllUp() { expect(mockService1.getServiceStatus()).andReturn(new ServiceStatus(SERVICE_1_NAME, Status.UP)); expect(mockService2.getServiceStatus()).andReturn(new ServiceStatus(SERVICE_2_NAME, Status.UP)); replay(mockService1); replay(mockService2); ServiceStatus serviceStatus = rolledUpService.getServiceStatus(); assertEquals(ROLLEDUP_SERVICE_NAME, serviceStatus.getName()); assertEquals(serviceStatus.getStatus(), Status.UP); }
@Test public void testCriticalDegraded() { expect(mockService1.getServiceStatus()).andReturn( new ServiceStatus(SERVICE_1_NAME, Status.DEGRADED, SERVICE_1_REASON)); expect(mockService2.getServiceStatus()).andReturn(new ServiceStatus(SERVICE_2_NAME, Status.UP)); replay(mockService1); replay(mockService2); ServiceStatus serviceStatus = rolledUpService.getServiceStatus(); assertEquals(ROLLEDUP_SERVICE_NAME, serviceStatus.getName()); assertEquals(serviceStatus.getStatus(), Status.DEGRADED); assertTrue(serviceStatus.getReasons().contains(SERVICE_1_NAME + ":" + SERVICE_1_REASON)); }
@Test public void testNonCriticalDegraded() { expect(mockService1.getServiceStatus()).andReturn(new ServiceStatus(SERVICE_1_NAME, Status.UP)); expect(mockService2.getServiceStatus()).andReturn( new ServiceStatus(SERVICE_2_NAME, Status.DEGRADED, SERVICE_2_REASON)); replay(mockService1); replay(mockService2); ServiceStatus serviceStatus = rolledUpService.getServiceStatus(); assertEquals(ROLLEDUP_SERVICE_NAME, serviceStatus.getName()); assertEquals(serviceStatus.getStatus(), Status.DEGRADED); assertTrue(serviceStatus.getReasons().contains(SERVICE_2_NAME + ":" + SERVICE_2_REASON)); }
@Test public void testCritialAndNonCriticalDegraded() { expect(mockService1.getServiceStatus()).andReturn( new ServiceStatus(SERVICE_1_NAME, Status.DEGRADED, SERVICE_1_REASON)); expect(mockService2.getServiceStatus()).andReturn( new ServiceStatus(SERVICE_2_NAME, Status.DEGRADED, SERVICE_2_REASON)); replay(mockService1); replay(mockService2); ServiceStatus serviceStatus = rolledUpService.getServiceStatus(); assertEquals(ROLLEDUP_SERVICE_NAME, serviceStatus.getName()); assertEquals(serviceStatus.getStatus(), Status.DEGRADED); assertTrue(serviceStatus.getReasons().contains(SERVICE_1_NAME + ":" + SERVICE_1_REASON)); assertTrue(serviceStatus.getReasons().contains(SERVICE_2_NAME + ":" + SERVICE_2_REASON)); }
@Test public void testNonCritialDown() { expect(mockService1.getServiceStatus()).andReturn(new ServiceStatus(SERVICE_1_NAME, Status.UP)); expect(mockService2.getServiceStatus()).andReturn( new ServiceStatus(SERVICE_2_NAME, Status.DOWN, SERVICE_2_REASON)); replay(mockService1); replay(mockService2); ServiceStatus serviceStatus = rolledUpService.getServiceStatus(); assertEquals(ROLLEDUP_SERVICE_NAME, serviceStatus.getName()); assertEquals(serviceStatus.getStatus(), Status.DEGRADED); assertTrue(serviceStatus.getReasons().contains(SERVICE_2_NAME + ":" + SERVICE_2_REASON)); }