Search in sources :

Example 1 with IntSerializer

use of org.apache.flink.api.common.typeutils.base.IntSerializer in project flink by apache.

the class LockableTypeSerializerTest method testDuplicate.

/**
 * This tests that {@link Lockable.LockableTypeSerializer#duplicate()} works as expected.
 */
@Test
public void testDuplicate() {
    IntSerializer nonDuplicatingInnerSerializer = IntSerializer.INSTANCE;
    Assert.assertSame(nonDuplicatingInnerSerializer, nonDuplicatingInnerSerializer.duplicate());
    Lockable.LockableTypeSerializer<Integer> candidateTestShallowDuplicate = new Lockable.LockableTypeSerializer<>(nonDuplicatingInnerSerializer);
    Assert.assertSame(candidateTestShallowDuplicate, candidateTestShallowDuplicate.duplicate());
    TestDuplicateSerializer duplicatingInnerSerializer = new TestDuplicateSerializer();
    Assert.assertNotSame(duplicatingInnerSerializer, duplicatingInnerSerializer.duplicate());
    Lockable.LockableTypeSerializer<Integer> candidateTestDeepDuplicate = new Lockable.LockableTypeSerializer<>(duplicatingInnerSerializer);
    Lockable.LockableTypeSerializer<Integer> deepDuplicate = candidateTestDeepDuplicate.duplicate();
    Assert.assertNotSame(candidateTestDeepDuplicate, deepDuplicate);
    Assert.assertNotSame(candidateTestDeepDuplicate.getElementSerializer(), deepDuplicate.getElementSerializer());
}
Also used : IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) TestDuplicateSerializer(org.apache.flink.runtime.state.heap.TestDuplicateSerializer) Test(org.junit.Test)

Example 2 with IntSerializer

use of org.apache.flink.api.common.typeutils.base.IntSerializer in project flink by apache.

the class OutputEmitterTest method testPartitionHash.

@Test
public void testPartitionHash() {
    // Test for IntValue
    verifyPartitionHashSelectedChannels(50000, 100, RecordType.INTEGER);
    // Test for StringValue
    verifyPartitionHashSelectedChannels(10000, 100, RecordType.STRING);
    // Test hash corner cases
    final TestIntComparator testIntComp = new TestIntComparator();
    final ChannelSelector<SerializationDelegate<Integer>> selector = createChannelSelector(ShipStrategyType.PARTITION_HASH, testIntComp, 100);
    final SerializationDelegate<Integer> serializationDelegate = new SerializationDelegate<>(new IntSerializer());
    assertPartitionHashSelectedChannels(selector, serializationDelegate, Integer.MIN_VALUE, 100);
    assertPartitionHashSelectedChannels(selector, serializationDelegate, -1, 100);
    assertPartitionHashSelectedChannels(selector, serializationDelegate, 0, 100);
    assertPartitionHashSelectedChannels(selector, serializationDelegate, 1, 100);
    assertPartitionHashSelectedChannels(selector, serializationDelegate, Integer.MAX_VALUE, 100);
}
Also used : IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) Test(org.junit.Test)

Example 3 with IntSerializer

use of org.apache.flink.api.common.typeutils.base.IntSerializer in project flink by apache.

the class MultiInputSortingDataInputsTest method twoInputOrderTest.

