use of org.apache.flink.runtime.state.VoidNamespace in project flink by apache.
the class LatencyTrackingAggregatingStateTest method testLatencyTrackingAggregatingState.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testLatencyTrackingAggregatingState() throws Exception {
AbstractKeyedStateBackend<Integer> keyedBackend = createKeyedBackend(getKeySerializer());
try {
LatencyTrackingAggregatingState<Integer, VoidNamespace, Long, Long, Long> latencyTrackingState = (LatencyTrackingAggregatingState) createLatencyTrackingState(keyedBackend, getStateDescriptor());
latencyTrackingState.setCurrentNamespace(VoidNamespace.INSTANCE);
LatencyTrackingAggregatingState.AggregatingStateLatencyMetrics latencyTrackingStateMetric = latencyTrackingState.getLatencyTrackingStateMetric();
assertEquals(0, latencyTrackingStateMetric.getAddCount());
assertEquals(0, latencyTrackingStateMetric.getGetCount());
assertEquals(0, latencyTrackingStateMetric.getMergeNamespaceCount());
setCurrentKey(keyedBackend);
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int index = 1; index <= SAMPLE_INTERVAL; index++) {
int expectedResult = index == SAMPLE_INTERVAL ? 0 : index;
latencyTrackingState.add(random.nextLong());
assertEquals(expectedResult, latencyTrackingStateMetric.getAddCount());
latencyTrackingState.get();
assertEquals(expectedResult, latencyTrackingStateMetric.getGetCount());
latencyTrackingState.mergeNamespaces(VoidNamespace.INSTANCE, Collections.emptyList());
assertEquals(expectedResult, latencyTrackingStateMetric.getMergeNamespaceCount());
}
} finally {
if (keyedBackend != null) {
keyedBackend.close();
keyedBackend.dispose();
}
}
}
use of org.apache.flink.runtime.state.VoidNamespace in project flink by apache.
the class LatencyTrackingMapStateTest method testLatencyTrackingMapState.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testLatencyTrackingMapState() throws Exception {
AbstractKeyedStateBackend<Integer> keyedBackend = createKeyedBackend(getKeySerializer());
try {
LatencyTrackingMapState<Integer, VoidNamespace, Long, Double> latencyTrackingState = (LatencyTrackingMapState) createLatencyTrackingState(keyedBackend, getStateDescriptor());
latencyTrackingState.setCurrentNamespace(VoidNamespace.INSTANCE);
LatencyTrackingMapState.MapStateLatencyMetrics latencyTrackingStateMetric = latencyTrackingState.getLatencyTrackingStateMetric();
assertEquals(0, latencyTrackingStateMetric.getContainsCount());
assertEquals(0, latencyTrackingStateMetric.getEntriesInitCount());
assertEquals(0, latencyTrackingStateMetric.getGetCount());
assertEquals(0, latencyTrackingStateMetric.getIsEmptyCount());
assertEquals(0, latencyTrackingStateMetric.getIteratorInitCount());
assertEquals(0, latencyTrackingStateMetric.getIteratorHasNextCount());
assertEquals(0, latencyTrackingStateMetric.getIteratorNextCount());
assertEquals(0, latencyTrackingStateMetric.getKeysInitCount());
assertEquals(0, latencyTrackingStateMetric.getValuesInitCount());
assertEquals(0, latencyTrackingStateMetric.getIteratorRemoveCount());
assertEquals(0, latencyTrackingStateMetric.getPutAllCount());
assertEquals(0, latencyTrackingStateMetric.getPutCount());
assertEquals(0, latencyTrackingStateMetric.getRemoveCount());
setCurrentKey(keyedBackend);
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int index = 1; index <= SAMPLE_INTERVAL; index++) {
int expectedResult = index == SAMPLE_INTERVAL ? 0 : index;
latencyTrackingState.put(random.nextLong(), random.nextDouble());
assertEquals(expectedResult, latencyTrackingStateMetric.getPutCount());
latencyTrackingState.putAll(Collections.singletonMap(random.nextLong(), random.nextDouble()));
assertEquals(expectedResult, latencyTrackingStateMetric.getPutAllCount());
latencyTrackingState.get(random.nextLong());
assertEquals(expectedResult, latencyTrackingStateMetric.getGetCount());
latencyTrackingState.remove(random.nextLong());
assertEquals(expectedResult, latencyTrackingStateMetric.getRemoveCount());
latencyTrackingState.contains(random.nextLong());
assertEquals(expectedResult, latencyTrackingStateMetric.getContainsCount());
latencyTrackingState.isEmpty();
assertEquals(expectedResult, latencyTrackingStateMetric.getIsEmptyCount());
latencyTrackingState.entries();
assertEquals(expectedResult, latencyTrackingStateMetric.getEntriesInitCount());
latencyTrackingState.keys();
assertEquals(expectedResult, latencyTrackingStateMetric.getKeysInitCount());
latencyTrackingState.values();
assertEquals(expectedResult, latencyTrackingStateMetric.getValuesInitCount());
latencyTrackingState.iterator();
assertEquals(expectedResult, latencyTrackingStateMetric.getIteratorInitCount());
}
} finally {
if (keyedBackend != null) {
keyedBackend.close();
keyedBackend.dispose();
}
}
}
use of org.apache.flink.runtime.state.VoidNamespace in project flink by apache.
the class LegacyKeyedCoProcessOperator method open.
@Override
public void open() throws Exception {
super.open();
collector = new TimestampedCollector<>(output);
InternalTimerService<VoidNamespace> internalTimerService = getInternalTimerService("user-timers", VoidNamespaceSerializer.INSTANCE, this);
TimerService timerService = new SimpleTimerService(internalTimerService);
context = new ContextImpl<>(userFunction, timerService);
onTimerContext = new OnTimerContextImpl<>(userFunction, timerService);
}
use of org.apache.flink.runtime.state.VoidNamespace in project flink by apache.
the class RocksDBAggregatingStateTest method testAddAndGet.
// ------------------------------------------------------------------------
@Test
public void testAddAndGet() throws Exception {
final AggregatingStateDescriptor<Long, MutableLong, Long> stateDescr = new AggregatingStateDescriptor<>("my-state", new AddingFunction(), MutableLong.class);
stateDescr.initializeSerializerUnlessSet(new ExecutionConfig());
final RocksDBStateBackend backend = new RocksDBStateBackend(tmp.newFolder().toURI());
backend.setDbStoragePath(tmp.newFolder().getAbsolutePath());
final RocksDBKeyedStateBackend<String> keyedBackend = createKeyedBackend(backend);
try {
InternalAggregatingState<VoidNamespace, Long, Long> state = keyedBackend.createAggregatingState(VoidNamespaceSerializer.INSTANCE, stateDescr);
state.setCurrentNamespace(VoidNamespace.INSTANCE);
keyedBackend.setCurrentKey("abc");
assertNull(state.get());
keyedBackend.setCurrentKey("def");
assertNull(state.get());
state.add(17L);
state.add(11L);
assertEquals(28L, state.get().longValue());
keyedBackend.setCurrentKey("abc");
assertNull(state.get());
keyedBackend.setCurrentKey("g");
assertNull(state.get());
state.add(1L);
state.add(2L);
keyedBackend.setCurrentKey("def");
assertEquals(28L, state.get().longValue());
state.clear();
assertNull(state.get());
keyedBackend.setCurrentKey("g");
state.add(3L);
state.add(2L);
state.add(1L);
keyedBackend.setCurrentKey("def");
assertNull(state.get());
keyedBackend.setCurrentKey("g");
assertEquals(9L, state.get().longValue());
} finally {
keyedBackend.close();
keyedBackend.dispose();
}
}
use of org.apache.flink.runtime.state.VoidNamespace in project flink by apache.
the class RocksDBListStateTest method testAddAndGet.
// ------------------------------------------------------------------------
@Test
public void testAddAndGet() throws Exception {
final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);
stateDescr.initializeSerializerUnlessSet(new ExecutionConfig());
final RocksDBStateBackend backend = new RocksDBStateBackend(tmp.newFolder().toURI());
backend.setDbStoragePath(tmp.newFolder().getAbsolutePath());
final RocksDBKeyedStateBackend<String> keyedBackend = createKeyedBackend(backend);
try {
InternalListState<VoidNamespace, Long> state = keyedBackend.createListState(VoidNamespaceSerializer.INSTANCE, stateDescr);
state.setCurrentNamespace(VoidNamespace.INSTANCE);
keyedBackend.setCurrentKey("abc");
assertNull(state.get());
keyedBackend.setCurrentKey("def");
assertNull(state.get());
state.add(17L);
state.add(11L);
assertEquals(asList(17L, 11L), state.get());
keyedBackend.setCurrentKey("abc");
assertNull(state.get());
keyedBackend.setCurrentKey("g");
assertNull(state.get());
state.add(1L);
state.add(2L);
keyedBackend.setCurrentKey("def");
assertEquals(asList(17L, 11L), state.get());
state.clear();
assertNull(state.get());
keyedBackend.setCurrentKey("g");
state.add(3L);
state.add(2L);
state.add(1L);
keyedBackend.setCurrentKey("def");
assertNull(state.get());
keyedBackend.setCurrentKey("g");
assertEquals(asList(1L, 2L, 3L, 2L, 1L), state.get());
} finally {
keyedBackend.close();
keyedBackend.dispose();
}
}
Aggregations