Java Code Examples for org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle

The following examples show how to use org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Flink-CEPplus   Source File: CompletedCheckpointTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the garbage collection properties are respected when subsuming checkpoints.
 */
@Test
public void testCleanUpOnSubsume() throws Exception {
	OperatorState state = mock(OperatorState.class);
	Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
	operatorStates.put(new OperatorID(), state);

	EmptyStreamStateHandle metadata = new EmptyStreamStateHandle();
	TestCompletedCheckpointStorageLocation location =
			new TestCompletedCheckpointStorageLocation(metadata, "ptr");

	CheckpointProperties props = new CheckpointProperties(false, CheckpointType.CHECKPOINT, true, false, false, false, false);

	CompletedCheckpoint checkpoint = new CompletedCheckpoint(
			new JobID(), 0, 0, 1,
			operatorStates,
			Collections.emptyList(),
			props,
			location);

	SharedStateRegistry sharedStateRegistry = new SharedStateRegistry();
	checkpoint.registerSharedStatesAfterRestored(sharedStateRegistry);
	verify(state, times(1)).registerSharedStates(sharedStateRegistry);

	// Subsume
	checkpoint.discardOnSubsume();

	verify(state, times(1)).discardState();
	assertTrue(location.isDisposed());
	assertTrue(metadata.isDisposed());
}
 
Example 2
Source Project: flink   Source File: CompletedCheckpointTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the garbage collection properties are respected when subsuming checkpoints.
 */
@Test
public void testCleanUpOnSubsume() throws Exception {
	OperatorState state = mock(OperatorState.class);
	Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
	operatorStates.put(new OperatorID(), state);

	EmptyStreamStateHandle metadata = new EmptyStreamStateHandle();
	TestCompletedCheckpointStorageLocation location =
			new TestCompletedCheckpointStorageLocation(metadata, "ptr");

	CheckpointProperties props = new CheckpointProperties(false, CheckpointType.CHECKPOINT, true, false, false, false, false);

	CompletedCheckpoint checkpoint = new CompletedCheckpoint(
			new JobID(), 0, 0, 1,
			operatorStates,
			Collections.emptyList(),
			props,
			location);

	SharedStateRegistry sharedStateRegistry = new SharedStateRegistry();
	checkpoint.registerSharedStatesAfterRestored(sharedStateRegistry);
	verify(state, times(1)).registerSharedStates(sharedStateRegistry);

	// Subsume
	checkpoint.discardOnSubsume();

	verify(state, times(1)).discardState();
	assertTrue(location.isDisposed());
	assertTrue(metadata.isDisposed());
}
 
Example 3
@Test
public <T extends AbstractChannelStateHandle<?>> void testNoRescaling() {
	OperatorState state = new OperatorState(OPERATOR_ID, oldParallelism, oldParallelism);
	state.putState(0, new OperatorSubtaskState(
		empty(),
		empty(),
		empty(),
		empty(),
		singleton(new InputChannelStateHandle(new InputChannelInfo(0, 0), new EmptyStreamStateHandle(), getOffset())),
		singleton(new ResultSubpartitionStateHandle(new ResultSubpartitionInfo(0, 0), new EmptyStreamStateHandle(), getOffset()))));
	try {
		// noinspection unchecked
		StateAssignmentOperation.reDistributePartitionableStates(
			singletonList(state),
			newParallelism,
			singletonList(OperatorIDPair.generatedIDOnly(OPERATOR_ID)),
			(Function<OperatorSubtaskState, StateObjectCollection<T>>) this.extractState,
			channelStateNonRescalingRepartitioner("test"));
	} catch (IllegalArgumentException e) {
		if (!shouldFail()) {
			throw e;
		} else {
			return;
		}
	}
	if (shouldFail()) {
		fail("expected to fail for: oldParallelism=" + oldParallelism + ", newParallelism=" + newParallelism + ", offsetsSize=" + offsetsSize + ", extractState=" + extractState);
	}
}
 
