use of org.apache.flink.core.memory.DataInputViewStreamWrapper in project flink by apache.
the class AbstractAlignedProcessingTimeWindowOperator method restoreState.
@Override
public void restoreState(FSDataInputStream in) throws Exception {
super.restoreState(in);
DataInputViewStreamWrapper inView = new DataInputViewStreamWrapper(in);
final long nextEvaluationTime = inView.readLong();
final long nextSlideTime = inView.readLong();
AbstractKeyedTimePanes<IN, KEY, STATE, OUT> panes = createPanes(keySelector, function);
panes.readFromInput(inView, keySerializer, stateTypeSerializer);
restoredState = new RestoredState<>(panes, nextEvaluationTime, nextSlideTime);
}
use of org.apache.flink.core.memory.DataInputViewStreamWrapper in project flink by apache.
the class StateInitializationContextImplTest method close.
@Test
public void close() throws Exception {
int count = 0;
int stopCount = NUM_HANDLES / 2;
boolean isClosed = false;
try {
for (KeyGroupStatePartitionStreamProvider stateStreamProvider : initializationContext.getRawKeyedStateInputs()) {
Assert.assertNotNull(stateStreamProvider);
if (count == stopCount) {
initializationContext.close();
isClosed = true;
}
try (InputStream is = stateStreamProvider.getStream()) {
DataInputView div = new DataInputViewStreamWrapper(is);
try {
int val = div.readInt();
Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
if (isClosed) {
Assert.fail("Close was ignored: stream");
}
++count;
} catch (IOException ioex) {
if (!isClosed) {
throw ioex;
}
}
}
}
Assert.fail("Close was ignored: registry");
} catch (IOException iex) {
Assert.assertTrue(isClosed);
Assert.assertEquals(stopCount, count);
}
}
use of org.apache.flink.core.memory.DataInputViewStreamWrapper in project flink by apache.
the class StateInitializationContextImplTest method getOperatorStateStore.
@Test
public void getOperatorStateStore() throws Exception {
Set<Integer> readStatesCount = new HashSet<>();
for (StatePartitionStreamProvider statePartitionStreamProvider : initializationContext.getRawOperatorStateInputs()) {
Assert.assertNotNull(statePartitionStreamProvider);
try (InputStream is = statePartitionStreamProvider.getStream()) {
DataInputView div = new DataInputViewStreamWrapper(is);
Assert.assertTrue(readStatesCount.add(div.readInt()));
}
}
Assert.assertEquals(writtenOperatorStates, readStatesCount);
}
use of org.apache.flink.core.memory.DataInputViewStreamWrapper in project flink by apache.
the class SavepointV1SerializerTest method testSerializeDeserializeV1.
/**
* Test serialization of {@link SavepointV1} instance.
*/
@Test
public void testSerializeDeserializeV1() throws Exception {
Random r = new Random(42);
for (int i = 0; i < 100; ++i) {
SavepointV1 expected = new SavepointV1(i + 123123, SavepointV1Test.createTaskStates(1 + r.nextInt(64), 1 + r.nextInt(64)));
SavepointV1Serializer serializer = SavepointV1Serializer.INSTANCE;
// Serialize
ByteArrayOutputStreamWithPos baos = new ByteArrayOutputStreamWithPos();
serializer.serialize(expected, new DataOutputViewStreamWrapper(baos));
byte[] bytes = baos.toByteArray();
// Deserialize
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
Savepoint actual = serializer.deserialize(new DataInputViewStreamWrapper(bais), Thread.currentThread().getContextClassLoader());
assertEquals(expected, actual);
}
}
use of org.apache.flink.core.memory.DataInputViewStreamWrapper in project flink by apache.
the class OutputEmitterTest method testWrongKeyClass.
@Test
public void testWrongKeyClass() {
// Test for IntValue
@SuppressWarnings({ "unchecked", "rawtypes" }) final TypeComparator<Record> doubleComp = new RecordComparatorFactory(new int[] { 0 }, new Class[] { DoubleValue.class }).createComparator();
final ChannelSelector<SerializationDelegate<Record>> oe1 = new OutputEmitter<Record>(ShipStrategyType.PARTITION_HASH, doubleComp);
final SerializationDelegate<Record> delegate = new SerializationDelegate<Record>(new RecordSerializerFactory().getSerializer());
;
Record rec = null;
try {
PipedInputStream pipedInput = new PipedInputStream(1024 * 1024);
DataInputView in = new DataInputViewStreamWrapper(pipedInput);
DataOutputView out = new DataOutputViewStreamWrapper(new PipedOutputStream(pipedInput));
rec = new Record(1);
rec.setField(0, new IntValue());
rec.write(out);
rec = new Record();
rec.read(in);
} catch (IOException e) {
fail("Test erroneous");
}
try {
delegate.setInstance(rec);
oe1.selectChannels(delegate, 100);
} catch (DeserializationException re) {
return;
}
Assert.fail("Expected a NullKeyFieldException.");
}
Aggregations