Java Code Examples for org.apache.flink.core.testutils.CommonTestUtils#createCopySerializable()
The following examples show how to use
org.apache.flink.core.testutils.CommonTestUtils#createCopySerializable() .
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 |
@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 2
Source File: ListStateDescriptorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testHashCodeEquals() throws Exception { final String name = "testName"; ListStateDescriptor<String> original = new ListStateDescriptor<>(name, String.class); ListStateDescriptor<String> same = new ListStateDescriptor<>(name, String.class); ListStateDescriptor<String> sameBySerializer = new ListStateDescriptor<>(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 ListStateDescriptor<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 3
Source File: StateDescriptorTest.java From flink with Apache License 2.0 | 6 votes |
@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 4
Source File: SerializedValueTest.java From flink with Apache License 2.0 | 6 votes |
@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 5
Source File: StateDescriptorTest.java From flink with Apache License 2.0 | 6 votes |
@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 6
Source File: GenericMessageTester.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public static void testMessageInstance(Serializable instance) throws Exception { Serializable copy = CommonTestUtils.createCopySerializable(instance); // test equals, hash code, toString assertTrue(instance.equals(copy)); assertTrue(copy.equals(instance)); assertTrue(instance.hashCode() == copy.hashCode()); assertTrue(instance.toString().equals(copy.toString())); }
Example 7
Source File: SerializedJobExecutionResultTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSerializationWithNullValues() throws Exception { SerializedJobExecutionResult result = new SerializedJobExecutionResult(null, 0L, null); SerializedJobExecutionResult cloned = CommonTestUtils.createCopySerializable(result); assertNull(cloned.getJobId()); assertEquals(0L, cloned.getNetRuntime()); assertNull(cloned.getSerializedAccumulatorResults()); JobExecutionResult jResult = result.toJobExecutionResult(getClass().getClassLoader()); assertNull(jResult.getJobID()); assertTrue(jResult.getAllAccumulatorResults().isEmpty()); }
Example 8
Source File: CheckpointOptionsTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDefaultCheckpoint() throws Exception { final CheckpointOptions options = CheckpointOptions.forCheckpointWithDefaultLocation(); assertEquals(CheckpointType.CHECKPOINT, options.getCheckpointType()); assertTrue(options.getTargetLocation().isDefaultReference()); final CheckpointOptions copy = CommonTestUtils.createCopySerializable(options); assertEquals(CheckpointType.CHECKPOINT, copy.getCheckpointType()); assertTrue(copy.getTargetLocation().isDefaultReference()); }
Example 9
Source File: GenericMessageTester.java From flink with Apache License 2.0 | 5 votes |
public static void testMessageInstance(Serializable instance) throws Exception { Serializable copy = CommonTestUtils.createCopySerializable(instance); // test equals, hash code, toString assertTrue(instance.equals(copy)); assertTrue(copy.equals(instance)); assertTrue(instance.hashCode() == copy.hashCode()); assertTrue(instance.toString().equals(copy.toString())); }
Example 10
Source File: MemorySizeTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testStandardUtils() throws IOException { final MemorySize size = new MemorySize(1234567890L); final MemorySize cloned = CommonTestUtils.createCopySerializable(size); assertEquals(size, cloned); assertEquals(size.hashCode(), cloned.hashCode()); assertEquals(size.toString(), cloned.toString()); }
Example 11
Source File: ValueStateDescriptorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testVeryLargeDefaultValue() throws Exception { // ensure that we correctly read very large data when deserializing the default value TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig()); byte[] data = new byte[200000]; for (int i = 0; i < 200000; i++) { data[i] = 65; } data[199000] = '\0'; String defaultValue = new String(data, ConfigConstants.DEFAULT_CHARSET); ValueStateDescriptor<String> descr = new ValueStateDescriptor<>("testName", serializer, defaultValue); assertEquals("testName", descr.getName()); assertEquals(defaultValue, descr.getDefaultValue()); assertNotNull(descr.getSerializer()); assertEquals(serializer, descr.getSerializer()); ValueStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr); assertEquals("testName", copy.getName()); assertEquals(defaultValue, copy.getDefaultValue()); assertNotNull(copy.getSerializer()); assertEquals(serializer, copy.getSerializer()); }
Example 12
Source File: TaskExecutionStateTest.java From flink with Apache License 2.0 | 5 votes |
@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 13
Source File: ResultPartitionDeploymentDescriptorTest.java From flink with Apache License 2.0 | 5 votes |
private static ResultPartitionDeploymentDescriptor createCopyAndVerifyResultPartitionDeploymentDescriptor( ShuffleDescriptor shuffleDescriptor) throws IOException { ResultPartitionDeploymentDescriptor orig = new ResultPartitionDeploymentDescriptor( partitionDescriptor, shuffleDescriptor, numberOfSubpartitions, true); ResultPartitionDeploymentDescriptor copy = CommonTestUtils.createCopySerializable(orig); verifyResultPartitionDeploymentDescriptorCopy(copy); return copy; }
Example 14
Source File: CheckpointOptionsTest.java From flink with Apache License 2.0 | 5 votes |
@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 15
Source File: PendingCheckpointStatsTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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); PendingCheckpointStats pending = new PendingCheckpointStats( 123123123L, 10123L, CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION), 1337, taskStats, mock(CheckpointStatsTracker.PendingCheckpointStatsCallback.class)); PendingCheckpointStats copy = CommonTestUtils.createCopySerializable(pending); assertEquals(pending.getCheckpointId(), copy.getCheckpointId()); assertEquals(pending.getTriggerTimestamp(), copy.getTriggerTimestamp()); assertEquals(pending.getProperties(), copy.getProperties()); assertEquals(pending.getNumberOfSubtasks(), copy.getNumberOfSubtasks()); assertEquals(pending.getNumberOfAcknowledgedSubtasks(), copy.getNumberOfAcknowledgedSubtasks()); assertEquals(pending.getEndToEndDuration(), copy.getEndToEndDuration()); assertEquals(pending.getStateSize(), copy.getStateSize()); assertEquals(pending.getLatestAcknowledgedSubtaskStats(), copy.getLatestAcknowledgedSubtaskStats()); assertEquals(pending.getStatus(), copy.getStatus()); }
Example 16
Source File: MapStateDescriptorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testHashCodeEquals() throws Exception { final String name = "testName"; MapStateDescriptor<String, String> original = new MapStateDescriptor<>(name, String.class, String.class); MapStateDescriptor<String, String> same = new MapStateDescriptor<>(name, String.class, String.class); MapStateDescriptor<String, String> sameBySerializer = new MapStateDescriptor<>(name, StringSerializer.INSTANCE, 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 MapStateDescriptor<String, 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 17
Source File: CheckpointMessagesTest.java From flink with Apache License 2.0 | 5 votes |
private static void testSerializabilityEqualsHashCode(Serializable o) throws IOException { Object copy = CommonTestUtils.createCopySerializable(o); assertEquals(o, copy); assertEquals(o.hashCode(), copy.hashCode()); assertNotNull(o.toString()); assertNotNull(copy.toString()); }
Example 18
Source File: FailedCheckpointStatsTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testIsJavaSerializable() throws Exception { long duration = 123912931293L; long triggerTimestamp = 10123; long failureTimestamp = triggerTimestamp + duration; Map<JobVertexID, TaskStateStats> taskStats = new HashMap<>(); JobVertexID jobVertexId = new JobVertexID(); taskStats.put(jobVertexId, new TaskStateStats(jobVertexId, 1)); FailedCheckpointStats failed = new FailedCheckpointStats( 123123123L, triggerTimestamp, CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION), 1337, taskStats, 3, 190890123, failureTimestamp, null, new NotSerializableException("message")); FailedCheckpointStats copy = CommonTestUtils.createCopySerializable(failed); assertEquals(failed.getCheckpointId(), copy.getCheckpointId()); assertEquals(failed.getTriggerTimestamp(), copy.getTriggerTimestamp()); assertEquals(failed.getProperties(), copy.getProperties()); assertEquals(failed.getNumberOfSubtasks(), copy.getNumberOfSubtasks()); assertEquals(failed.getNumberOfAcknowledgedSubtasks(), copy.getNumberOfAcknowledgedSubtasks()); assertEquals(failed.getEndToEndDuration(), copy.getEndToEndDuration()); assertEquals(failed.getStateSize(), copy.getStateSize()); assertEquals(failed.getLatestAcknowledgedSubtaskStats(), copy.getLatestAcknowledgedSubtaskStats()); assertEquals(failed.getStatus(), copy.getStatus()); assertEquals(failed.getFailureMessage(), copy.getFailureMessage()); }
Example 19
Source File: SimpleStringSchemaTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSerializability() throws Exception { final SimpleStringSchema schema = new SimpleStringSchema(StandardCharsets.UTF_16LE); final SimpleStringSchema copy = CommonTestUtils.createCopySerializable(schema); assertEquals(schema.getCharset(), copy.getCharset()); }
Example 20
Source File: CheckpointSettingsSerializableTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testDeserializationOfUserCodeWithUserClassLoader() throws Exception { final ClassLoaderUtils.ObjectAndClassLoader<Serializable> outsideClassLoading = ClassLoaderUtils.createSerializableObjectFromNewClassLoader(); final ClassLoader classLoader = outsideClassLoading.getClassLoader(); final Serializable outOfClassPath = outsideClassLoading.getObject(); final MasterTriggerRestoreHook.Factory[] hooks = { new TestFactory(outOfClassPath) }; final SerializedValue<MasterTriggerRestoreHook.Factory[]> serHooks = new SerializedValue<>(hooks); final JobCheckpointingSettings checkpointingSettings = new JobCheckpointingSettings( Collections.<JobVertexID>emptyList(), Collections.<JobVertexID>emptyList(), Collections.<JobVertexID>emptyList(), new CheckpointCoordinatorConfiguration( 1000L, 10000L, 0L, 1, CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION, true, false, false, 0), new SerializedValue<StateBackend>(new CustomStateBackend(outOfClassPath)), serHooks); final JobGraph jobGraph = new JobGraph(new JobID(), "test job"); jobGraph.setSnapshotSettings(checkpointingSettings); // to serialize/deserialize the job graph to see if the behavior is correct under // distributed execution final JobGraph copy = CommonTestUtils.createCopySerializable(jobGraph); final Time timeout = Time.seconds(10L); final ExecutionGraph eg = ExecutionGraphBuilder.buildGraph( null, copy, new Configuration(), TestingUtils.defaultExecutor(), TestingUtils.defaultExecutor(), mock(SlotProvider.class), classLoader, new StandaloneCheckpointRecoveryFactory(), timeout, new NoRestartStrategy(), new UnregisteredMetricsGroup(), VoidBlobWriter.getInstance(), timeout, log, NettyShuffleMaster.INSTANCE, NoOpJobMasterPartitionTracker.INSTANCE); assertEquals(1, eg.getCheckpointCoordinator().getNumberOfRegisteredMasterHooks()); assertTrue(jobGraph.getCheckpointingSettings().getDefaultStateBackend().deserializeValue(classLoader) instanceof CustomStateBackend); }