Example 4
Source Project: flink   Source File: CompletedCheckpointTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the garbage collection properties are respected when subsuming checkpoints.
 */
@Test
public void testCleanUpOnSubsume() throws Exception {
	OperatorState state = mock(OperatorState.class);
	Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
	operatorStates.put(new OperatorID(), state);

	EmptyStreamStateHandle metadata = new EmptyStreamStateHandle();
	TestCompletedCheckpointStorageLocation location =
			new TestCompletedCheckpointStorageLocation(metadata, "ptr");

	CheckpointProperties props = new CheckpointProperties(false, CheckpointType.CHECKPOINT, true, false, false, false, false);

	CompletedCheckpoint checkpoint = new CompletedCheckpoint(
			new JobID(), 0, 0, 1,
			operatorStates,
			Collections.emptyList(),
			props,
			location);

	SharedStateRegistry sharedStateRegistry = new SharedStateRegistry();
	checkpoint.registerSharedStatesAfterRestored(sharedStateRegistry);
	verify(state, times(1)).registerSharedStates(sharedStateRegistry);

	// Subsume
	checkpoint.discardOnSubsume();

	verify(state, times(1)).discardState();
	assertTrue(location.isDisposed());
	assertTrue(metadata.isDisposed());
}
 
Example 5
Source Project: Flink-CEPplus   Source File: CompletedCheckpointTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the garbage collection properties are respected when shutting down.
 */
@Test
public void testCleanUpOnShutdown() throws Exception {
	JobStatus[] terminalStates = new JobStatus[] {
			JobStatus.FINISHED, JobStatus.CANCELED, JobStatus.FAILED, JobStatus.SUSPENDED
	};

	for (JobStatus status : terminalStates) {

		OperatorState state = mock(OperatorState.class);
		Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
		operatorStates.put(new OperatorID(), state);

		EmptyStreamStateHandle retainedHandle = new EmptyStreamStateHandle();
		TestCompletedCheckpointStorageLocation retainedLocation =
				new TestCompletedCheckpointStorageLocation(retainedHandle, "ptr");

		// Keep
		CheckpointProperties retainProps = new CheckpointProperties(false, CheckpointType.CHECKPOINT, false, false, false, false, false);
		CompletedCheckpoint checkpoint = new CompletedCheckpoint(
				new JobID(), 0, 0, 1,
				new HashMap<>(operatorStates),
				Collections.emptyList(),
				retainProps,
				retainedLocation);

		checkpoint.discardOnShutdown(status);

		verify(state, times(0)).discardState();
		assertFalse(retainedLocation.isDisposed());
		assertFalse(retainedHandle.isDisposed());

		// Discard
		EmptyStreamStateHandle discardHandle = new EmptyStreamStateHandle();
		TestCompletedCheckpointStorageLocation discardLocation =
				new TestCompletedCheckpointStorageLocation(discardHandle, "ptr");

		// Keep
		CheckpointProperties discardProps = new CheckpointProperties(false, CheckpointType.CHECKPOINT, true, true, true, true, true);

		checkpoint = new CompletedCheckpoint(
				new JobID(), 0, 0, 1,
				new HashMap<>(operatorStates),
				Collections.emptyList(),
				discardProps,
				discardLocation);

		checkpoint.discardOnShutdown(status);

		verify(state, times(1)).discardState();
		assertTrue(discardLocation.isDisposed());
		assertTrue(discardHandle.isDisposed());
	}
}
 
Example 6
Source Project: flink   Source File: CompletedCheckpointTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the garbage collection properties are respected when shutting down.
 */