@SuppressWarnings("unchecked")
public void twoInputOrderTest(int preferredIndex, int sortedIndex) throws Exception {
    CollectingDataOutput<Object> collectingDataOutput = new CollectingDataOutput<>();
    List<StreamElement> sortedInputElements = Arrays.asList(new StreamRecord<>(1, 3), new StreamRecord<>(1, 1), new StreamRecord<>(2, 1), new StreamRecord<>(2, 3), new StreamRecord<>(1, 2), new StreamRecord<>(2, 2), Watermark.MAX_WATERMARK);
    CollectionDataInput<Integer> sortedInput = new CollectionDataInput<>(sortedInputElements, sortedIndex);
    List<StreamElement> preferredInputElements = Arrays.asList(new StreamRecord<>(99, 3), new StreamRecord<>(99, 1), new Watermark(99L));
    CollectionDataInput<Integer> preferredInput = new CollectionDataInput<>(preferredInputElements, preferredIndex);
    KeySelector<Integer, Integer> keySelector = value -> value;
    try (MockEnvironment environment = MockEnvironment.builder().build()) {
        SelectableSortingInputs selectableSortingInputs = MultiInputSortingDataInput.wrapInputs(new DummyInvokable(), new StreamTaskInput[] { sortedInput }, new KeySelector[] { keySelector }, new TypeSerializer[] { new IntSerializer() }, new IntSerializer(), new StreamTaskInput[] { preferredInput }, environment.getMemoryManager(), environment.getIOManager(), true, 1.0, new Configuration(), new ExecutionConfig());
        StreamTaskInput<?>[] sortingDataInputs = selectableSortingInputs.getSortedInputs();
        StreamTaskInput<?>[] preferredDataInputs = selectableSortingInputs.getPassThroughInputs();
        try (StreamTaskInput<Object> preferredTaskInput = (StreamTaskInput<Object>) preferredDataInputs[0];
            StreamTaskInput<Object> sortedTaskInput = (StreamTaskInput<Object>) sortingDataInputs[0]) {
            MultipleInputSelectionHandler selectionHandler = new MultipleInputSelectionHandler(selectableSortingInputs.getInputSelectable(), 2);
            @SuppressWarnings("rawtypes") StreamOneInputProcessor[] inputProcessors = new StreamOneInputProcessor[2];
            inputProcessors[preferredIndex] = new StreamOneInputProcessor<>(preferredTaskInput, collectingDataOutput, new DummyOperatorChain());
            inputProcessors[sortedIndex] = new StreamOneInputProcessor<>(sortedTaskInput, collectingDataOutput, new DummyOperatorChain());
            StreamMultipleInputProcessor processor = new StreamMultipleInputProcessor(selectionHandler, inputProcessors);
            DataInputStatus inputStatus;
            do {
                inputStatus = processor.processInput();
            } while (inputStatus != DataInputStatus.END_OF_INPUT);
        }
    }
    assertThat(collectingDataOutput.events, equalTo(Arrays.asList(new StreamRecord<>(99, 3), new StreamRecord<>(99, 1), // max watermark from the preferred input
    new Watermark(99L), new StreamRecord<>(1, 1), new StreamRecord<>(1, 2), new StreamRecord<>(1, 3), new StreamRecord<>(2, 1), new StreamRecord<>(2, 2), new StreamRecord<>(2, 3), // max watermark from the sorted input
    Watermark.MAX_WATERMARK)));
}
Also used : StreamTaskInput(org.apache.flink.streaming.runtime.io.StreamTaskInput) Arrays(java.util.Arrays) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) KeySelector(org.apache.flink.api.java.functions.KeySelector) BoundedMultiInput(org.apache.flink.streaming.api.operators.BoundedMultiInput) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Configuration(org.apache.flink.configuration.Configuration) SelectableSortingInputs(org.apache.flink.streaming.api.operators.sort.MultiInputSortingDataInput.SelectableSortingInputs) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test) StreamMultipleInputProcessor(org.apache.flink.streaming.runtime.io.StreamMultipleInputProcessor) Assert.assertThat(org.junit.Assert.assertThat) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) List(java.util.List) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) MultipleInputSelectionHandler(org.apache.flink.streaming.runtime.io.MultipleInputSelectionHandler) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) StreamOneInputProcessor(org.apache.flink.streaming.runtime.io.StreamOneInputProcessor) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) Configuration(org.apache.flink.configuration.Configuration) StreamTaskInput(org.apache.flink.streaming.runtime.io.StreamTaskInput) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) SelectableSortingInputs(org.apache.flink.streaming.api.operators.sort.MultiInputSortingDataInput.SelectableSortingInputs) StreamOneInputProcessor(org.apache.flink.streaming.runtime.io.StreamOneInputProcessor) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) StreamMultipleInputProcessor(org.apache.flink.streaming.runtime.io.StreamMultipleInputProcessor) Watermark(org.apache.flink.streaming.api.watermark.Watermark) MultipleInputSelectionHandler(org.apache.flink.streaming.runtime.io.MultipleInputSelectionHandler)

Example 4 with IntSerializer

use of org.apache.flink.api.common.typeutils.base.IntSerializer in project flink by apache.

the class SortingDataInputTest method simpleVariableLengthKeySorting.

