Search in sources :

Example 31 with OperatorState

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

the class KeyedStateInputFormatTest method testReadMultipleOutputPerKey.

@Test
public void testReadMultipleOutputPerKey() 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 split = format.createInputSplits(1)[0];
    KeyedStateReaderFunction<Integer, Integer> userFunction = new DoubleReaderFunction();
    List<Integer> data = readInputSplit(split, userFunction);
    Assert.assertEquals("Incorrect data read from input split", Arrays.asList(1, 1, 2, 2, 3, 3), data);
}
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)

Example 32 with OperatorState

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

the class StreamOperatorContextBuilderTest method testStateBackendLoading.

@Test(expected = CustomStateBackendFactory.ExpectedException.class)
public void testStateBackendLoading() throws Exception {
    Configuration configuration = new Configuration();
    configuration.set(StateBackendOptions.STATE_BACKEND, CustomStateBackendFactory.class.getCanonicalName());
    StreamOperatorContextBuilder builder = new StreamOperatorContextBuilder(new MockStreamingRuntimeContext(true, 1, 0), configuration, new OperatorState(new OperatorID(), 1, 128), new PrioritizedOperatorSubtaskStateInputSplit() {

        @Override
        public PrioritizedOperatorSubtaskState getPrioritizedOperatorSubtaskState() {
            return PrioritizedOperatorSubtaskState.emptyNotRestored();
        }

        @Override
        public int getSplitNumber() {
            return 0;
        }
    }, new CloseableRegistry(), null);
    builder.build(LOG);
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) PrioritizedOperatorSubtaskState(org.apache.flink.runtime.checkpoint.PrioritizedOperatorSubtaskState) CustomStateBackendFactory(org.apache.flink.state.api.utils.CustomStateBackendFactory) PrioritizedOperatorSubtaskStateInputSplit(org.apache.flink.state.api.input.splits.PrioritizedOperatorSubtaskStateInputSplit) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) Test(org.junit.Test)

Example 33 with OperatorState

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

the class SavepointTest method testExistingSavepointEnforceUniqueUIDsWithOldSavepoint.

@Test(expected = IllegalArgumentException.class)
public void testExistingSavepointEnforceUniqueUIDsWithOldSavepoint() throws IOException {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(10);
    DataSource<Integer> input = env.fromElements(0);
    BootstrapTransformation<Integer> transformation = OperatorTransformation.bootstrapWith(input).transform(new ExampleStateBootstrapFunction());
    Collection<OperatorState> operatorStates = Collections.singletonList(new OperatorState(OperatorIDGenerator.fromUid(UID), 1, 4));
    SavepointMetadata metadata = new SavepointMetadata(4, Collections.emptyList(), operatorStates);
    new ExistingSavepoint(env, metadata, new MemoryStateBackend()).withOperator(UID, transformation).write("");
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) SavepointMetadata(org.apache.flink.state.api.runtime.metadata.SavepointMetadata) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) Test(org.junit.Test)

Example 34 with OperatorState

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

the class SavepointTest method testExistingSavepointEnforceUniqueUIDs.

@Test(expected = IllegalArgumentException.class)
public void testExistingSavepointEnforceUniqueUIDs() throws IOException {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(10);
    DataSource<Integer> input = env.fromElements(0);
    BootstrapTransformation<Integer> transformation = OperatorTransformation.bootstrapWith(input).transform(new ExampleStateBootstrapFunction());
    Collection<OperatorState> operatorStates = Collections.singletonList(new OperatorState(OperatorIDGenerator.fromUid(UID), 1, 4));
    SavepointMetadata metadata = new SavepointMetadata(4, Collections.emptyList(), operatorStates);
    new ExistingSavepoint(env, metadata, new MemoryStateBackend()).withOperator(UID, transformation).withOperator(UID, transformation);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) SavepointMetadata(org.apache.flink.state.api.runtime.metadata.SavepointMetadata) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) Test(org.junit.Test)

Example 35 with OperatorState

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

the class WindowReaderTest method testAggregateWindow.

@Test
public void testAggregateWindow() throws Exception {
    WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).aggregate(new AggregateSum()));
    OperatorState operatorState = getOperatorState(operator);
    KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.aggregate(new AggregateSum(), 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) AggregateSum(org.apache.flink.state.api.utils.AggregateSum) 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