use of org.apache.flink.core.memory.ByteArrayInputStreamWithPos in project flink by apache.
the class SerializationProxiesTest method testOperatorStateMetaInfoSerialization.
@Test
public void testOperatorStateMetaInfoSerialization() throws Exception {
String name = "test";
TypeSerializer<?> stateSerializer = DoubleSerializer.INSTANCE;
OperatorBackendSerializationProxy.StateMetaInfo<?> metaInfo = new OperatorBackendSerializationProxy.StateMetaInfo<>(name, stateSerializer, OperatorStateHandle.Mode.BROADCAST);
byte[] serialized;
try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
metaInfo.write(new DataOutputViewStreamWrapper(out));
serialized = out.toByteArray();
}
metaInfo = new OperatorBackendSerializationProxy.StateMetaInfo<>(Thread.currentThread().getContextClassLoader());
try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
metaInfo.read(new DataInputViewStreamWrapper(in));
}
Assert.assertEquals(name, metaInfo.getName());
}
use of org.apache.flink.core.memory.ByteArrayInputStreamWithPos in project flink by apache.
the class SerializationProxiesTest method testOperatorBackendSerializationProxyRoundtrip.
@Test
public void testOperatorBackendSerializationProxyRoundtrip() throws Exception {
TypeSerializer<?> stateSerializer = DoubleSerializer.INSTANCE;
List<OperatorBackendSerializationProxy.StateMetaInfo<?>> stateMetaInfoList = new ArrayList<>();
stateMetaInfoList.add(new OperatorBackendSerializationProxy.StateMetaInfo<>("a", stateSerializer, OperatorStateHandle.Mode.SPLIT_DISTRIBUTE));
stateMetaInfoList.add(new OperatorBackendSerializationProxy.StateMetaInfo<>("b", stateSerializer, OperatorStateHandle.Mode.SPLIT_DISTRIBUTE));
stateMetaInfoList.add(new OperatorBackendSerializationProxy.StateMetaInfo<>("c", stateSerializer, OperatorStateHandle.Mode.BROADCAST));
OperatorBackendSerializationProxy serializationProxy = new OperatorBackendSerializationProxy(stateMetaInfoList);
byte[] serialized;
try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
serializationProxy.write(new DataOutputViewStreamWrapper(out));
serialized = out.toByteArray();
}
serializationProxy = new OperatorBackendSerializationProxy(Thread.currentThread().getContextClassLoader());
try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
serializationProxy.read(new DataInputViewStreamWrapper(in));
}
Assert.assertEquals(stateMetaInfoList, serializationProxy.getNamedStateSerializationProxies());
}
use of org.apache.flink.core.memory.ByteArrayInputStreamWithPos in project flink by apache.
the class SerializationProxiesTest method testKeyedBackendSerializationProxyRoundtrip.
@Test
public void testKeyedBackendSerializationProxyRoundtrip() throws Exception {
TypeSerializer<?> keySerializer = IntSerializer.INSTANCE;
TypeSerializer<?> namespaceSerializer = LongSerializer.INSTANCE;
TypeSerializer<?> stateSerializer = DoubleSerializer.INSTANCE;
List<KeyedBackendSerializationProxy.StateMetaInfo<?, ?>> stateMetaInfoList = new ArrayList<>();
stateMetaInfoList.add(new KeyedBackendSerializationProxy.StateMetaInfo<>(StateDescriptor.Type.VALUE, "a", namespaceSerializer, stateSerializer));
stateMetaInfoList.add(new KeyedBackendSerializationProxy.StateMetaInfo<>(StateDescriptor.Type.VALUE, "b", namespaceSerializer, stateSerializer));
stateMetaInfoList.add(new KeyedBackendSerializationProxy.StateMetaInfo<>(StateDescriptor.Type.VALUE, "c", namespaceSerializer, stateSerializer));
KeyedBackendSerializationProxy serializationProxy = new KeyedBackendSerializationProxy(keySerializer, stateMetaInfoList);
byte[] serialized;
try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
serializationProxy.write(new DataOutputViewStreamWrapper(out));
serialized = out.toByteArray();
}
serializationProxy = new KeyedBackendSerializationProxy(Thread.currentThread().getContextClassLoader());
try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
serializationProxy.read(new DataInputViewStreamWrapper(in));
}
Assert.assertEquals(keySerializer, serializationProxy.getKeySerializerProxy().getTypeSerializer());
Assert.assertEquals(stateMetaInfoList, serializationProxy.getNamedStateSerializationProxies());
}
use of org.apache.flink.core.memory.ByteArrayInputStreamWithPos in project flink by apache.
the class StateTableSnapshotCompatibilityTest method restoreStateTableFromSnapshot.
private static <K, N, S> void restoreStateTableFromSnapshot(StateTable<K, N, S> stateTable, StateTableSnapshot snapshot, KeyGroupRange keyGroupRange) throws IOException {
final ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos(1024 * 1024);
final DataOutputViewStreamWrapper dov = new DataOutputViewStreamWrapper(out);
for (Integer keyGroup : keyGroupRange) {
snapshot.writeMappingsInKeyGroup(dov, keyGroup);
}
final ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(out.getBuf());
final DataInputViewStreamWrapper div = new DataInputViewStreamWrapper(in);
final StateTableByKeyGroupReader keyGroupReader = StateTableByKeyGroupReaders.readerForVersion(stateTable, KeyedBackendSerializationProxy.VERSION);
for (Integer keyGroup : keyGroupRange) {
keyGroupReader.readMappingsInKeyGroup(div, keyGroup);
}
}
Aggregations