Java Code Examples for org.apache.flink.runtime.checkpoint.StateHandleDummyUtil#createNewKeyedStateHandle()

The following examples show how to use org.apache.flink.runtime.checkpoint.StateHandleDummyUtil#createNewKeyedStateHandle() . 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 File: OperatorSnapshotFinalizerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Test that the runnable futures are executed and the result is correctly extracted.
 */
@Test
public void testRunAndExtract() throws Exception{

	Random random = new Random(0x42);

	KeyedStateHandle keyedTemplate =
		StateHandleDummyUtil.createNewKeyedStateHandle(new KeyGroupRange(0, 0));
	OperatorStateHandle operatorTemplate =
		StateHandleDummyUtil.createNewOperatorStateHandle(2, random);

	SnapshotResult<KeyedStateHandle> snapKeyMan = SnapshotResult.withLocalState(
		StateHandleDummyUtil.deepDummyCopy(keyedTemplate),
		StateHandleDummyUtil.deepDummyCopy(keyedTemplate));

	SnapshotResult<KeyedStateHandle> snapKeyRaw = SnapshotResult.withLocalState(
		StateHandleDummyUtil.deepDummyCopy(keyedTemplate),
		StateHandleDummyUtil.deepDummyCopy(keyedTemplate));

	SnapshotResult<OperatorStateHandle> snapOpMan = SnapshotResult.withLocalState(
		StateHandleDummyUtil.deepDummyCopy(operatorTemplate),
		StateHandleDummyUtil.deepDummyCopy(operatorTemplate));

	SnapshotResult<OperatorStateHandle> snapOpRaw = SnapshotResult.withLocalState(
		StateHandleDummyUtil.deepDummyCopy(operatorTemplate),
		StateHandleDummyUtil.deepDummyCopy(operatorTemplate));

	DoneFuture<SnapshotResult<KeyedStateHandle>> managedKeyed = new PseudoNotDoneFuture<>(snapKeyMan);
	DoneFuture<SnapshotResult<KeyedStateHandle>> rawKeyed = new PseudoNotDoneFuture<>(snapKeyRaw);
	DoneFuture<SnapshotResult<OperatorStateHandle>> managedOp = new PseudoNotDoneFuture<>(snapOpMan);
	DoneFuture<SnapshotResult<OperatorStateHandle>> rawOp = new PseudoNotDoneFuture<>(snapOpRaw);

	Assert.assertFalse(managedKeyed.isDone());
	Assert.assertFalse(rawKeyed.isDone());
	Assert.assertFalse(managedOp.isDone());
	Assert.assertFalse(rawOp.isDone());

	OperatorSnapshotFutures futures = new OperatorSnapshotFutures(managedKeyed, rawKeyed, managedOp, rawOp);
	OperatorSnapshotFinalizer operatorSnapshotFinalizer = new OperatorSnapshotFinalizer(futures);

	Assert.assertTrue(managedKeyed.isDone());
	Assert.assertTrue(rawKeyed.isDone());
	Assert.assertTrue(managedOp.isDone());
	Assert.assertTrue(rawOp.isDone());

	OperatorSubtaskState jobManagerOwnedState = operatorSnapshotFinalizer.getJobManagerOwnedState();
	Assert.assertTrue(checkResult(snapKeyMan.getJobManagerOwnedSnapshot(), jobManagerOwnedState.getManagedKeyedState()));
	Assert.assertTrue(checkResult(snapKeyRaw.getJobManagerOwnedSnapshot(), jobManagerOwnedState.getRawKeyedState()));
	Assert.assertTrue(checkResult(snapOpMan.getJobManagerOwnedSnapshot(), jobManagerOwnedState.getManagedOperatorState()));
	Assert.assertTrue(checkResult(snapOpRaw.getJobManagerOwnedSnapshot(), jobManagerOwnedState.getRawOperatorState()));

	OperatorSubtaskState taskLocalState = operatorSnapshotFinalizer.getTaskLocalState();
	Assert.assertTrue(checkResult(snapKeyMan.getTaskLocalSnapshot(), taskLocalState.getManagedKeyedState()));
	Assert.assertTrue(checkResult(snapKeyRaw.getTaskLocalSnapshot(), taskLocalState.getRawKeyedState()));
	Assert.assertTrue(checkResult(snapOpMan.getTaskLocalSnapshot(), taskLocalState.getManagedOperatorState()));
	Assert.assertTrue(checkResult(snapOpRaw.getTaskLocalSnapshot(), taskLocalState.getRawOperatorState()));
}
 
Example 2
Source File: OperatorSnapshotFinalizerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Test that the runnable futures are executed and the result is correctly extracted.
 */
@Test
public void testRunAndExtract() throws Exception{

	Random random = new Random(0x42);

	KeyedStateHandle keyedTemplate =
		StateHandleDummyUtil.createNewKeyedStateHandle(new KeyGroupRange(0, 0));
	OperatorStateHandle operatorTemplate =
		StateHandleDummyUtil.createNewOperatorStateHandle(2, random);

	SnapshotResult<KeyedStateHandle> snapKeyMan = SnapshotResult.withLocalState(
		StateHandleDummyUtil.deepDummyCopy(keyedTemplate),
		StateHandleDummyUtil.deepDummyCopy(keyedTemplate));

	SnapshotResult<KeyedStateHandle> snapKeyRaw = SnapshotResult.withLocalState(
		StateHandleDummyUtil.deepDummyCopy(keyedTemplate),
		StateHandleDummyUtil.deepDummyCopy(keyedTemplate));

	SnapshotResult<OperatorStateHandle> snapOpMan = SnapshotResult.withLocalState(
		StateHandleDummyUtil.deepDummyCopy(operatorTemplate),
		StateHandleDummyUtil.deepDummyCopy(operatorTemplate));

	SnapshotResult<OperatorStateHandle> snapOpRaw = SnapshotResult.withLocalState(
		StateHandleDummyUtil.deepDummyCopy(operatorTemplate),
		StateHandleDummyUtil.deepDummyCopy(operatorTemplate));

	DoneFuture<SnapshotResult<KeyedStateHandle>> managedKeyed = new PseudoNotDoneFuture<>(snapKeyMan);
	DoneFuture<SnapshotResult<KeyedStateHandle>> rawKeyed = new PseudoNotDoneFuture<>(snapKeyRaw);
	DoneFuture<SnapshotResult<OperatorStateHandle>> managedOp = new PseudoNotDoneFuture<>(snapOpMan);
	DoneFuture<SnapshotResult<OperatorStateHandle>> rawOp = new PseudoNotDoneFuture<>(snapOpRaw);

	Assert.assertFalse(managedKeyed.isDone());
	Assert.assertFalse(rawKeyed.isDone());
	Assert.assertFalse(managedOp.isDone());
	Assert.assertFalse(rawOp.isDone());

	OperatorSnapshotFutures futures = new OperatorSnapshotFutures(managedKeyed, rawKeyed, managedOp, rawOp);
	OperatorSnapshotFinalizer operatorSnapshotFinalizer = new OperatorSnapshotFinalizer(futures);

	Assert.assertTrue(managedKeyed.isDone());
	Assert.assertTrue(rawKeyed.isDone());
	Assert.assertTrue(managedOp.isDone());
	Assert.assertTrue(rawOp.isDone());

	OperatorSubtaskState jobManagerOwnedState = operatorSnapshotFinalizer.getJobManagerOwnedState();
	Assert.assertTrue(checkResult(snapKeyMan.getJobManagerOwnedSnapshot(), jobManagerOwnedState.getManagedKeyedState()));
	Assert.assertTrue(checkResult(snapKeyRaw.getJobManagerOwnedSnapshot(), jobManagerOwnedState.getRawKeyedState()));
	Assert.assertTrue(checkResult(snapOpMan.getJobManagerOwnedSnapshot(), jobManagerOwnedState.getManagedOperatorState()));
	Assert.assertTrue(checkResult(snapOpRaw.getJobManagerOwnedSnapshot(), jobManagerOwnedState.getRawOperatorState()));

	OperatorSubtaskState taskLocalState = operatorSnapshotFinalizer.getTaskLocalState();
	Assert.assertTrue(checkResult(snapKeyMan.getTaskLocalSnapshot(), taskLocalState.getManagedKeyedState()));
	Assert.assertTrue(checkResult(snapKeyRaw.getTaskLocalSnapshot(), taskLocalState.getRawKeyedState()));
	Assert.assertTrue(checkResult(snapOpMan.getTaskLocalSnapshot(), taskLocalState.getManagedOperatorState()));
	Assert.assertTrue(checkResult(snapOpRaw.getTaskLocalSnapshot(), taskLocalState.getRawOperatorState()));
}