org.apache.flink.core.testutils.CommonTestUtils Java Examples

The following examples show how to use org.apache.flink.core.testutils.CommonTestUtils. 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: StateDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitializeSerializerBeforeSerialization() throws Exception {
	final TestStateDescriptor<String> descr = new TestStateDescriptor<>("test", String.class);

	assertFalse(descr.isSerializerInitialized());
	try {
		descr.getSerializer();
		fail("should fail with an exception");
	} catch (IllegalStateException ignored) {}

	descr.initializeSerializerUnlessSet(new ExecutionConfig());

	assertTrue(descr.isSerializerInitialized());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof StringSerializer);

	TestStateDescriptor<String> clone = CommonTestUtils.createCopySerializable(descr);

	assertTrue(clone.isSerializerInitialized());
	assertNotNull(clone.getSerializer());
	assertTrue(clone.getSerializer() instanceof StringSerializer);
}
 
Example #2
Source File: ListStateDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testListStateDescriptor() throws Exception {

	TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig());

	ListStateDescriptor<String> descr =
			new ListStateDescriptor<>("testName", serializer);

	assertEquals("testName", descr.getName());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof ListSerializer);
	assertNotNull(descr.getElementSerializer());
	assertEquals(serializer, descr.getElementSerializer());

	ListStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr);

	assertEquals("testName", copy.getName());
	assertNotNull(copy.getSerializer());
	assertTrue(copy.getSerializer() instanceof ListSerializer);

	assertNotNull(copy.getElementSerializer());
	assertEquals(serializer, copy.getElementSerializer());
}
 
Example #3
Source File: StateDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitializeWithSerializer() throws Exception {
	final TypeSerializer<String> serializer = StringSerializer.INSTANCE;
	final TestStateDescriptor<String> descr = new TestStateDescriptor<>("test", serializer);

	assertTrue(descr.isSerializerInitialized());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof StringSerializer);

	// this should not have any effect
	descr.initializeSerializerUnlessSet(new ExecutionConfig());
	assertTrue(descr.isSerializerInitialized());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof StringSerializer);

	TestStateDescriptor<String> clone = CommonTestUtils.createCopySerializable(descr);
	assertTrue(clone.isSerializerInitialized());
	assertNotNull(clone.getSerializer());
	assertTrue(clone.getSerializer() instanceof StringSerializer);
}
 
Example #4
Source File: StringifiedAccumulatorResultTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialization() throws IOException {
	final String name = "a";
	final String type = "b";
	final String value = "c";
	final StringifiedAccumulatorResult original = new StringifiedAccumulatorResult(name, type, value);

	// Confirm no funny business in the constructor to getter pathway
	assertEquals(name, original.getName());
	assertEquals(type, original.getType());
	assertEquals(value, original.getValue());

	final StringifiedAccumulatorResult copy = CommonTestUtils.createCopySerializable(original);

	// Copy should have equivalent core fields
	assertEquals(name, copy.getName());
	assertEquals(type, copy.getType());
	assertEquals(value, copy.getValue());
}
 
Example #5
Source File: FlinkDistributionOverlayTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuilderFromEnvironment() throws Exception {
	Configuration conf = new Configuration();

	File binFolder = tempFolder.newFolder("bin");
	File libFolder = tempFolder.newFolder("lib");
	File pluginsFolder = tempFolder.newFolder("plugins");
	File confFolder = tempFolder.newFolder("conf");

	// adjust the test environment for the purposes of this test
	Map<String, String> map = new HashMap<String, String>(System.getenv());
	map.put(ENV_FLINK_BIN_DIR, binFolder.getAbsolutePath());
	map.put(ENV_FLINK_LIB_DIR, libFolder.getAbsolutePath());
	map.put(ENV_FLINK_PLUGINS_DIR, pluginsFolder.getAbsolutePath());
	map.put(ENV_FLINK_CONF_DIR, confFolder.getAbsolutePath());
	CommonTestUtils.setEnv(map);

	FlinkDistributionOverlay.Builder builder = FlinkDistributionOverlay.newBuilder().fromEnvironment(conf);

	assertEquals(binFolder.getAbsolutePath(), builder.flinkBinPath.getAbsolutePath());
	assertEquals(libFolder.getAbsolutePath(), builder.flinkLibPath.getAbsolutePath());
	final File flinkPluginsPath = builder.flinkPluginsPath;
	assertNotNull(flinkPluginsPath);
	assertEquals(pluginsFolder.getAbsolutePath(), flinkPluginsPath.getAbsolutePath());
	assertEquals(confFolder.getAbsolutePath(), builder.flinkConfPath.getAbsolutePath());
}
 
