use of org.mockito.verification.VerificationMode in project mockito by mockito.
the class AtMostXVerificationTest method should_return_formatted_output_from_toString_method.
@Test
public void should_return_formatted_output_from_toString_method() {
VerificationMode atMost = atMost(3);
assertThat(atMost).hasToString("Wanted invocations count: at most 3");
}
use of org.mockito.verification.VerificationMode in project mockito by mockito.
the class OnlyVerificationTest method should_return_formatted_output_from_toString_method.
@Test
public void should_return_formatted_output_from_toString_method() {
VerificationMode only = only();
assertThat(only).hasToString("Wanted invocations count: 1 and no other method invoked");
}
use of org.mockito.verification.VerificationMode in project mockito by mockito.
the class MockingProgressImplTest method shouldStartVerificationAndPullVerificationMode.
@Test
public void shouldStartVerificationAndPullVerificationMode() throws Exception {
assertNull(mockingProgress.pullVerificationMode());
VerificationMode mode = VerificationModeFactory.times(19);
mockingProgress.verificationStarted(mode);
assertSame(mode, mockingProgress.pullVerificationMode());
assertNull(mockingProgress.pullVerificationMode());
}
use of org.mockito.verification.VerificationMode in project flink by apache.
the class CheckpointCoordinatorTest method testSharedStateRegistrationOnRestore.
@Test
public void testSharedStateRegistrationOnRestore() throws Exception {
JobVertexID jobVertexID1 = new JobVertexID();
int parallelism1 = 2;
int maxParallelism1 = 4;
ExecutionGraph graph = new CheckpointCoordinatorTestingUtils.CheckpointExecutionGraphBuilder().addJobVertex(jobVertexID1, parallelism1, maxParallelism1).build();
ExecutionJobVertex jobVertex1 = graph.getJobVertex(jobVertexID1);
List<CompletedCheckpoint> checkpoints = Collections.emptyList();
SharedStateRegistry firstInstance = SharedStateRegistry.DEFAULT_FACTORY.create(org.apache.flink.util.concurrent.Executors.directExecutor(), checkpoints);
final EmbeddedCompletedCheckpointStore store = new EmbeddedCompletedCheckpointStore(10, checkpoints, firstInstance);
// set up the coordinator and validate the initial state
final CheckpointCoordinatorBuilder coordinatorBuilder = new CheckpointCoordinatorBuilder().setExecutionGraph(graph).setTimer(manuallyTriggeredScheduledExecutor);
final CheckpointCoordinator coordinator = coordinatorBuilder.setCompletedCheckpointStore(store).build();
final int numCheckpoints = 3;
List<KeyGroupRange> keyGroupPartitions1 = StateAssignmentOperation.createKeyGroupPartitions(maxParallelism1, parallelism1);
for (int i = 0; i < numCheckpoints; ++i) {
performIncrementalCheckpoint(graph.getJobID(), coordinator, jobVertex1, keyGroupPartitions1, i);
}
List<CompletedCheckpoint> completedCheckpoints = coordinator.getSuccessfulCheckpoints();
assertEquals(numCheckpoints, completedCheckpoints.size());
int sharedHandleCount = 0;
List<Map<StateHandleID, StreamStateHandle>> sharedHandlesByCheckpoint = new ArrayList<>(numCheckpoints);
for (int i = 0; i < numCheckpoints; ++i) {
sharedHandlesByCheckpoint.add(new HashMap<>(2));
}
int cp = 0;
for (CompletedCheckpoint completedCheckpoint : completedCheckpoints) {
for (OperatorState taskState : completedCheckpoint.getOperatorStates().values()) {
for (OperatorSubtaskState subtaskState : taskState.getStates()) {
for (KeyedStateHandle keyedStateHandle : subtaskState.getManagedKeyedState()) {
// test we are once registered with the current registry
verify(keyedStateHandle, times(1)).registerSharedStates(firstInstance, completedCheckpoint.getCheckpointID());
IncrementalRemoteKeyedStateHandle incrementalKeyedStateHandle = (IncrementalRemoteKeyedStateHandle) keyedStateHandle;
sharedHandlesByCheckpoint.get(cp).putAll(incrementalKeyedStateHandle.getSharedState());
for (StreamStateHandle streamStateHandle : incrementalKeyedStateHandle.getSharedState().values()) {
assertTrue(!(streamStateHandle instanceof PlaceholderStreamStateHandle));
verify(streamStateHandle, never()).discardState();
++sharedHandleCount;
}
for (StreamStateHandle streamStateHandle : incrementalKeyedStateHandle.getPrivateState().values()) {
verify(streamStateHandle, never()).discardState();
}
verify(incrementalKeyedStateHandle.getMetaStateHandle(), never()).discardState();
}
verify(subtaskState, never()).discardState();
}
}
++cp;
}
// 2 (parallelism) x (1 (CP0) + 2 (CP1) + 2 (CP2)) = 10
assertEquals(10, sharedHandleCount);
// discard CP0
store.removeOldestCheckpoint();
// CP1
for (Map<StateHandleID, StreamStateHandle> cpList : sharedHandlesByCheckpoint) {
for (StreamStateHandle streamStateHandle : cpList.values()) {
verify(streamStateHandle, never()).discardState();
}
}
// shutdown the store
store.shutdown(JobStatus.SUSPENDED, new CheckpointsCleaner());
// restore the store
Set<ExecutionJobVertex> tasks = new HashSet<>();
tasks.add(jobVertex1);
assertEquals(JobStatus.SUSPENDED, store.getShutdownStatus().orElse(null));
SharedStateRegistry secondInstance = SharedStateRegistry.DEFAULT_FACTORY.create(org.apache.flink.util.concurrent.Executors.directExecutor(), store.getAllCheckpoints());
final EmbeddedCompletedCheckpointStore secondStore = new EmbeddedCompletedCheckpointStore(10, store.getAllCheckpoints(), secondInstance);
final CheckpointCoordinator secondCoordinator = coordinatorBuilder.setCompletedCheckpointStore(secondStore).build();
assertTrue(secondCoordinator.restoreLatestCheckpointedStateToAll(tasks, false));
// validate that all shared states are registered again after the recovery.
cp = 0;
for (CompletedCheckpoint completedCheckpoint : completedCheckpoints) {
for (OperatorState taskState : completedCheckpoint.getOperatorStates().values()) {
for (OperatorSubtaskState subtaskState : taskState.getStates()) {
for (KeyedStateHandle keyedStateHandle : subtaskState.getManagedKeyedState()) {
VerificationMode verificationMode;
// test we are once registered with the new registry
if (cp > 0) {
verificationMode = times(1);
} else {
verificationMode = never();
}
// check that all are registered with the new registry
verify(keyedStateHandle, verificationMode).registerSharedStates(secondInstance, completedCheckpoint.getCheckpointID());
}
}
}
++cp;
}
// discard CP1
secondStore.removeOldestCheckpoint();
// we expect that all shared state from CP0 is no longer referenced and discarded. CP2 is
// still live and also
// references the state from CP1, so we expect they are not discarded.
verifyDiscard(sharedHandlesByCheckpoint, cpId -> cpId == 0 ? times(1) : never());
// discard CP2
secondStore.removeOldestCheckpoint();
// still expect shared state not to be discarded because it may be used in later checkpoints
verifyDiscard(sharedHandlesByCheckpoint, cpId -> cpId == 1 ? never() : atLeast(0));
}
use of org.mockito.verification.VerificationMode in project flink by apache.
the class CheckpointCoordinatorTest method verifyDiscard.
private static void verifyDiscard(List<Map<StateHandleID, StreamStateHandle>> sharedHandlesByCheckpoint1, Function<Integer, VerificationMode> checkpointVerify) throws Exception {
for (Map<StateHandleID, StreamStateHandle> cpList : sharedHandlesByCheckpoint1) {
for (Map.Entry<StateHandleID, StreamStateHandle> entry : cpList.entrySet()) {
String key = entry.getKey().getKeyString();
int checkpointID = Integer.parseInt(String.valueOf(key.charAt(key.length() - 1)));
VerificationMode verificationMode = checkpointVerify.apply(checkpointID);
verify(entry.getValue(), verificationMode).discardState();
}
}
}
Aggregations