Search in sources :

Example 26 with OperatorState

use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.

the class WindowReaderTest method testReducingWindow.

@Test
public void testReducingWindow() throws Exception {
    WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).reduce(new ReduceSum()));
    OperatorState operatorState = getOperatorState(operator);
    KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.reduce(new ReduceSum(), new PassThroughReader<>(), Types.INT, new TimeWindow.Serializer(), Types.INT));
    List<Integer> list = readState(format);
    Assert.assertEquals(Arrays.asList(1, 1), list);
}
Also used : PassThroughReader(org.apache.flink.state.api.input.operator.window.PassThroughReader) Configuration(org.apache.flink.configuration.Configuration) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) ReduceSum(org.apache.flink.state.api.utils.ReduceSum) Test(org.junit.Test)

Example 27 with OperatorState

use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.

the class WindowReaderTest method testProcessReader.

@Test
public void testProcessReader() throws Exception {
    WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).process(mockProcessWindowFunction(), Types.INT));
    OperatorState operatorState = getOperatorState(operator);
    KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.process(new PassThroughReader<>(), Types.INT, new TimeWindow.Serializer(), Types.INT));
    List<Integer> list = readState(format);
    Assert.assertEquals(Arrays.asList(1, 1), list);
}
Also used : PassThroughReader(org.apache.flink.state.api.input.operator.window.PassThroughReader) Configuration(org.apache.flink.configuration.Configuration) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) Test(org.junit.Test)

Example 28 with OperatorState

use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.

the class OperatorCoordinatorSchedulerTest method createOperatorState.

private static OperatorState createOperatorState(OperatorID id, byte[] coordinatorState) {
    final OperatorState state = new OperatorState(id, 10, 16384);
    state.setCoordinatorState(new ByteStreamStateHandle("name", coordinatorState));
    return state;
}
Also used : ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState)

Example 29 with OperatorState

use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.

the class OperatorCoordinatorSchedulerTest method serializeAsCheckpointMetadata.

private static byte[] serializeAsCheckpointMetadata(OperatorID id, byte[] coordinatorState) throws IOException {
    final OperatorState state = createOperatorState(id, coordinatorState);
    final CheckpointMetadata metadata = new CheckpointMetadata(1337L, Collections.singletonList(state), Collections.emptyList());
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    Checkpoints.storeCheckpointMetadata(metadata, out);
    return out.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)

Example 30 with OperatorState

use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.

the class KeyedStateInputFormatTest method testMaxParallelismRespected.

@Test
public void testMaxParallelismRespected() throws Exception {
    OperatorID operatorID = OperatorIDGenerator.fromUid("uid");
    OperatorSubtaskState state = createOperatorSubtaskState(new StreamFlatMap<>(new StatefulFunction()));
    OperatorState operatorState = new OperatorState(operatorID, 1, 128);
    operatorState.putState(0, state);
    KeyedStateInputFormat<?, ?, ?> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), new KeyedStateReaderOperator<>(new ReaderFunction(), Types.INT));
    KeyGroupRangeInputSplit[] splits = format.createInputSplits(129);
    Assert.assertEquals("Failed to properly partition operator state into input splits", 128, splits.length);
}
Also used : KeyGroupRangeInputSplit(org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit) Configuration(org.apache.flink.configuration.Configuration) KeyedStateReaderFunction(org.apache.flink.state.api.functions.KeyedStateReaderFunction) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) Test(org.junit.Test)

Aggregations

OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)63 Test (org.junit.Test)22 Configuration (org.apache.flink.configuration.Configuration)17 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)14 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)14 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)14 CheckpointMetadata (org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)11 MasterState (org.apache.flink.runtime.checkpoint.MasterState)9 Random (java.util.Random)8 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)8 KeyGroupRangeInputSplit (org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit)7 ArrayList (java.util.ArrayList)6 KeyedStateReaderFunction (org.apache.flink.state.api.functions.KeyedStateReaderFunction)6 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)5 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)4 BroadcastStateInputFormat (org.apache.flink.state.api.input.BroadcastStateInputFormat)4 ListStateInputFormat (org.apache.flink.state.api.input.ListStateInputFormat)4 UnionStateInputFormat (org.apache.flink.state.api.input.UnionStateInputFormat)4 PassThroughReader (org.apache.flink.state.api.input.operator.window.PassThroughReader)4