Example #6
Source File: ListStateDescriptorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testListStateDescriptor() throws Exception {

	TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig());

	ListStateDescriptor<String> descr =
			new ListStateDescriptor<>("testName", serializer);

	assertEquals("testName", descr.getName());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof ListSerializer);
	assertNotNull(descr.getElementSerializer());
	assertEquals(serializer, descr.getElementSerializer());

	ListStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr);

	assertEquals("testName", copy.getName());
	assertNotNull(copy.getSerializer());
	assertTrue(copy.getSerializer() instanceof ListSerializer);

	assertNotNull(copy.getElementSerializer());
	assertEquals(serializer, copy.getElementSerializer());
}
 
Example #7
Source File: SerializedValueTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullValue() {
	try {
		SerializedValue<Object> v = new SerializedValue<>(null);
		SerializedValue<Object> copy = CommonTestUtils.createCopySerializable(v);

		assertNull(copy.deserializeValue(getClass().getClassLoader()));

		assertEquals(v, copy);
		assertEquals(v.hashCode(), copy.hashCode());
		assertEquals(v.toString(), copy.toString());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #8
Source File: ReducingStateDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReducingStateDescriptor() throws Exception {

	ReduceFunction<String> reducer = (a, b) -> a;

	TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig());

	ReducingStateDescriptor<String> descr =
			new ReducingStateDescriptor<>("testName", reducer, serializer);

	assertEquals("testName", descr.getName());
	assertNotNull(descr.getSerializer());
	assertEquals(serializer, descr.getSerializer());
	assertEquals(reducer, descr.getReduceFunction());

	ReducingStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr);

	assertEquals("testName", copy.getName());
	assertNotNull(copy.getSerializer());
	assertEquals(serializer, copy.getSerializer());
}
 
Example #9
Source File: StateDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitializeWithSerializer() throws Exception {
	final TypeSerializer<String> serializer = StringSerializer.INSTANCE;
	final TestStateDescriptor<String> descr = new TestStateDescriptor<>("test", serializer);

	assertTrue(descr.isSerializerInitialized());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof StringSerializer);

	// this should not have any effect
	descr.initializeSerializerUnlessSet(new ExecutionConfig());
	assertTrue(descr.isSerializerInitialized());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof StringSerializer);

	TestStateDescriptor<String> clone = CommonTestUtils.createCopySerializable(descr);
	assertTrue(clone.isSerializerInitialized());
	assertNotNull(clone.getSerializer());
	assertTrue(clone.getSerializer() instanceof StringSerializer);
}
 
Example #10
Source File: StateDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitializeSerializerAfterSerializationWithCustomConfig() throws Exception {
	// guard our test assumptions.
	assertEquals("broken test assumption", -1,
			new KryoSerializer<>(String.class, new ExecutionConfig()).getKryo()
					.getRegistration(File.class).getId());

	final ExecutionConfig config = new ExecutionConfig();
	config.registerKryoType(File.class);

	final TestStateDescriptor<Path> original = new TestStateDescriptor<>("test", Path.class);
	TestStateDescriptor<Path> clone = CommonTestUtils.createCopySerializable(original);

	clone.initializeSerializerUnlessSet(config);

	// serialized one (later initialized) carries the registration
	assertTrue(((KryoSerializer<?>) clone.getSerializer()).getKryo()
			.getRegistration(File.class).getId() > 0);
}
 
