@Test public void testDeadAgentReaper() throws Exception { final MasterModel masterModel = mock(MasterModel.class); final Clock clock = mock(Clock.class); when(clock.now()).thenReturn(new Instant(HOURS.toMillis(2000))); final List<Datapoint> datapoints = Lists.newArrayList( new Datapoint("host1", 0, TIMEOUT_HOURS - 1, HostStatus.Status.DOWN, true), new Datapoint("host2", 0, TIMEOUT_HOURS + 1, HostStatus.Status.DOWN, false), new Datapoint("host3", 1000, 1000, HostStatus.Status.UP, false), new Datapoint("host4", 500, 300, HostStatus.Status.DOWN, true), new Datapoint("host5", 5000, 0, HostStatus.Status.DOWN, false), new Datapoint("host6", 0, 0, HostStatus.Status.UP, false) ); when(masterModel.listHosts()).thenReturn(Lists.newArrayList( datapoints.stream().map(input -> input.host).collect(Collectors.toList()))); for (final Datapoint datapoint : datapoints) { when(masterModel.isHostUp(datapoint.host)) .thenReturn(HostStatus.Status.UP == datapoint.status); when(masterModel.getAgentInfo(datapoint.host)).thenReturn(AgentInfo.newBuilder() .setStartTime(datapoint.startTime) .setUptime(datapoint.uptime) .build()); } final DeadAgentReaper reaper = new DeadAgentReaper(masterModel, TIMEOUT_HOURS, clock, 100, 0); reaper.startAsync().awaitRunning(); for (final Datapoint datapoint : datapoints) { if (datapoint.expectReap) { verify(masterModel, timeout(500)).deregisterHost(datapoint.host); } else { verify(masterModel, never()).deregisterHost(datapoint.host); } } }
public DeadAgentReaper(final MasterModel masterModel, final long timeoutHours) { this(masterModel, timeoutHours, SYSTEM_CLOCK, PERMITS_PER_SECOND, new Random().nextInt(DELAY)); }
DeadAgentReaper extends RateLimitedService<String> { public DeadAgentReaper(final MasterModel masterModel, final long timeoutHours) { this(masterModel, timeoutHours, SYSTEM_CLOCK, PERMITS_PER_SECOND, new Random().nextInt(DELAY)); } }
DeadAgentReaper extends RateLimitedService<String> { public DeadAgentReaper(final MasterModel masterModel, final long timeoutHours) { this(masterModel, timeoutHours, SYSTEM_CLOCK, PERMITS_PER_SECOND, new Random().nextInt(DELAY)); } DeadAgentReaper(final MasterModel masterModel,
                         final long timeoutHours); @VisibleForTesting  DeadAgentReaper(final MasterModel masterModel,
                  final long timeoutHours,
                  final Clock clock,
                  final double permitsPerSecond,
                  final int initialDelay); }
DeadAgentReaper extends RateLimitedService<String> { public DeadAgentReaper(final MasterModel masterModel, final long timeoutHours) { this(masterModel, timeoutHours, SYSTEM_CLOCK, PERMITS_PER_SECOND, new Random().nextInt(DELAY)); } DeadAgentReaper(final MasterModel masterModel,
                         final long timeoutHours); @VisibleForTesting  DeadAgentReaper(final MasterModel masterModel,
                  final long timeoutHours,
                  final Clock clock,
                  final double permitsPerSecond,
                  final int initialDelay);  }
DeadAgentReaper extends RateLimitedService<String> { public DeadAgentReaper(final MasterModel masterModel, final long timeoutHours) { this(masterModel, timeoutHours, SYSTEM_CLOCK, PERMITS_PER_SECOND, new Random().nextInt(DELAY)); } DeadAgentReaper(final MasterModel masterModel,
                         final long timeoutHours); @VisibleForTesting  DeadAgentReaper(final MasterModel masterModel,
                  final long timeoutHours,
                  final Clock clock,
                  final double permitsPerSecond,
                  final int initialDelay);   }