@Test
public void testCleanUpOnShutdown() throws Exception {
	JobStatus[] terminalStates = new JobStatus[] {
			JobStatus.FINISHED, JobStatus.CANCELED, JobStatus.FAILED, JobStatus.SUSPENDED
	};

	for (JobStatus status : terminalStates) {

		OperatorState state = mock(OperatorState.class);
		Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
		operatorStates.put(new OperatorID(), state);

		EmptyStreamStateHandle retainedHandle = new EmptyStreamStateHandle();
		TestCompletedCheckpointStorageLocation retainedLocation =
				new TestCompletedCheckpointStorageLocation(retainedHandle, "ptr");

		// Keep
		CheckpointProperties retainProps = new CheckpointProperties(false, CheckpointType.CHECKPOINT, false, false, false, false, false);
		CompletedCheckpoint checkpoint = new CompletedCheckpoint(
				new JobID(), 0, 0, 1,
				new HashMap<>(operatorStates),
				Collections.emptyList(),
				retainProps,
				retainedLocation);

		checkpoint.discardOnShutdown(status);

		verify(state, times(0)).discardState();
		assertFalse(retainedLocation.isDisposed());
		assertFalse(retainedHandle.isDisposed());

		// Discard
		EmptyStreamStateHandle discardHandle = new EmptyStreamStateHandle();
		TestCompletedCheckpointStorageLocation discardLocation =
				new TestCompletedCheckpointStorageLocation(discardHandle, "ptr");

		// Keep
		CheckpointProperties discardProps = new CheckpointProperties(false, CheckpointType.CHECKPOINT, true, true, true, true, true);

		checkpoint = new CompletedCheckpoint(
				new JobID(), 0, 0, 1,
				new HashMap<>(operatorStates),
				Collections.emptyList(),
				discardProps,
				discardLocation);

		checkpoint.discardOnShutdown(status);

		verify(state, times(1)).discardState();
		assertTrue(discardLocation.isDisposed());
		assertTrue(discardHandle.isDisposed());
	}
}
 
Example 7
Source Project: flink   Source File: CompletedCheckpointTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the garbage collection properties are respected when shutting down.
 */
@Test
public void testCleanUpOnShutdown() throws Exception {
	JobStatus[] terminalStates = new JobStatus[] {
			JobStatus.FINISHED, JobStatus.CANCELED, JobStatus.FAILED, JobStatus.SUSPENDED
	};

	for (JobStatus status : terminalStates) {

		OperatorState state = mock(OperatorState.class);
		Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
		operatorStates.put(new OperatorID(), state);

		EmptyStreamStateHandle retainedHandle = new EmptyStreamStateHandle();
		TestCompletedCheckpointStorageLocation retainedLocation =
				new TestCompletedCheckpointStorageLocation(retainedHandle, "ptr");

		// Keep
		CheckpointProperties retainProps = new CheckpointProperties(false, CheckpointType.CHECKPOINT, false, false, false, false, false);
		CompletedCheckpoint checkpoint = new CompletedCheckpoint(
				new JobID(), 0, 0, 1,
				new HashMap<>(operatorStates),
				Collections.emptyList(),
				retainProps,
				retainedLocation);

		checkpoint.discardOnShutdown(status);

		verify(state, times(0)).discardState();
		assertFalse(retainedLocation.isDisposed());
		assertFalse(retainedHandle.isDisposed());

		// Discard
		EmptyStreamStateHandle discardHandle = new EmptyStreamStateHandle();
		TestCompletedCheckpointStorageLocation discardLocation =
				new TestCompletedCheckpointStorageLocation(discardHandle, "ptr");

		// Keep
		CheckpointProperties discardProps = new CheckpointProperties(false, CheckpointType.CHECKPOINT, true, true, true, true, true);

		checkpoint = new CompletedCheckpoint(
				new JobID(), 0, 0, 1,
				new HashMap<>(operatorStates),
				Collections.emptyList(),
				discardProps,
				discardLocation);

		checkpoint.discardOnShutdown(status);

		verify(state, times(1)).discardState();
		assertTrue(discardLocation.isDisposed());
		assertTrue(discardHandle.isDisposed());
	}
}