@Test public void testResetCount() { CountingHealthMonitorStrategy sut = new CountingHealthMonitorStrategy(3); final boolean[] result = new boolean[1]; sut.registerListener(new HealthMonitorStrategyListener() { @Override public void onUpdate(boolean isHealthy) { result[0]= isHealthy; } }); sut.update(true); Assert.assertEquals(true, result[0]); sut.update(false); Assert.assertEquals(true,result[0]); sut.update(true); Assert.assertEquals(true,result[0]); sut.update(false); Assert.assertEquals(true,result[0]); sut.update(false); Assert.assertEquals(true,result[0]); sut.update(false); Assert.assertEquals(false,result[0]); }
@Override public synchronized void update(boolean isHealthy) { if (currentState == null) { adviseListeners(isHealthy); currentState = isHealthy; } else if (isHealthy != currentState) { if (++changesReceived >= requiredUpdateCount) { adviseListeners(isHealthy); currentState = isHealthy; changesReceived = 0; } } else { changesReceived = 0; } }
CountingHealthMonitorStrategy extends AbstractHealthMonitorStrategy { @Override public synchronized void update(boolean isHealthy) { if (currentState == null) { adviseListeners(isHealthy); currentState = isHealthy; } else if (isHealthy != currentState) { if (++changesReceived >= requiredUpdateCount) { adviseListeners(isHealthy); currentState = isHealthy; changesReceived = 0; } } else { changesReceived = 0; } } }
CountingHealthMonitorStrategy extends AbstractHealthMonitorStrategy { @Override public synchronized void update(boolean isHealthy) { if (currentState == null) { adviseListeners(isHealthy); currentState = isHealthy; } else if (isHealthy != currentState) { if (++changesReceived >= requiredUpdateCount) { adviseListeners(isHealthy); currentState = isHealthy; changesReceived = 0; } } else { changesReceived = 0; } } CountingHealthMonitorStrategy(int requiredUpdateCount); }
CountingHealthMonitorStrategy extends AbstractHealthMonitorStrategy { @Override public synchronized void update(boolean isHealthy) { if (currentState == null) { adviseListeners(isHealthy); currentState = isHealthy; } else if (isHealthy != currentState) { if (++changesReceived >= requiredUpdateCount) { adviseListeners(isHealthy); currentState = isHealthy; changesReceived = 0; } } else { changesReceived = 0; } } CountingHealthMonitorStrategy(int requiredUpdateCount); @Override synchronized void update(boolean isHealthy); }
CountingHealthMonitorStrategy extends AbstractHealthMonitorStrategy { @Override public synchronized void update(boolean isHealthy) { if (currentState == null) { adviseListeners(isHealthy); currentState = isHealthy; } else if (isHealthy != currentState) { if (++changesReceived >= requiredUpdateCount) { adviseListeners(isHealthy); currentState = isHealthy; changesReceived = 0; } } else { changesReceived = 0; } } CountingHealthMonitorStrategy(int requiredUpdateCount); @Override synchronized void update(boolean isHealthy);  }