Example #11
Source File: StateDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testHashCodeAndEquals() throws Exception {
	final String name = "testName";

	TestStateDescriptor<String> original = new TestStateDescriptor<>(name, String.class);
	TestStateDescriptor<String> same = new TestStateDescriptor<>(name, String.class);
	TestStateDescriptor<String> sameBySerializer = new TestStateDescriptor<>(name, StringSerializer.INSTANCE);

	// test that hashCode() works on state descriptors with initialized and uninitialized serializers
	assertEquals(original.hashCode(), same.hashCode());
	assertEquals(original.hashCode(), sameBySerializer.hashCode());

	assertEquals(original, same);
	assertEquals(original, sameBySerializer);

	// equality with a clone
	TestStateDescriptor<String> clone = CommonTestUtils.createCopySerializable(original);
	assertEquals(original, clone);

	// equality with an initialized
	clone.initializeSerializerUnlessSet(new ExecutionConfig());
	assertEquals(original, clone);

	original.initializeSerializerUnlessSet(new ExecutionConfig());
	assertEquals(original, same);
}
 
Example #12
Source File: StringifiedAccumulatorResultTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialization() throws IOException {
	final String name = "a";
	final String type = "b";
	final String value = "c";
	final StringifiedAccumulatorResult original = new StringifiedAccumulatorResult(name, type, value);

	// Confirm no funny business in the constructor to getter pathway
	assertEquals(name, original.getName());
	assertEquals(type, original.getType());
	assertEquals(value, original.getValue());

	final StringifiedAccumulatorResult copy = CommonTestUtils.createCopySerializable(original);

	// Copy should have equivalent core fields
	assertEquals(name, copy.getName());
	assertEquals(type, copy.getType());
	assertEquals(value, copy.getValue());
}
 
Example #13
Source File: SerializedValueTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleValue() {
	try {
		final String value = "teststring";

		SerializedValue<String> v = new SerializedValue<>(value);
		SerializedValue<String> copy = CommonTestUtils.createCopySerializable(v);

		assertEquals(value, v.deserializeValue(getClass().getClassLoader()));
		assertEquals(value, copy.deserializeValue(getClass().getClassLoader()));

		assertEquals(v, copy);
		assertEquals(v.hashCode(), copy.hashCode());

		assertNotNull(v.toString());
		assertNotNull(copy.toString());

	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #14
Source File: PythonEnvUtilsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetPythonExecutable() throws IOException {
	Configuration config = new Configuration();

	PythonEnvUtils.PythonEnvironment env = preparePythonEnvironment(config, null, tmpDirPath);
	if (OperatingSystem.isWindows()) {
		Assert.assertEquals("python.exe", env.pythonExec);
	} else {
		Assert.assertEquals("python", env.pythonExec);
	}

	Map<String, String> systemEnv = new HashMap<>(System.getenv());
	systemEnv.put(PYFLINK_CLIENT_EXECUTABLE, "python3");
	CommonTestUtils.setEnv(systemEnv);
	try {
		env = preparePythonEnvironment(config, null, tmpDirPath);
		Assert.assertEquals("python3", env.pythonExec);
	} finally {
		systemEnv.remove(PYFLINK_CLIENT_EXECUTABLE);
		CommonTestUtils.setEnv(systemEnv);
	}

	config.set(PYTHON_CLIENT_EXECUTABLE, "/usr/bin/python");
	env = preparePythonEnvironment(config, null, tmpDirPath);
	Assert.assertEquals("/usr/bin/python", env.pythonExec);
}
 
Example #15
Source File: ListStateDescriptorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testListStateDescriptor() throws Exception {

	TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig());

	ListStateDescriptor<String> descr =
			new ListStateDescriptor<>("testName", serializer);

	assertEquals("testName", descr.getName());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof ListSerializer);
	assertNotNull(descr.getElementSerializer());
	assertEquals(serializer, descr.getElementSerializer());

	ListStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr);

	assertEquals("testName", copy.getName());
	assertNotNull(copy.getSerializer());
	assertTrue(copy.getSerializer() instanceof ListSerializer);

	assertNotNull(copy.getElementSerializer());
	assertEquals(serializer, copy.getElementSerializer());
}
 
