Java Code Examples for org.apache.flink.api.common.typeutils.base.StringSerializer
The following examples show how to use
org.apache.flink.api.common.typeutils.base.StringSerializer. 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: TupleComparatorTTT1Test.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override protected TupleSerializer<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>> createSerializer() { return new TupleSerializer<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>( (Class<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>) (Class<?>) Tuple3.class, new TypeSerializer[]{ new TupleSerializer<Tuple2<String, Double>> ( (Class<Tuple2<String, Double>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }), new TupleSerializer<Tuple2<Long, Long>> ( (Class<Tuple2<Long, Long>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ LongSerializer.INSTANCE, LongSerializer.INSTANCE }), new TupleSerializer<Tuple2<Integer, Long>> ( (Class<Tuple2<Integer, Long>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ IntSerializer.INSTANCE, LongSerializer.INSTANCE }) }); }
Example 2
Source Project: flink Source File: StreamTaskOperatorTimerTest.java License: Apache License 2.0 | 6 votes |
@Test public void testOperatorYieldExecutesSelectedTimers() throws Exception { final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>( OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); testHarness.setupOperatorChain(new OperatorID(), new TestOperatorFactory()) .chain(new OperatorID(), new TestOperatorFactory(), StringSerializer.INSTANCE) .finish(); testHarness.invoke(); testHarness.waitForTaskRunning(); final String trigger = TRIGGER_PREFIX + 42; testHarness.processElement(new StreamRecord<>(trigger)); testHarness.endInput(); testHarness.waitForTaskCompletion(); List<String> events = new ArrayList<>(); testHarness.getOutput().forEach(element -> events.add(((StreamRecord<String>) element).getValue())); assertThat(events, is(Arrays.asList(trigger, RESULT_PREFIX + "1:0", RESULT_PREFIX + "0:0"))); }
Example 3
Source Project: Flink-CEPplus Source File: TupleComparatorTTT2Test.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override protected TupleSerializer<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>> createSerializer() { return new TupleSerializer<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>( (Class<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>) (Class<?>) Tuple3.class, new TypeSerializer[]{ new TupleSerializer<Tuple2<String, Double>> ( (Class<Tuple2<String, Double>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ StringSerializer.INSTANCE, DoubleSerializer.INSTANCE}), new TupleSerializer<Tuple2<Long, Long>> ( (Class<Tuple2<Long, Long>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ LongSerializer.INSTANCE, LongSerializer.INSTANCE}), new TupleSerializer<Tuple2<Integer, Long>> ( (Class<Tuple2<Integer, Long>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ IntSerializer.INSTANCE, LongSerializer.INSTANCE}) }); }
Example 4
Source Project: Flink-CEPplus Source File: PojoSerializerSnapshotTest.java License: Apache License 2.0 | 6 votes |
@Test public void testRestoreSerializerWithSameFields() { final PojoSerializerSnapshot<TestPojo> testSnapshot = buildTestSnapshot(Arrays.asList( ID_FIELD, NAME_FIELD, HEIGHT_FIELD )); final TypeSerializer<TestPojo> restoredSerializer = testSnapshot.restoreSerializer(); assertSame(restoredSerializer.getClass(), PojoSerializer.class); final PojoSerializer<TestPojo> restoredPojoSerializer = (PojoSerializer<TestPojo>) restoredSerializer; final Field[] restoredFields = restoredPojoSerializer.getFields(); assertArrayEquals( new Field[] { ID_FIELD.field, NAME_FIELD.field, HEIGHT_FIELD.field }, restoredFields); final TypeSerializer<?>[] restoredFieldSerializers = restoredPojoSerializer.getFieldSerializers(); assertArrayEquals( new TypeSerializer[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }, restoredFieldSerializers); }
Example 5
Source Project: flink Source File: BinaryRowTest.java License: Apache License 2.0 | 6 votes |
@Test public void testGeneric() { BinaryRow row = new BinaryRow(3); BinaryRowWriter writer = new BinaryRowWriter(row); BinaryGeneric<String> hahah = new BinaryGeneric<>("hahah", StringSerializer.INSTANCE); writer.writeGeneric(0, hahah); writer.setNullAt(1); hahah.ensureMaterialized(); writer.writeGeneric(2, hahah); writer.complete(); BinaryGeneric<String> generic0 = row.getGeneric(0); assertEquals(hahah, generic0); assertTrue(row.isNullAt(1)); BinaryGeneric<String> generic2 = row.getGeneric(2); assertEquals(hahah, generic2); }
Example 6
Source Project: flink Source File: StateDescriptorTest.java License: 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 7
Source Project: beam Source File: FlinkStateInternals.java License: Apache License 2.0 | 6 votes |
@Override public void addAccum(AccumT accum) { try { org.apache.flink.api.common.state.ValueState<AccumT> state = flinkStateBackend.getPartitionedState( namespace.stringKey(), StringSerializer.INSTANCE, flinkStateDescriptor); AccumT current = state.value(); if (current == null) { state.update(accum); } else { current = combineFn.mergeAccumulators(Lists.newArrayList(current, accum)); state.update(current); } } catch (Exception e) { throw new RuntimeException("Error adding to state.", e); } }
Example 8
Source Project: Flink-CEPplus Source File: ValueStateDescriptorTest.java License: Apache License 2.0 | 6 votes |
@Test public void testHashCodeEquals() throws Exception { final String name = "testName"; ValueStateDescriptor<String> original = new ValueStateDescriptor<>(name, String.class); ValueStateDescriptor<String> same = new ValueStateDescriptor<>(name, String.class); ValueStateDescriptor<String> sameBySerializer = new ValueStateDescriptor<>(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 ValueStateDescriptor<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 9
Source Project: Flink-CEPplus Source File: StateDescriptorTest.java License: 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 10
Source Project: flink Source File: TupleComparatorTTT1Test.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override protected TupleSerializer<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>> createSerializer() { return new TupleSerializer<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>( (Class<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>) (Class<?>) Tuple3.class, new TypeSerializer[]{ new TupleSerializer<Tuple2<String, Double>> ( (Class<Tuple2<String, Double>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }), new TupleSerializer<Tuple2<Long, Long>> ( (Class<Tuple2<Long, Long>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ LongSerializer.INSTANCE, LongSerializer.INSTANCE }), new TupleSerializer<Tuple2<Integer, Long>> ( (Class<Tuple2<Integer, Long>>) (Class<?>) Tuple2.class, new TypeSerializer[]{ IntSerializer.INSTANCE, LongSerializer.INSTANCE }) }); }
Example 11
Source Project: flink Source File: NonReusingSortMergeInnerJoinIteratorITCase.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Before public void beforeTest() { serializer1 = new TupleSerializer<Tuple2<Integer, String>>( (Class<Tuple2<Integer, String>>) (Class<?>) Tuple2.class, new TypeSerializer<?>[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE }); serializer2 = new TupleSerializer<Tuple2<Integer, String>>( (Class<Tuple2<Integer, String>>) (Class<?>) Tuple2.class, new TypeSerializer<?>[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE }); comparator1 = new TupleComparator<Tuple2<Integer, String>>( new int[]{0}, new TypeComparator<?>[] { new IntComparator(true) }, new TypeSerializer<?>[] { IntSerializer.INSTANCE }); comparator2 = new TupleComparator<Tuple2<Integer, String>>( new int[]{0}, new TypeComparator<?>[] { new IntComparator(true) }, new TypeSerializer<?>[] { IntSerializer.INSTANCE }); pairComparator = new GenericPairComparator<Tuple2<Integer, String>, Tuple2<Integer, String>>(comparator1, comparator2); this.memoryManager = new MemoryManager(MEMORY_SIZE, 1); this.ioManager = new IOManagerAsync(); }
Example 12
Source Project: flink Source File: PojoSerializerSnapshotTest.java License: Apache License 2.0 | 6 votes |
@Test public void testRestoreSerializerWithRemovedFields() { final PojoSerializerSnapshot<TestPojo> testSnapshot = buildTestSnapshot(Arrays.asList( mockRemovedField(ID_FIELD), NAME_FIELD, mockRemovedField(HEIGHT_FIELD) )); final TypeSerializer<TestPojo> restoredSerializer = testSnapshot.restoreSerializer(); assertTrue(restoredSerializer.getClass() == PojoSerializer.class); final PojoSerializer<TestPojo> restoredPojoSerializer = (PojoSerializer<TestPojo>) restoredSerializer; final Field[] restoredFields = restoredPojoSerializer.getFields(); assertArrayEquals( new Field[] { null, NAME_FIELD.field, null }, restoredFields); final TypeSerializer<?>[] restoredFieldSerializers = restoredPojoSerializer.getFieldSerializers(); assertArrayEquals( new TypeSerializer[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }, restoredFieldSerializers); }
Example 13
Source Project: Flink-CEPplus Source File: StateBackendTestBase.java License: Apache License 2.0 | 6 votes |
/** * This test verifies that all ListState implementations are consistent in not allowing * {@link ListState#addAll(List)} to be called with {@code null}. */ @Test public void testListStateUpdateNull() throws Exception { AbstractKeyedStateBackend<String> keyedBackend = createKeyedBackend(StringSerializer.INSTANCE); final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class); try { ListState<Long> state = keyedBackend.getPartitionedState( VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescr); keyedBackend.setCurrentKey("abc"); assertNull(state.get()); expectedException.expect(NullPointerException.class); state.update(null); } finally { keyedBackend.close(); keyedBackend.dispose(); } }
Example 14
Source Project: flink Source File: ValueStateDescriptorTest.java License: Apache License 2.0 | 6 votes |
@Test public void testHashCodeEquals() throws Exception { final String name = "testName"; ValueStateDescriptor<String> original = new ValueStateDescriptor<>(name, String.class); ValueStateDescriptor<String> same = new ValueStateDescriptor<>(name, String.class); ValueStateDescriptor<String> sameBySerializer = new ValueStateDescriptor<>(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 ValueStateDescriptor<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 15
Source Project: Flink-CEPplus Source File: StateBackendTestBase.java License: Apache License 2.0 | 6 votes |
@Test public void testApplyToAllKeysLambdaFunction() throws Exception { AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE); try { ListStateDescriptor<String> listStateDescriptor = new ListStateDescriptor<>("foo", StringSerializer.INSTANCE); ListState<String> listState = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, listStateDescriptor); for (int i = 0; i < 100; ++i) { backend.setCurrentKey(i); listState.add("Hello" + i); } // valid state value via applyToAllKeys(). backend.applyToAllKeys(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, listStateDescriptor, (Integer key, ListState<String> state) -> assertEquals("Hello" + key, state.get().iterator().next()) ); } finally { IOUtils.closeQuietly(backend); backend.dispose(); } }
Example 16
Source Project: flink Source File: StateDescriptorTest.java License: 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 17
Source Project: flink Source File: StateSnapshotCompressionTest.java License: Apache License 2.0 | 6 votes |
private HeapKeyedStateBackend<String> getStringHeapKeyedStateBackend( ExecutionConfig executionConfig, Collection<KeyedStateHandle> stateHandles) throws BackendBuildingException { return new HeapKeyedStateBackendBuilder<>( mock(TaskKvStateRegistry.class), StringSerializer.INSTANCE, StateSnapshotCompressionTest.class.getClassLoader(), 16, new KeyGroupRange(0, 15), executionConfig, TtlTimeProvider.DEFAULT, stateHandles, AbstractStateBackend.getCompressionDecorator(executionConfig), TestLocalRecoveryConfig.disabled(), mock(HeapPriorityQueueSetFactory.class), true, new CloseableRegistry()).build(); }
Example 18
Source Project: Flink-CEPplus Source File: NonReusingSortMergeInnerJoinIteratorITCase.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Before public void beforeTest() { serializer1 = new TupleSerializer<Tuple2<Integer, String>>( (Class<Tuple2<Integer, String>>) (Class<?>) Tuple2.class, new TypeSerializer<?>[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE }); serializer2 = new TupleSerializer<Tuple2<Integer, String>>( (Class<Tuple2<Integer, String>>) (Class<?>) Tuple2.class, new TypeSerializer<?>[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE }); comparator1 = new TupleComparator<Tuple2<Integer, String>>( new int[]{0}, new TypeComparator<?>[] { new IntComparator(true) }, new TypeSerializer<?>[] { IntSerializer.INSTANCE }); comparator2 = new TupleComparator<Tuple2<Integer, String>>( new int[]{0}, new TypeComparator<?>[] { new IntComparator(true) }, new TypeSerializer<?>[] { IntSerializer.INSTANCE }); pairComparator = new GenericPairComparator<Tuple2<Integer, String>, Tuple2<Integer, String>>(comparator1, comparator2); this.memoryManager = new MemoryManager(MEMORY_SIZE, 1); this.ioManager = new IOManagerAsync(); }
Example 19
Source Project: flink Source File: InternalTimerServiceImplTest.java License: Apache License 2.0 | 6 votes |
@Test public void testKeyGroupStartIndexSetting() { int startKeyGroupIdx = 7; int endKeyGroupIdx = 21; KeyGroupRange testKeyGroupList = new KeyGroupRange(startKeyGroupIdx, endKeyGroupIdx); TestKeyContext keyContext = new TestKeyContext(); TestProcessingTimeService processingTimeService = new TestProcessingTimeService(); InternalTimerServiceImpl<Integer, String> service = createInternalTimerService( testKeyGroupList, keyContext, processingTimeService, IntSerializer.INSTANCE, StringSerializer.INSTANCE, createQueueFactory()); Assert.assertEquals(startKeyGroupIdx, service.getLocalKeyGroupRangeStartIdx()); }
Example 20
Source Project: Flink-CEPplus Source File: InternalTimerServiceImplTest.java License: Apache License 2.0 | 6 votes |
@Test public void testKeyGroupStartIndexSetting() { int startKeyGroupIdx = 7; int endKeyGroupIdx = 21; KeyGroupRange testKeyGroupList = new KeyGroupRange(startKeyGroupIdx, endKeyGroupIdx); TestKeyContext keyContext = new TestKeyContext(); TestProcessingTimeService processingTimeService = new TestProcessingTimeService(); InternalTimerServiceImpl<Integer, String> service = createInternalTimerService( testKeyGroupList, keyContext, processingTimeService, IntSerializer.INSTANCE, StringSerializer.INSTANCE, createQueueFactory()); Assert.assertEquals(startKeyGroupIdx, service.getLocalKeyGroupRangeStartIdx()); }
Example 21
Source Project: Flink-CEPplus Source File: TupleComparatorTTT1Test.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override protected TupleComparator<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>> createComparator( boolean ascending) { return new TupleComparator<Tuple3<Tuple2<String, Double>, Tuple2<Long, Long>, Tuple2<Integer, Long>>>( new int[] { 0 }, new TypeComparator[] { new TupleComparator<Tuple2<String, Double>>( new int[] { 0, 1 }, new TypeComparator[] { new StringComparator(ascending), new DoubleComparator(ascending) }, new TypeSerializer[] { StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }) }, new TypeSerializer[] { new TupleSerializer<Tuple2<String, Double>>( (Class<Tuple2<String, Double>>) (Class<?>) Tuple2.class, new TypeSerializer[] { StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }), new TupleSerializer<Tuple2<Long, Long>>( (Class<Tuple2<Long, Long>>) (Class<?>) Tuple2.class, new TypeSerializer[] { LongSerializer.INSTANCE, LongSerializer.INSTANCE }), new TupleSerializer<Tuple2<Integer, Long>>( (Class<Tuple2<Integer, Long>>) (Class<?>) Tuple2.class, new TypeSerializer[] { IntSerializer.INSTANCE, LongSerializer.INSTANCE }) }); }
Example 22
Source Project: Flink-CEPplus Source File: TupleComparatorISD2Test.java License: Apache License 2.0 | 5 votes |
@Override protected TupleComparator<Tuple3<Integer, String, Double>> createComparator(boolean ascending) { return new TupleComparator<Tuple3<Integer, String, Double>>( new int[]{0, 1}, new TypeComparator[]{ new IntComparator(ascending), new StringComparator(ascending) }, new TypeSerializer[]{ IntSerializer.INSTANCE, StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }); }
Example 23
Source Project: flink Source File: PojoSerializerSnapshotTest.java License: Apache License 2.0 | 5 votes |
@Test public void testResolveSchemaCompatibilityWithCompatibleWithReconfigurationFieldSerializers() { final PojoSerializerSnapshot<TestPojo> testSnapshot = buildTestSnapshot(Arrays.asList( mockFieldSerializerSnapshot( ID_FIELD, SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration()), NAME_FIELD, HEIGHT_FIELD )); final PojoSerializer<TestPojo> newPojoSerializer = buildTestNewPojoSerializer(Arrays.asList( mockFieldSerializer(ID_FIELD, new SchemaCompatibilityTestingSerializer()), NAME_FIELD, HEIGHT_FIELD )); final TypeSerializerSchemaCompatibility<TestPojo> resultCompatibility = testSnapshot.resolveSchemaCompatibility(newPojoSerializer); assertTrue(resultCompatibility.isCompatibleWithReconfiguredSerializer()); final TypeSerializer<TestPojo> reconfiguredSerializer = resultCompatibility.getReconfiguredSerializer(); assertSame(reconfiguredSerializer.getClass(), PojoSerializer.class); final PojoSerializer<TestPojo> reconfiguredPojoSerializer = (PojoSerializer<TestPojo>) reconfiguredSerializer; final TypeSerializer<?>[] reconfiguredFieldSerializers = reconfiguredPojoSerializer.getFieldSerializers(); assertArrayEquals( new TypeSerializer[] { new SchemaCompatibilityTestingSerializer(), StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }, reconfiguredFieldSerializers); }
Example 24
Source Project: flink Source File: ReducingStateDescriptorTest.java License: Apache License 2.0 | 5 votes |
@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 25
Source Project: flink Source File: PojoSerializerSnapshotTest.java License: Apache License 2.0 | 5 votes |
@Test public void testResolveSchemaCompatibilityWithCompatibleWithReconfigurationFieldSerializers() { final PojoSerializerSnapshot<TestPojo> testSnapshot = buildTestSnapshot(Arrays.asList( mockFieldSerializerSnapshot( ID_FIELD, SchemaCompatibilityTestingSnapshot.thatIsCompatibleWithNextSerializerAfterReconfiguration()), NAME_FIELD, HEIGHT_FIELD )); final PojoSerializer<TestPojo> newPojoSerializer = buildTestNewPojoSerializer(Arrays.asList( mockFieldSerializer(ID_FIELD, new SchemaCompatibilityTestingSerializer()), NAME_FIELD, HEIGHT_FIELD )); final TypeSerializerSchemaCompatibility<TestPojo> resultCompatibility = testSnapshot.resolveSchemaCompatibility(newPojoSerializer); assertTrue(resultCompatibility.isCompatibleWithReconfiguredSerializer()); final TypeSerializer<TestPojo> reconfiguredSerializer = resultCompatibility.getReconfiguredSerializer(); assertSame(reconfiguredSerializer.getClass(), PojoSerializer.class); final PojoSerializer<TestPojo> reconfiguredPojoSerializer = (PojoSerializer<TestPojo>) reconfiguredSerializer; final TypeSerializer<?>[] reconfiguredFieldSerializers = reconfiguredPojoSerializer.getFieldSerializers(); assertArrayEquals( new TypeSerializer[] { new SchemaCompatibilityTestingSerializer(), StringSerializer.INSTANCE, DoubleSerializer.INSTANCE }, reconfiguredFieldSerializers); }
Example 26
Source Project: Flink-CEPplus Source File: TupleComparatorISD1Test.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override protected TupleSerializer<Tuple3<Integer, String, Double>> createSerializer() { return new TupleSerializer<Tuple3<Integer, String, Double>>( (Class<Tuple3<Integer, String, Double>>) (Class<?>) Tuple3.class, new TypeSerializer[]{ new IntSerializer(), new StringSerializer(), new DoubleSerializer()}); }
Example 27
Source Project: beam Source File: FlinkStateInternals.java License: Apache License 2.0 | 5 votes |
@Override public void add(T value) { try { flinkStateBackend .getPartitionedState( namespace.stringKey(), StringSerializer.INSTANCE, flinkStateDescriptor) .put(value, true); } catch (Exception e) { throw new RuntimeException("Error add value to state.", e); } }
Example 28
Source Project: flink Source File: RocksDBAsyncSnapshotTest.java License: Apache License 2.0 | 5 votes |
@Override public void processElement(StreamRecord<String> element) throws Exception { // we also don't care ValueState<String> state = getPartitionedState( VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, new ValueStateDescriptor<>("count", StringSerializer.INSTANCE)); state.update(element.getValue()); }
Example 29
Source Project: flink Source File: TupleComparatorISD1Test.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override protected TupleSerializer<Tuple3<Integer, String, Double>> createSerializer() { return new TupleSerializer<Tuple3<Integer, String, Double>>( (Class<Tuple3<Integer, String, Double>>) (Class<?>) Tuple3.class, new TypeSerializer[]{ new IntSerializer(), new StringSerializer(), new DoubleSerializer()}); }
Example 30
Source Project: Flink-CEPplus Source File: MigrationUtils.java License: Apache License 2.0 | 5 votes |
/** * Skips bytes corresponding to serialized states. In flink 1.6+ the states are no longer kept in state. */ static void skipSerializedStates(DataInputView in) throws IOException { TypeSerializer<String> nameSerializer = StringSerializer.INSTANCE; TypeSerializer<State.StateType> stateTypeSerializer = new EnumSerializer<>(State.StateType.class); TypeSerializer<StateTransitionAction> actionSerializer = new EnumSerializer<>(StateTransitionAction.class); final int noOfStates = in.readInt(); for (int i = 0; i < noOfStates; i++) { nameSerializer.deserialize(in); stateTypeSerializer.deserialize(in); } for (int i = 0; i < noOfStates; i++) { String srcName = nameSerializer.deserialize(in); int noOfTransitions = in.readInt(); for (int j = 0; j < noOfTransitions; j++) { String src = nameSerializer.deserialize(in); Preconditions.checkState(src.equals(srcName), "Source Edge names do not match (" + srcName + " - " + src + ")."); nameSerializer.deserialize(in); actionSerializer.deserialize(in); try { skipCondition(in); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } }