Java Code Examples for org.apache.flink.runtime.plugable.SerializationDelegate#setInstance()
The following examples show how to use
org.apache.flink.runtime.plugable.SerializationDelegate#setInstance() .
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: OutputEmitterTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private boolean verifyWrongPartitionHashKey(int position, int fieldNum) { final TypeComparator<Record> comparator = new RecordComparatorFactory( new int[] {position}, new Class[] {IntValue.class}).createComparator(); final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector( ShipStrategyType.PARTITION_HASH, comparator, 100); final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer()); Record record = new Record(2); record.setField(fieldNum, new IntValue(1)); delegate.setInstance(record); try { selector.selectChannel(delegate); } catch (NullKeyFieldException re) { Assert.assertEquals(position, re.getFieldNumber()); return true; } return false; }
Example 2
Source File: OutputEmitterTest.java From flink with Apache License 2.0 | 6 votes |
private boolean verifyWrongPartitionHashKey(int position, int fieldNum) { final TypeComparator<Record> comparator = new RecordComparatorFactory( new int[] {position}, new Class[] {IntValue.class}).createComparator(); final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector( ShipStrategyType.PARTITION_HASH, comparator, 100); final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer()); Record record = new Record(2); record.setField(fieldNum, new IntValue(1)); delegate.setInstance(record); try { selector.selectChannel(delegate); } catch (NullKeyFieldException re) { Assert.assertEquals(position, re.getFieldNumber()); return true; } return false; }
Example 3
Source File: OutputEmitterTest.java From flink with Apache License 2.0 | 6 votes |
private boolean verifyWrongPartitionHashKey(int position, int fieldNum) { final TypeComparator<Record> comparator = new RecordComparatorFactory( new int[] {position}, new Class[] {IntValue.class}).createComparator(); final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector( ShipStrategyType.PARTITION_HASH, comparator, 100); final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer()); Record record = new Record(2); record.setField(fieldNum, new IntValue(1)); delegate.setInstance(record); try { selector.selectChannel(delegate); } catch (NullKeyFieldException re) { Assert.assertEquals(position, re.getFieldNumber()); return true; } return false; }
Example 4
Source File: OutputEmitterTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testMultiKeys() { final int numberOfChannels = 100; final int numRecords = 5000; final TypeComparator<Record> multiComp = new RecordComparatorFactory( new int[] {0,1, 3}, new Class[] {IntValue.class, StringValue.class, DoubleValue.class}).createComparator(); final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector( ShipStrategyType.PARTITION_HASH, multiComp, numberOfChannels); final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer()); int[] hits = new int[numberOfChannels]; for (int i = 0; i < numRecords; i++) { Record record = new Record(4); record.setField(0, new IntValue(i)); record.setField(1, new StringValue("AB" + i + "CD" + i)); record.setField(3, new DoubleValue(i * 3.141d)); delegate.setInstance(record); int channel = selector.selectChannel(delegate); hits[channel]++; } int totalHitCount = 0; for (int hit : hits) { assertTrue(hit > 0); totalHitCount += hit; } assertTrue(totalHitCount == numRecords); }
Example 5
Source File: OutputEmitterTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void assertPartitionHashSelectedChannels( ChannelSelector selector, SerializationDelegate<Integer> serializationDelegate, int record, int numberOfChannels) { serializationDelegate.setInstance(record); int selectedChannel = selector.selectChannel(serializationDelegate); assertTrue(selectedChannel >= 0 && selectedChannel <= numberOfChannels - 1); }
Example 6
Source File: OutputEmitterTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testMultiKeys() { final int numberOfChannels = 100; final int numRecords = 5000; final TypeComparator<Record> multiComp = new RecordComparatorFactory( new int[] {0,1, 3}, new Class[] {IntValue.class, StringValue.class, DoubleValue.class}).createComparator(); final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector( ShipStrategyType.PARTITION_HASH, multiComp, numberOfChannels); final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer()); int[] hits = new int[numberOfChannels]; for (int i = 0; i < numRecords; i++) { Record record = new Record(4); record.setField(0, new IntValue(i)); record.setField(1, new StringValue("AB" + i + "CD" + i)); record.setField(3, new DoubleValue(i * 3.141d)); delegate.setInstance(record); int channel = selector.selectChannel(delegate); hits[channel]++; } int totalHitCount = 0; for (int hit : hits) { assertTrue(hit > 0); totalHitCount += hit; } assertTrue(totalHitCount == numRecords); }
Example 7
Source File: OutputEmitterTest.java From flink with Apache License 2.0 | 5 votes |
private void assertPartitionHashSelectedChannels( ChannelSelector selector, SerializationDelegate<Integer> serializationDelegate, int record, int numberOfChannels) { serializationDelegate.setInstance(record); int selectedChannel = selector.selectChannel(serializationDelegate); assertTrue(selectedChannel >= 0 && selectedChannel <= numberOfChannels - 1); }
Example 8
Source File: StreamTaskNetworkInputTest.java From flink with Apache License 2.0 | 5 votes |
private void serializeRecord(long value, BufferBuilder bufferBuilder) throws IOException { RecordSerializer<SerializationDelegate<StreamElement>> serializer = new SpanningRecordSerializer<>(); SerializationDelegate<StreamElement> serializationDelegate = new SerializationDelegate<>( new StreamElementSerializer<>(LongSerializer.INSTANCE)); serializationDelegate.setInstance(new StreamRecord<>(value)); serializer.serializeRecord(serializationDelegate); assertFalse(serializer.copyToBufferBuilder(bufferBuilder).isFullBuffer()); }
Example 9
Source File: OutputEmitterTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testMultiKeys() { final int numberOfChannels = 100; final int numRecords = 5000; final TypeComparator<Record> multiComp = new RecordComparatorFactory( new int[] {0,1, 3}, new Class[] {IntValue.class, StringValue.class, DoubleValue.class}).createComparator(); final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector( ShipStrategyType.PARTITION_HASH, multiComp, numberOfChannels); final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer()); int[] hits = new int[numberOfChannels]; for (int i = 0; i < numRecords; i++) { Record record = new Record(4); record.setField(0, new IntValue(i)); record.setField(1, new StringValue("AB" + i + "CD" + i)); record.setField(3, new DoubleValue(i * 3.141d)); delegate.setInstance(record); int channel = selector.selectChannel(delegate); hits[channel]++; } int totalHitCount = 0; for (int hit : hits) { assertTrue(hit > 0); totalHitCount += hit; } assertTrue(totalHitCount == numRecords); }
Example 10
Source File: OutputEmitterTest.java From flink with Apache License 2.0 | 5 votes |
private void assertPartitionHashSelectedChannels( ChannelSelector selector, SerializationDelegate<Integer> serializationDelegate, int record, int numberOfChannels) { serializationDelegate.setInstance(record); int selectedChannel = selector.selectChannel(serializationDelegate); assertTrue(selectedChannel >= 0 && selectedChannel <= numberOfChannels - 1); }
Example 11
Source File: StreamTaskNetworkInputTest.java From flink with Apache License 2.0 | 5 votes |
private void serializeRecord(long value, BufferBuilder bufferBuilder) throws IOException { RecordSerializer<SerializationDelegate<StreamElement>> serializer = new SpanningRecordSerializer<>(); SerializationDelegate<StreamElement> serializationDelegate = new SerializationDelegate<>( new StreamElementSerializer<>(LongSerializer.INSTANCE)); serializationDelegate.setInstance(new StreamRecord<>(value)); serializer.serializeRecord(serializationDelegate); assertFalse(serializer.copyToBufferBuilder(bufferBuilder).isFullBuffer()); }
Example 12
Source File: StreamTestSingleInputGate.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void setupInputChannels() throws IOException, InterruptedException { for (int i = 0; i < numInputChannels; i++) { final int channelIndex = i; final RecordSerializer<SerializationDelegate<Object>> recordSerializer = new SpanningRecordSerializer<SerializationDelegate<Object>>(); final SerializationDelegate<Object> delegate = (SerializationDelegate<Object>) (SerializationDelegate<?>) new SerializationDelegate<StreamElement>(new StreamElementSerializer<T>(serializer)); inputQueues[channelIndex] = new ConcurrentLinkedQueue<InputValue<Object>>(); inputChannels[channelIndex] = new TestInputChannel(inputGate, i); final BufferAndAvailabilityProvider answer = () -> { ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex]; InputValue<Object> input; boolean moreAvailable; synchronized (inputQueue) { input = inputQueue.poll(); moreAvailable = !inputQueue.isEmpty(); } if (input != null && input.isStreamEnd()) { inputChannels[channelIndex].setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), moreAvailable, 0)); } else if (input != null && input.isStreamRecord()) { Object inputElement = input.getStreamRecord(); delegate.setInstance(inputElement); recordSerializer.serializeRecord(delegate); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); recordSerializer.copyToBufferBuilder(bufferBuilder); bufferBuilder.finish(); // Call getCurrentBuffer to ensure size is set return Optional.of(new BufferAndAvailability(buildSingleBuffer(bufferBuilder), moreAvailable, 0)); } else if (input != null && input.isEvent()) { AbstractEvent event = input.getEvent(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(event), moreAvailable, 0)); } else { return Optional.empty(); } }; inputChannels[channelIndex].addBufferAndAvailability(answer); inputGate.setInputChannel(new IntermediateResultPartitionID(), inputChannels[channelIndex]); } }
Example 13
Source File: StreamTestSingleInputGate.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void setupInputChannels() throws IOException, InterruptedException { for (int i = 0; i < numInputChannels; i++) { final int channelIndex = i; final RecordSerializer<SerializationDelegate<Object>> recordSerializer = new SpanningRecordSerializer<SerializationDelegate<Object>>(); final SerializationDelegate<Object> delegate = (SerializationDelegate<Object>) (SerializationDelegate<?>) new SerializationDelegate<StreamElement>(new StreamElementSerializer<T>(serializer)); inputQueues[channelIndex] = new ConcurrentLinkedQueue<InputValue<Object>>(); inputChannels[channelIndex] = new TestInputChannel(inputGate, i); final BufferAndAvailabilityProvider answer = () -> { ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex]; InputValue<Object> input; boolean moreAvailable; synchronized (inputQueue) { input = inputQueue.poll(); moreAvailable = !inputQueue.isEmpty(); } if (input != null && input.isStreamEnd()) { inputChannels[channelIndex].setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), moreAvailable, 0)); } else if (input != null && input.isStreamRecord()) { Object inputElement = input.getStreamRecord(); delegate.setInstance(inputElement); recordSerializer.serializeRecord(delegate); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); recordSerializer.copyToBufferBuilder(bufferBuilder); bufferBuilder.finish(); // Call getCurrentBuffer to ensure size is set return Optional.of(new BufferAndAvailability(buildSingleBuffer(bufferBuilder), moreAvailable, 0)); } else if (input != null && input.isEvent()) { AbstractEvent event = input.getEvent(); if (event instanceof EndOfPartitionEvent) { inputChannels[channelIndex].setReleased(); } return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(event), moreAvailable, 0)); } else { return Optional.empty(); } }; inputChannels[channelIndex].addBufferAndAvailability(answer); inputGate.setInputChannel(new IntermediateResultPartitionID(), inputChannels[channelIndex]); } }
Example 14
Source File: StreamTestSingleInputGate.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void setupInputChannels() { for (int i = 0; i < numInputChannels; i++) { final int channelIndex = i; final RecordSerializer<SerializationDelegate<Object>> recordSerializer = new SpanningRecordSerializer<SerializationDelegate<Object>>(); final SerializationDelegate<Object> delegate = (SerializationDelegate<Object>) (SerializationDelegate<?>) new SerializationDelegate<>(new StreamElementSerializer<T>(serializer)); inputQueues[channelIndex] = new ConcurrentLinkedQueue<>(); inputChannels[channelIndex] = new TestInputChannel(inputGate, i); final BufferAndAvailabilityProvider answer = () -> { ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex]; InputValue<Object> input; boolean moreAvailable; synchronized (inputQueue) { input = inputQueue.poll(); moreAvailable = !inputQueue.isEmpty(); } if (input != null && input.isStreamEnd()) { inputChannels[channelIndex].setReleased(); return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), moreAvailable, 0)); } else if (input != null && input.isStreamRecord()) { Object inputElement = input.getStreamRecord(); delegate.setInstance(inputElement); recordSerializer.serializeRecord(delegate); BufferBuilder bufferBuilder = createBufferBuilder(bufferSize); BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumer(); recordSerializer.copyToBufferBuilder(bufferBuilder); bufferBuilder.finish(); // Call getCurrentBuffer to ensure size is set return Optional.of(new BufferAndAvailability(bufferConsumer.build(), moreAvailable, 0)); } else if (input != null && input.isEvent()) { AbstractEvent event = input.getEvent(); if (event instanceof EndOfPartitionEvent) { inputChannels[channelIndex].setReleased(); } return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(event), moreAvailable, 0)); } else { return Optional.empty(); } }; inputChannels[channelIndex].addBufferAndAvailability(answer); } inputGate.setInputChannels(inputChannels); }