Example #16
Source File: AbstractIDTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the serialization/deserialization of an abstract ID.
 */
@Test
public void testSerialization() throws Exception {
	final AbstractID origID = new AbstractID();
	final AbstractID copyID = CommonTestUtils.createCopySerializable(origID);

	assertEquals(origID.hashCode(), copyID.hashCode());
	assertEquals(origID, copyID);
}
 
Example #17
Source File: CheckpointOptionsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSavepoint() throws Exception {
	final Random rnd = new Random();
	final byte[] locationBytes = new byte[rnd.nextInt(41) + 1];
	rnd.nextBytes(locationBytes);

	final CheckpointOptions options = new CheckpointOptions(
			CheckpointType.values()[rnd.nextInt(CheckpointType.values().length)],
			new CheckpointStorageLocationReference(locationBytes));

	final CheckpointOptions copy = CommonTestUtils.createCopySerializable(options);
	assertEquals(options.getCheckpointType(), copy.getCheckpointType());
	assertArrayEquals(locationBytes, copy.getTargetLocation().getReferenceBytes());
}
 
Example #18
Source File: ErrorInfoTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationWithExceptionOutsideClassLoader() throws Exception {
	final ErrorInfo error = new ErrorInfo(new ExceptionWithCustomClassLoader(), System.currentTimeMillis());
	final ErrorInfo copy = CommonTestUtils.createCopySerializable(error);

	assertEquals(error.getTimestamp(), copy.getTimestamp());
	assertEquals(error.getExceptionAsString(), copy.getExceptionAsString());
	assertEquals(error.getException().getMessage(), copy.getException().getMessage());

}
 
Example #19
Source File: JobCheckpointingSettingsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the settings are actually serializable.
 */
@Test
public void testIsJavaSerializable() throws Exception {
	JobCheckpointingSettings settings = new JobCheckpointingSettings(
		Arrays.asList(new JobVertexID(), new JobVertexID()),
		Arrays.asList(new JobVertexID(), new JobVertexID()),
		Arrays.asList(new JobVertexID(), new JobVertexID()),
		new CheckpointCoordinatorConfiguration(
			1231231,
			1231,
			112,
			12,
			CheckpointRetentionPolicy.RETAIN_ON_FAILURE,
			false,
			false,
			false,
			0),
		new SerializedValue<>(new MemoryStateBackend()));

	JobCheckpointingSettings copy = CommonTestUtils.createCopySerializable(settings);
	assertEquals(settings.getVerticesToAcknowledge(), copy.getVerticesToAcknowledge());
	assertEquals(settings.getVerticesToConfirm(), copy.getVerticesToConfirm());
	assertEquals(settings.getVerticesToTrigger(), copy.getVerticesToTrigger());
	assertEquals(settings.getCheckpointCoordinatorConfiguration(), copy.getCheckpointCoordinatorConfiguration());
	assertNotNull(copy.getDefaultStateBackend());
	assertTrue(copy.getDefaultStateBackend().deserializeValue(this.getClass().getClassLoader()).getClass() == MemoryStateBackend.class);
}
 
