use of org.apache.flink.runtime.state.StateEntry in project flink by apache.
the class CopyOnWriteSkipListStateMapTestUtils method verifySnapshotWithoutTransform.
static <K, N, S> void verifySnapshotWithoutTransform(Map<N, Map<K, S>> referenceStates, @Nonnull CopyOnWriteSkipListStateMapSnapshot<K, N, S> snapshot, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, TypeSerializer<S> stateSerializer, SnapshotVerificationMode verificationMode) throws IOException {
ByteArrayOutputStreamWithPos outputStream = new ByteArrayOutputStreamWithPos();
DataOutputView outputView = new DataOutputViewStreamWrapper(outputStream);
if (verificationMode == SnapshotVerificationMode.ITERATOR) {
Iterator<StateEntry<K, N, S>> iterator = snapshot.getIterator(keySerializer, namespaceSerializer, stateSerializer, null);
assertThat(() -> iterator, containsInAnyOrder(toMatchers(referenceStates)));
} else {
snapshot.writeState(keySerializer, namespaceSerializer, stateSerializer, outputView, null);
Map<N, Map<K, S>> actualStates = readStateFromSnapshot(outputStream.toByteArray(), keySerializer, namespaceSerializer, stateSerializer);
assertEquals(referenceStates, actualStates);
}
}
use of org.apache.flink.runtime.state.StateEntry in project flink by apache.
the class CopyOnWriteSkipListStateMapTestUtils method verifySnapshotWithTransform.
static <K, N, S> void verifySnapshotWithTransform(@Nonnull Map<N, Map<K, S>> referenceStates, @Nonnull CopyOnWriteSkipListStateMapSnapshot<K, N, S> snapshot, StateSnapshotTransformer<S> transformer, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, TypeSerializer<S> stateSerializer, SnapshotVerificationMode verificationMode) throws IOException {
ByteArrayOutputStreamWithPos outputStream = new ByteArrayOutputStreamWithPos();
DataOutputView outputView = new DataOutputViewStreamWrapper(outputStream);
Map<N, Map<K, S>> transformedStates = new HashMap<>();
for (Map.Entry<N, Map<K, S>> namespaceEntry : referenceStates.entrySet()) {
for (Map.Entry<K, S> keyEntry : namespaceEntry.getValue().entrySet()) {
S state = transformer.filterOrTransform(keyEntry.getValue());
if (state != null) {
transformedStates.computeIfAbsent(namespaceEntry.getKey(), (none) -> new HashMap<>()).put(keyEntry.getKey(), state);
}
}
}
if (verificationMode == SnapshotVerificationMode.SERIALIZED) {
snapshot.writeState(keySerializer, namespaceSerializer, stateSerializer, outputView, transformer);
Map<N, Map<K, S>> actualStates = readStateFromSnapshot(outputStream.toByteArray(), keySerializer, namespaceSerializer, stateSerializer);
assertEquals(transformedStates, actualStates);
} else {
Iterator<StateEntry<K, N, S>> iterator = snapshot.getIterator(keySerializer, namespaceSerializer, stateSerializer, null);
assertThat(() -> iterator, containsInAnyOrder(toMatchers(referenceStates)));
}
}
Aggregations