Search in sources :

Example 6 with HashMapStateBackend

use of org.apache.flink.runtime.state.hashmap.HashMapStateBackend in project flink by apache.

the class StateBootstrapTransformationTest method testOperatorSpecificMaxParallelismRespected.

@Test
public void testOperatorSpecificMaxParallelismRespected() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(4);
    DataStream<Integer> input = env.fromElements(0);
    StateBootstrapTransformation<Integer> transformation = OperatorTransformation.bootstrapWith(input).setMaxParallelism(1).transform(new ExampleStateBootstrapFunction());
    int maxParallelism = transformation.getMaxParallelism(4);
    DataStream<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(OperatorIDGenerator.fromUid("uid"), new HashMapStateBackend(), new Path(), maxParallelism);
    Assert.assertEquals("The parallelism of a data set should be constrained my the savepoint max parallelism", 1, result.getParallelism());
}
Also used : Path(org.apache.flink.core.fs.Path) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) TaggedOperatorSubtaskState(org.apache.flink.state.api.output.TaggedOperatorSubtaskState) Test(org.junit.Test)

Example 7 with HashMapStateBackend

use of org.apache.flink.runtime.state.hashmap.HashMapStateBackend in project flink by apache.

the class StateBootstrapTransformationTest method testStreamConfig.

@Test
public void testStreamConfig() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<String> input = env.fromElements("");
    StateBootstrapTransformation<String> transformation = OperatorTransformation.bootstrapWith(input).keyBy(new CustomKeySelector()).transform(new ExampleKeyedStateBootstrapFunction());
    StreamConfig config = transformation.getConfig(OperatorIDGenerator.fromUid("uid"), new HashMapStateBackend(), new Configuration(), null);
    KeySelector selector = config.getStatePartitioner(0, Thread.currentThread().getContextClassLoader());
    Assert.assertEquals("Incorrect key selector forwarded to stream operator", CustomKeySelector.class, selector.getClass());
}
Also used : Configuration(org.apache.flink.configuration.Configuration) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) KeySelector(org.apache.flink.api.java.functions.KeySelector) Test(org.junit.Test)

Example 8 with HashMapStateBackend

use of org.apache.flink.runtime.state.hashmap.HashMapStateBackend in project flink by apache.

the class StateBootstrapTransformationTest method testDefaultParallelismRespectedWhenLessThanMaxParallelism.

@Test
public void testDefaultParallelismRespectedWhenLessThanMaxParallelism() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(4);
    DataStream<Integer> input = env.fromElements(0);
    StateBootstrapTransformation<Integer> transformation = OperatorTransformation.bootstrapWith(input).transform(new ExampleStateBootstrapFunction());
    int maxParallelism = transformation.getMaxParallelism(10);
    DataStream<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(OperatorIDGenerator.fromUid("uid"), new HashMapStateBackend(), new Path(), maxParallelism);
    Assert.assertEquals("The parallelism of a data set should not change when less than the max parallelism of the savepoint", env.getParallelism(), result.getParallelism());
}
Also used : Path(org.apache.flink.core.fs.Path) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) TaggedOperatorSubtaskState(org.apache.flink.state.api.output.TaggedOperatorSubtaskState) Test(org.junit.Test)

Example 9 with HashMapStateBackend

use of org.apache.flink.runtime.state.hashmap.HashMapStateBackend in project flink by apache.

the class SavepointReaderITTestBase method verifyListState.

private void verifyListState(String path, StreamExecutionEnvironment env) throws Exception {
    SavepointReader savepoint = SavepointReader.read(env, path, new HashMapStateBackend());
    List<Integer> listResult = JobResultRetriever.collect(readListState(savepoint));
    listResult.sort(Comparator.naturalOrder());
    Assert.assertEquals("Unexpected elements read from list state", SavepointSource.getElements(), listResult);
}
Also used : HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend)

Example 10 with HashMapStateBackend

use of org.apache.flink.runtime.state.hashmap.HashMapStateBackend in project flink by apache.

the class ChangelogStateBackendLoadingTest method testLoadingDefault.

@Test
public void testLoadingDefault() throws Exception {
    final StateBackend backend = StateBackendLoader.fromApplicationOrConfigOrDefault(null, TernaryBoolean.UNDEFINED, config(), cl, null);
    final CheckpointStorage storage = CheckpointStorageLoader.load(null, null, backend, config(), cl, null);
    assertTrue(backend instanceof HashMapStateBackend);
}
Also used : CheckpointStorage(org.apache.flink.runtime.state.CheckpointStorage) JobManagerCheckpointStorage(org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) EmbeddedRocksDBStateBackend(org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend) StateBackend(org.apache.flink.runtime.state.StateBackend) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) DelegatingStateBackend(org.apache.flink.runtime.state.delegate.DelegatingStateBackend) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) AbstractStateBackend(org.apache.flink.runtime.state.AbstractStateBackend) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) ConfigurableStateBackend(org.apache.flink.runtime.state.ConfigurableStateBackend) Test(org.junit.Test)

Aggregations

HashMapStateBackend (org.apache.flink.runtime.state.hashmap.HashMapStateBackend)22 Test (org.junit.Test)12 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)11 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)10 EmbeddedRocksDBStateBackend (org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend)7 Configuration (org.apache.flink.configuration.Configuration)6 Path (org.apache.flink.core.fs.Path)6 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 TaggedOperatorSubtaskState (org.apache.flink.state.api.output.TaggedOperatorSubtaskState)4 DelegatingStateBackend (org.apache.flink.runtime.state.delegate.DelegatingStateBackend)3 FsStateBackend (org.apache.flink.runtime.state.filesystem.FsStateBackend)3 MigrationTestUtils (org.apache.flink.test.checkpointing.utils.MigrationTestUtils)3 KeySelector (org.apache.flink.api.java.functions.KeySelector)2 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)2 AbstractKeyedStateBackend (org.apache.flink.runtime.state.AbstractKeyedStateBackend)2 AbstractStateBackend (org.apache.flink.runtime.state.AbstractStateBackend)2 ConfigurableStateBackend (org.apache.flink.runtime.state.ConfigurableStateBackend)2 OperatorStateBackend (org.apache.flink.runtime.state.OperatorStateBackend)2 StateBackend (org.apache.flink.runtime.state.StateBackend)2 HashMapStateBackendFactory (org.apache.flink.runtime.state.hashmap.HashMapStateBackendFactory)2