Example #20
Source File: ReducingStateDescriptorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testHashCodeEquals() throws Exception {
	final String name = "testName";
	final ReduceFunction<String> reducer = (a, b) -> a;

	ReducingStateDescriptor<String> original = new ReducingStateDescriptor<>(name, reducer, String.class);
	ReducingStateDescriptor<String> same = new ReducingStateDescriptor<>(name, reducer, String.class);
	ReducingStateDescriptor<String> sameBySerializer = new ReducingStateDescriptor<>(name, reducer, StringSerializer.INSTANCE);

	// test that hashCode() works on state descriptors with initialized and uninitialized serializers
	assertEquals(original.hashCode(), same.hashCode());
	assertEquals(original.hashCode(), sameBySerializer.hashCode());

	assertEquals(original, same);
	assertEquals(original, sameBySerializer);

	// equality with a clone
	ReducingStateDescriptor<String> clone = CommonTestUtils.createCopySerializable(original);
	assertEquals(original, clone);

	// equality with an initialized
	clone.initializeSerializerUnlessSet(new ExecutionConfig());
	assertEquals(original, clone);

	original.initializeSerializerUnlessSet(new ExecutionConfig());
	assertEquals(original, same);
}
 
Example #21
Source File: ResultPartitionDeploymentDescriptorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests simple de/serialization with {@link UnknownShuffleDescriptor}.
 */
@Test
public void testSerializationOfUnknownShuffleDescriptor() throws IOException {
	ShuffleDescriptor shuffleDescriptor = new UnknownShuffleDescriptor(resultPartitionID);
	ShuffleDescriptor shuffleDescriptorCopy = CommonTestUtils.createCopySerializable(shuffleDescriptor);
	assertThat(shuffleDescriptorCopy, instanceOf(UnknownShuffleDescriptor.class));
	assertThat(shuffleDescriptorCopy.getResultPartitionID(), is(resultPartitionID));
	assertThat(shuffleDescriptorCopy.isUnknown(), is(true));
}
 
Example #22
Source File: OperatorCoordinatorSchedulerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliveringClientRequestToNonRequestHandler() throws Exception {
	final OperatorCoordinator.Provider provider = new TestingOperatorCoordinator.Provider(testOperatorId);
	final DefaultScheduler scheduler = createScheduler(provider);

	final String payload = "testing payload";
	final TestingCoordinationRequestHandler.Request<String> request =
		new TestingCoordinationRequestHandler.Request<>(payload);

	CommonTestUtils.assertThrows(
		"cannot handle client event",
		FlinkException.class,
		() -> scheduler.deliverCoordinationRequestToCoordinator(testOperatorId, request));
}
 
Example #23
Source File: CheckpointOptionsTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSavepoint() throws Exception {
	final Random rnd = new Random();
	final byte[] locationBytes = new byte[rnd.nextInt(41) + 1];
	rnd.nextBytes(locationBytes);

	final CheckpointOptions options = new CheckpointOptions(
			CheckpointType.values()[rnd.nextInt(CheckpointType.values().length)],
			new CheckpointStorageLocationReference(locationBytes));

	final CheckpointOptions copy = CommonTestUtils.createCopySerializable(options);
	assertEquals(options.getCheckpointType(), copy.getCheckpointType());
	assertArrayEquals(locationBytes, copy.getTargetLocation().getReferenceBytes());
}
 
Example #24
Source File: MapStateDescriptorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapStateDescriptor() throws Exception {

	TypeSerializer<Integer> keySerializer = new KryoSerializer<>(Integer.class, new ExecutionConfig());
	TypeSerializer<String> valueSerializer = new KryoSerializer<>(String.class, new ExecutionConfig());

	MapStateDescriptor<Integer, String> descr =
			new MapStateDescriptor<>("testName", keySerializer, valueSerializer);

	assertEquals("testName", descr.getName());
	assertNotNull(descr.getSerializer());
	assertTrue(descr.getSerializer() instanceof MapSerializer);
	assertNotNull(descr.getKeySerializer());
	assertEquals(keySerializer, descr.getKeySerializer());
	assertNotNull(descr.getValueSerializer());
	assertEquals(valueSerializer, descr.getValueSerializer());

	MapStateDescriptor<Integer, String> copy = CommonTestUtils.createCopySerializable(descr);

	assertEquals("testName", copy.getName());
	assertNotNull(copy.getSerializer());
	assertTrue(copy.getSerializer() instanceof MapSerializer);

	assertNotNull(copy.getKeySerializer());
	assertEquals(keySerializer, copy.getKeySerializer());
	assertNotNull(copy.getValueSerializer());
	assertEquals(valueSerializer, copy.getValueSerializer());
}
 
