@Test public void testPartiallyRepaired() { long now = System.currentTimeMillis(); long repairIntervalInMs = TimeUnit.HOURS.toMillis(1); long expectedAtLeastRepairedAt = now - repairIntervalInMs; RepairConfiguration repairConfiguration = repairConfiguration(repairIntervalInMs); Host host = mockHost("DC1"); when(mockHostStates.isUp(eq(host))).thenReturn(true); VnodeRepairState vnodeRepairState = new VnodeRepairState(new LongTokenRange(1, 2), ImmutableSet.of(host), VnodeRepairState.UNREPAIRED); VnodeRepairState repairedVnodeRepairState = new VnodeRepairState(new LongTokenRange(2, 3), ImmutableSet.of(host), now); VnodeRepairStates vnodeRepairStates = VnodeRepairStates.newBuilder(Arrays.asList(vnodeRepairState, repairedVnodeRepairState)) .build(); when(mockVnodeRepairStateFactory.calculateNewState(eq(tableReference), isNull(RepairStateSnapshot.class))).thenReturn(vnodeRepairStates); when(mockReplicaRepairGroupFactory.generateReplicaRepairGroups(repairGroupCaptor.capture())).thenReturn(Collections.singletonList(mockReplicaRepairGroup)); RepairState repairState = new RepairStateImpl(tableReference, repairConfiguration, mockVnodeRepairStateFactory, mockHostStates, mockTableRepairMetrics, mockReplicaRepairGroupFactory); RepairStateSnapshot repairStateSnapshot = repairState.getSnapshot(); List<VnodeRepairState> capturedVnodeStates = repairGroupCaptor.getValue(); assertThat(capturedVnodeStates).hasSize(1); VnodeRepairState capturedVnodeRepairState = capturedVnodeStates.get(0); assertVnodeRepairStateRepairedBefore(vnodeRepairState, capturedVnodeRepairState, System.currentTimeMillis() - repairIntervalInMs); assertRepairStateSnapshot(repairStateSnapshot, expectedAtLeastRepairedAt, Collections.singletonList(mockReplicaRepairGroup), vnodeRepairStates); verify(mockTableRepairMetrics).repairState(eq(tableReference), eq(1), eq(1)); verify(mockTableRepairMetrics).lastRepairedAt(eq(tableReference), eq(repairStateSnapshot.lastRepairedAt())); }
@Override public RepairStateSnapshot getSnapshot() { return myRepairStateSnapshot.get(); }
RepairStateImpl implements RepairState { @Override public RepairStateSnapshot getSnapshot() { return myRepairStateSnapshot.get(); } }
RepairStateImpl implements RepairState { @Override public RepairStateSnapshot getSnapshot() { return myRepairStateSnapshot.get(); } RepairStateImpl(TableReference tableReference, RepairConfiguration repairConfiguration,
                           VnodeRepairStateFactory vnodeRepairStateFactory, HostStates hostStates,
                           TableRepairMetrics tableRepairMetrics, ReplicaRepairGroupFactory replicaRepairGroupFactory); }
RepairStateImpl implements RepairState { @Override public RepairStateSnapshot getSnapshot() { return myRepairStateSnapshot.get(); } RepairStateImpl(TableReference tableReference, RepairConfiguration repairConfiguration,
                           VnodeRepairStateFactory vnodeRepairStateFactory, HostStates hostStates,
                           TableRepairMetrics tableRepairMetrics, ReplicaRepairGroupFactory replicaRepairGroupFactory); @Override final void update(); @Override RepairStateSnapshot getSnapshot(); }
RepairStateImpl implements RepairState { @Override public RepairStateSnapshot getSnapshot() { return myRepairStateSnapshot.get(); } RepairStateImpl(TableReference tableReference, RepairConfiguration repairConfiguration,
                           VnodeRepairStateFactory vnodeRepairStateFactory, HostStates hostStates,
                           TableRepairMetrics tableRepairMetrics, ReplicaRepairGroupFactory replicaRepairGroupFactory); @Override final void update(); @Override RepairStateSnapshot getSnapshot();  }