@Test
public void simpleVariableLengthKeySorting() throws Exception {
    CollectingDataOutput<Integer> collectingDataOutput = new CollectingDataOutput<>();
    CollectionDataInput<Integer> input = new CollectionDataInput<>(Arrays.asList(new StreamRecord<>(1, 3), new StreamRecord<>(1, 1), new StreamRecord<>(2, 1), new StreamRecord<>(2, 3), new StreamRecord<>(1, 2), new StreamRecord<>(2, 2)));
    MockEnvironment environment = MockEnvironment.builder().build();
    SortingDataInput<Integer, String> sortingDataInput = new SortingDataInput<>(input, new IntSerializer(), new StringSerializer(), (KeySelector<Integer, String>) value -> "" + value, environment.getMemoryManager(), environment.getIOManager(), true, 1.0, new Configuration(), new DummyInvokable(), new ExecutionConfig());
    DataInputStatus inputStatus;
    do {
        inputStatus = sortingDataInput.emitNext(collectingDataOutput);
    } while (inputStatus != DataInputStatus.END_OF_INPUT);
    assertThat(collectingDataOutput.events, equalTo(Arrays.asList(new StreamRecord<>(1, 1), new StreamRecord<>(1, 2), new StreamRecord<>(1, 3), new StreamRecord<>(2, 1), new StreamRecord<>(2, 2), new StreamRecord<>(2, 3))));
}
Also used : Arrays(java.util.Arrays) KeySelector(org.apache.flink.api.java.functions.KeySelector) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Configuration(org.apache.flink.configuration.Configuration) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) Assert.assertThat(org.junit.Assert.assertThat) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) Configuration(org.apache.flink.configuration.Configuration) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) Test(org.junit.Test)

Example 5 with IntSerializer

use of org.apache.flink.api.common.typeutils.base.IntSerializer in project flink by apache.

the class SerializerComparatorTestData method getOrderedIntTestData.

@SuppressWarnings("unchecked")
static Tuple2<byte[], StreamRecord<Integer>>[] getOrderedIntTestData() {
    IntSerializer intSerializer = new IntSerializer();
    DataOutputSerializer outputSerializer = new DataOutputSerializer(intSerializer.getLength());
    return IntStream.range(-10, 10).mapToObj(idx -> {
        try {
            intSerializer.serialize(idx, outputSerializer);
            byte[] copyOfBuffer = outputSerializer.getCopyOfBuffer();
            outputSerializer.clear();
            return Tuple2.of(copyOfBuffer, new StreamRecord<>(idx, idx));
        } catch (IOException e) {
            throw new AssertionError(e);
        }
    }).toArray(Tuple2[]::new);
}
Also used : IntStream(java.util.stream.IntStream) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) Stream(java.util.stream.Stream) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) Tuple2(org.apache.flink.api.java.tuple.Tuple2) DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) IOException(java.io.IOException) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) IOException(java.io.IOException)

Aggregations

IntSerializer (org.apache.flink.api.common.typeutils.base.IntSerializer)12 Test (org.junit.Test)11 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)8 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)7 KeySelector (org.apache.flink.api.java.functions.KeySelector)7 Configuration (org.apache.flink.configuration.Configuration)7 DummyInvokable (org.apache.flink.runtime.operators.testutils.DummyInvokable)7 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)7 Watermark (org.apache.flink.streaming.api.watermark.Watermark)7 DataInputStatus (org.apache.flink.streaming.runtime.io.DataInputStatus)7 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)7 Assert.assertThat (org.junit.Assert.assertThat)7 Arrays (java.util.Arrays)6 StringSerializer (org.apache.flink.api.common.typeutils.base.StringSerializer)5 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)4 BoundedMultiInput (org.apache.flink.streaming.api.operators.BoundedMultiInput)4 SelectableSortingInputs (org.apache.flink.streaming.api.operators.sort.MultiInputSortingDataInput.SelectableSortingInputs)4 MultipleInputSelectionHandler (org.apache.flink.streaming.runtime.io.MultipleInputSelectionHandler)4 StreamMultipleInputProcessor (org.apache.flink.streaming.runtime.io.StreamMultipleInputProcessor)4 StreamOneInputProcessor (org.apache.flink.streaming.runtime.io.StreamOneInputProcessor)4