@Test public void testCleanupRequestedInstances() { Stack stack = new Stack(); stack.setId(STACK_ID); InstanceMetaData instanceMetaData1 = mock(InstanceMetaData.class); InstanceMetaData instanceMetaData2 = mock(InstanceMetaData.class); when(instanceMetaData1.getInstanceStatus()).thenReturn(InstanceStatus.REQUESTED); when(instanceMetaData2.getInstanceStatus()).thenReturn(InstanceStatus.CREATED); Set<InstanceMetaData> metadata = Set.of(instanceMetaData1, instanceMetaData2); when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME); when(instanceMetaDataService.findNotTerminatedForStack(any())).thenReturn(metadata); underTest.cleanupRequestedInstances(stack); verify(instanceMetaData1, times(1)).setTerminationDate(CURRENT_TIME); verify(instanceMetaData1, times(1)).setInstanceStatus(InstanceStatus.TERMINATED); verify(instanceMetaData2, never()).setTerminationDate(any()); verify(instanceMetaData2, never()).setInstanceStatus(InstanceStatus.TERMINATED); verify(instanceMetaDataService, times(1)).saveAll(any()); }
public void cleanupRequestedInstances(Stack stack) { Set<InstanceMetaData> requestedInstances = instanceMetaDataService.findNotTerminatedForStack(stack.getId()).stream() .filter(instanceMetaData -> instanceMetaData.getInstanceStatus() == InstanceStatus.REQUESTED) .collect(Collectors.toSet()); requestedInstances.forEach(instanceMetaData -> { instanceMetaData.setTerminationDate(clock.getCurrentTimeMillis()); instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED); }); instanceMetaDataService.saveAll(requestedInstances); }
MetadataSetupService { public void cleanupRequestedInstances(Stack stack) { Set<InstanceMetaData> requestedInstances = instanceMetaDataService.findNotTerminatedForStack(stack.getId()).stream() .filter(instanceMetaData -> instanceMetaData.getInstanceStatus() == InstanceStatus.REQUESTED) .collect(Collectors.toSet()); requestedInstances.forEach(instanceMetaData -> { instanceMetaData.setTerminationDate(clock.getCurrentTimeMillis()); instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED); }); instanceMetaDataService.saveAll(requestedInstances); } }
MetadataSetupService { public void cleanupRequestedInstances(Stack stack) { Set<InstanceMetaData> requestedInstances = instanceMetaDataService.findNotTerminatedForStack(stack.getId()).stream() .filter(instanceMetaData -> instanceMetaData.getInstanceStatus() == InstanceStatus.REQUESTED) .collect(Collectors.toSet()); requestedInstances.forEach(instanceMetaData -> { instanceMetaData.setTerminationDate(clock.getCurrentTimeMillis()); instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED); }); instanceMetaDataService.saveAll(requestedInstances); }  }
MetadataSetupService { public void cleanupRequestedInstances(Stack stack) { Set<InstanceMetaData> requestedInstances = instanceMetaDataService.findNotTerminatedForStack(stack.getId()).stream() .filter(instanceMetaData -> instanceMetaData.getInstanceStatus() == InstanceStatus.REQUESTED) .collect(Collectors.toSet()); requestedInstances.forEach(instanceMetaData -> { instanceMetaData.setTerminationDate(clock.getCurrentTimeMillis()); instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED); }); instanceMetaDataService.saveAll(requestedInstances); }  int saveInstanceMetaData(Stack stack, Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatusList, InstanceStatus status); void cleanupRequestedInstances(Stack stack); }
MetadataSetupService { public void cleanupRequestedInstances(Stack stack) { Set<InstanceMetaData> requestedInstances = instanceMetaDataService.findNotTerminatedForStack(stack.getId()).stream() .filter(instanceMetaData -> instanceMetaData.getInstanceStatus() == InstanceStatus.REQUESTED) .collect(Collectors.toSet()); requestedInstances.forEach(instanceMetaData -> { instanceMetaData.setTerminationDate(clock.getCurrentTimeMillis()); instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED); }); instanceMetaDataService.saveAll(requestedInstances); }  int saveInstanceMetaData(Stack stack, Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatusList, InstanceStatus status); void cleanupRequestedInstances(Stack stack);  }