Example #25
Source File: SourceFunctionTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void fromElementsTest() throws Exception {
	List<Integer> expectedList = Arrays.asList(1, 2, 3);
	List<Integer> actualList = SourceFunctionUtil.runSourceFunction(CommonTestUtils.createCopySerializable(
			new FromElementsFunction<Integer>(
					IntSerializer.INSTANCE,
					1,
					2,
					3)));
	assertEquals(expectedList, actualList);
}
 
Example #26
Source File: SubtaskStateStatsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the snapshot is actually serializable.
 */
@Test
public void testIsJavaSerializable() throws Exception {
	SubtaskStateStats stats = new SubtaskStateStats(
		0,
		Integer.MAX_VALUE + 1L,
		Integer.MAX_VALUE + 2L,
		Integer.MAX_VALUE + 3L,
		Integer.MAX_VALUE + 4L,
		Integer.MAX_VALUE + 6L,
		Integer.MAX_VALUE + 7L);


	SubtaskStateStats copy = CommonTestUtils.createCopySerializable(stats);

	assertEquals(0, copy.getSubtaskIndex());
	assertEquals(Integer.MAX_VALUE + 1L, copy.getAckTimestamp());
	assertEquals(Integer.MAX_VALUE + 2L, copy.getStateSize());
	assertEquals(Integer.MAX_VALUE + 3L, copy.getSyncCheckpointDuration());
	assertEquals(Integer.MAX_VALUE + 4L, copy.getAsyncCheckpointDuration());
	assertEquals(Integer.MAX_VALUE + 6L, copy.getAlignmentDuration());
	assertEquals(Integer.MAX_VALUE + 7L, stats.getCheckpointStartDelay());

	// Check duration helper
	long ackTimestamp = copy.getAckTimestamp();
	long triggerTimestamp = ackTimestamp - 10123;
	assertEquals(10123, copy.getEndToEndDuration(triggerTimestamp));

	// Trigger timestamp < ack timestamp
	assertEquals(0, copy.getEndToEndDuration(ackTimestamp + 1));

}
 
