OperationHistoryManager { public <A extends ClusterManagementOperation<V>, V extends OperationResult> List<OperationState<A, V>> list( A opType) { expireHistory(); return operationStateStore.list() .stream() .filter(instance -> opType.getClass().isAssignableFrom(instance.getOperation().getClass())) .map(fi -> (OperationState<A, V>) fi) .collect(Collectors.toList()); } OperationHistoryManager(
      OperationStateStore operationStateStore, InternalCache cache);  OperationHistoryManager(Duration keepCompleted,
      OperationStateStore operationStateStore,
      InternalCache cache); @SuppressWarnings("unchecked") OperationState<A, V> get(
      String opId); String recordStart(ClusterManagementOperation<?> op, String locator); void recordEnd(String opId, OperationResult result, Throwable cause); List<OperationState<A, V>> list(
      A opType);  }
@Test public void listFiltersByType() { ClusterManagementOperation<OperationResult> opType1 = mock(ClusterManagementOperation.class); ClusterManagementOperation<OperationResult> opType2 = new CmOperation(); List<OperationState<?, ?>> sampleOps = new ArrayList<>(); for (int i = 0; i < 9; i++) { if (i % 2 == 0) { sampleOps.add(new OperationState<>("op-" + i, opType1, new Date())); } else { sampleOps.add(new OperationState<>("op-" + i, opType2, new Date())); } } doReturn(sampleOps).when(operationStateStore).list(); List<OperationState<ClusterManagementOperation<OperationResult>, OperationResult>> opList1 = history.list(opType1); List<OperationState<ClusterManagementOperation<OperationResult>, OperationResult>> opList2 = history.list(opType2); assertThat(opList1.size()).isEqualTo(5); assertThat(opList2.size()).isEqualTo(4); }
@Test public void listCallsDelegatesToPersistenceService() { ClusterManagementOperation<OperationResult> op = mock(ClusterManagementOperation.class); history.list(op); verify(operationStateStore, times(2)).list(); }