Search in sources :

Example 16 with VoidNamespace

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();
        }
    }
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) Test(org.junit.Test)

Example 17 with VoidNamespace

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();
        }
    }
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) Test(org.junit.Test)

Example 18 with VoidNamespace

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);
}
Also used : SimpleTimerService(org.apache.flink.streaming.api.SimpleTimerService) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) TimerService(org.apache.flink.streaming.api.TimerService) SimpleTimerService(org.apache.flink.streaming.api.SimpleTimerService) InternalTimerService(org.apache.flink.streaming.api.operators.InternalTimerService)

Example 19 with VoidNamespace

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();
    }
}
Also used : AggregatingStateDescriptor(org.apache.flink.api.common.state.AggregatingStateDescriptor) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 20 with VoidNamespace

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();
    }
}
Also used : ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Aggregations

VoidNamespace (org.apache.flink.runtime.state.VoidNamespace)31 Test (org.junit.Test)21 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)11 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)10 ArrayList (java.util.ArrayList)9 SimpleTimerService (org.apache.flink.streaming.api.SimpleTimerService)8 JobID (org.apache.flink.api.common.JobID)6 VoidNamespaceSerializer (org.apache.flink.runtime.state.VoidNamespaceSerializer)6 InternalTimerService (org.apache.flink.streaming.api.operators.InternalTimerService)6 TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)6 List (java.util.List)5 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)5 TimerService (org.apache.flink.streaming.api.TimerService)5 Arrays (java.util.Arrays)4 TaskKvStateRegistry (org.apache.flink.runtime.query.TaskKvStateRegistry)4 Watermark (org.apache.flink.streaming.api.watermark.Watermark)4 Assert (org.junit.Assert)4 Collections (java.util.Collections)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 BiConsumer (java.util.function.BiConsumer)3