Example #27
Source File: TaskExecutionStateTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization() {
	try {
		final JobID jid = new JobID();
		final ExecutionAttemptID executionId = new ExecutionAttemptID();
		final ExecutionState state = ExecutionState.DEPLOYING;
		final Throwable error = new IOException("fubar");
		
		TaskExecutionState original1 = new TaskExecutionState(jid, executionId, state, error);
		TaskExecutionState original2 = new TaskExecutionState(jid, executionId, state);
		
		TaskExecutionState javaSerCopy1 = CommonTestUtils.createCopySerializable(original1);
		TaskExecutionState javaSerCopy2 = CommonTestUtils.createCopySerializable(original2);

		// equalities
		assertEquals(original1, javaSerCopy1);
		assertEquals(javaSerCopy1, original1);

		assertEquals(original2, javaSerCopy2);
		assertEquals(javaSerCopy2, original2);

		// hash codes
		assertEquals(original1.hashCode(), javaSerCopy1.hashCode());
		assertEquals(original2.hashCode(), javaSerCopy2.hashCode());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #28
Source File: TaskDeploymentDescriptorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization() throws Exception {
	final TaskDeploymentDescriptor orig = createTaskDeploymentDescriptor(
		new TaskDeploymentDescriptor.NonOffloaded<>(serializedJobInformation),
		new TaskDeploymentDescriptor.NonOffloaded<>(serializedJobVertexInformation));

	final TaskDeploymentDescriptor copy = CommonTestUtils.createCopySerializable(orig);

	assertFalse(orig.getSerializedJobInformation() == copy.getSerializedJobInformation());
	assertFalse(orig.getSerializedTaskInformation() == copy.getSerializedTaskInformation());
	assertFalse(orig.getExecutionAttemptId() == copy.getExecutionAttemptId());
	assertFalse(orig.getTaskRestore() == copy.getTaskRestore());
	assertFalse(orig.getProducedPartitions() == copy.getProducedPartitions());
	assertFalse(orig.getInputGates() == copy.getInputGates());

	assertEquals(orig.getSerializedJobInformation(), copy.getSerializedJobInformation());
	assertEquals(orig.getSerializedTaskInformation(), copy.getSerializedTaskInformation());
	assertEquals(orig.getExecutionAttemptId(), copy.getExecutionAttemptId());
	assertEquals(orig.getAllocationId(), copy.getAllocationId());
	assertEquals(orig.getSubtaskIndex(), copy.getSubtaskIndex());
	assertEquals(orig.getAttemptNumber(), copy.getAttemptNumber());
	assertEquals(orig.getTargetSlotNumber(), copy.getTargetSlotNumber());
	assertEquals(orig.getTaskRestore().getRestoreCheckpointId(), copy.getTaskRestore().getRestoreCheckpointId());
	assertEquals(orig.getTaskRestore().getTaskStateSnapshot(), copy.getTaskRestore().getTaskStateSnapshot());
	assertEquals(orig.getProducedPartitions(), copy.getProducedPartitions());
	assertEquals(orig.getInputGates(), copy.getInputGates());
}
 
Example #29
Source File: CompletedCheckpointTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsJavaSerializable() throws Exception {
	TaskStateStats task1 = new TaskStateStats(new JobVertexID(), 3);
	TaskStateStats task2 = new TaskStateStats(new JobVertexID(), 4);

	HashMap<JobVertexID, TaskStateStats> taskStats = new HashMap<>();
	taskStats.put(task1.getJobVertexId(), task1);
	taskStats.put(task2.getJobVertexId(), task2);

	CompletedCheckpointStats completed = new CompletedCheckpointStats(
		123123123L,
		10123L,
		CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION),
		1337,
		taskStats,
		1337,
		123129837912L,
		123819239812L,
		new SubtaskStateStats(123, 213123, 123123, 0, 0, 0, 0),
		null);

	CompletedCheckpointStats copy = CommonTestUtils.createCopySerializable(completed);

	assertEquals(completed.getCheckpointId(), copy.getCheckpointId());
	assertEquals(completed.getTriggerTimestamp(), copy.getTriggerTimestamp());
	assertEquals(completed.getProperties(), copy.getProperties());
	assertEquals(completed.getNumberOfSubtasks(), copy.getNumberOfSubtasks());
	assertEquals(completed.getNumberOfAcknowledgedSubtasks(), copy.getNumberOfAcknowledgedSubtasks());
	assertEquals(completed.getEndToEndDuration(), copy.getEndToEndDuration());
	assertEquals(completed.getStateSize(), copy.getStateSize());
	assertEquals(completed.getLatestAcknowledgedSubtaskStats().getSubtaskIndex(), copy.getLatestAcknowledgedSubtaskStats().getSubtaskIndex());
	assertEquals(completed.getStatus(), copy.getStatus());
}
 
Example #30
Source File: PojoSerializerUpgradeTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Changing field types of a POJO as keyed state should require a state migration.
 */
@Test
public void testChangedFieldTypesWithKeyedState() throws Exception {
	try {
		testPojoSerializerUpgrade(SOURCE_A, SOURCE_C, true, true);
		fail("Expected a state migration exception.");
	} catch (Exception e) {
		if (CommonTestUtils.containsCause(e, StateMigrationException.class)) {
			// StateMigrationException expected
		} else {
			throw e;
		}
	}
}