Search in sources :

Example 16 with MiniClusterWithClientResource

use of org.apache.flink.test.util.MiniClusterWithClientResource in project flink by apache.

the class UnalignedCheckpointTestBase method execute.

@Nullable
protected File execute(UnalignedSettings settings) throws Exception {
    final File checkpointDir = temp.newFolder();
    Configuration conf = settings.getConfiguration(checkpointDir);
    // Configure DFS DSTL for this test as it might produce too much GC pressure if
    // ChangelogStateBackend is used.
    // Doing it on cluster level unconditionally as randomization currently happens on the job
    // level (environment); while this factory can only be set on the cluster level.
    FsStateChangelogStorageFactory.configure(conf, temp.newFolder());
    final StreamGraph streamGraph = getStreamGraph(settings, conf);
    final int requiredSlots = streamGraph.getStreamNodes().stream().mapToInt(node -> node.getParallelism()).reduce(0, settings.channelType.slotSharing ? Integer::max : Integer::sum);
    int numberTaskmanagers = settings.channelType.slotsToTaskManagers.apply(requiredSlots);
    final int slotsPerTM = (requiredSlots + numberTaskmanagers - 1) / numberTaskmanagers;
    final MiniClusterWithClientResource miniCluster = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(conf).setNumberTaskManagers(numberTaskmanagers).setNumberSlotsPerTaskManager(slotsPerTM).build());
    miniCluster.before();
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
    settings.configure(env);
    try {
        // print the test parameters to help debugging when the case is stuck
        System.out.println("Starting " + getClass().getCanonicalName() + "#" + name.getMethodName() + ".");
        waitForCleanShutdown();
        final CompletableFuture<JobSubmissionResult> result = miniCluster.getMiniCluster().submitJob(streamGraph.getJobGraph());
        checkCounters(miniCluster.getMiniCluster().requestJobResult(result.get().getJobID()).get().toJobExecutionResult(getClass().getClassLoader()));
        System.out.println("Finished " + getClass().getCanonicalName() + "#" + name.getMethodName() + ".");
    } catch (Exception e) {
        if (!ExceptionUtils.findThrowable(e, TestException.class).isPresent()) {
            throw e;
        }
    } finally {
        miniCluster.after();
    }
    if (settings.generateCheckpoint) {
        return TestUtils.getMostRecentCompletedCheckpoint(checkpointDir);
    }
    return null;
}
Also used : Deadline(org.apache.flink.api.common.time.Deadline) PlatformDependent(org.apache.flink.shaded.netty4.io.netty.util.internal.PlatformDependent) LoggerFactory(org.slf4j.LoggerFactory) ExceptionUtils(org.apache.flink.util.ExceptionUtils) InputStatus(org.apache.flink.core.io.InputStatus) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) MemorySize(org.apache.flink.configuration.MemorySize) ByteBuffer(java.nio.ByteBuffer) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) ListState(org.apache.flink.api.common.state.ListState) CheckpointListener(org.apache.flink.api.common.state.CheckpointListener) SplitEnumerator(org.apache.flink.api.connector.source.SplitEnumerator) Duration(java.time.Duration) Map(java.util.Map) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) TestLogger(org.apache.flink.util.TestLogger) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) FsStateChangelogStorageFactory(org.apache.flink.changelog.fs.FsStateChangelogStorageFactory) ReaderOutput(org.apache.flink.api.connector.source.ReaderOutput) SourceReaderContext(org.apache.flink.api.connector.source.SourceReaderContext) AkkaOptions(org.apache.flink.configuration.AkkaOptions) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) SourceEvent(org.apache.flink.api.connector.source.SourceEvent) SplitEnumeratorContext(org.apache.flink.api.connector.source.SplitEnumeratorContext) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) TestUtils(org.apache.flink.test.util.TestUtils) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) ErrorCollector(org.junit.rules.ErrorCollector) CheckpointingOptions(org.apache.flink.configuration.CheckpointingOptions) RichSinkFunction(org.apache.flink.streaming.api.functions.sink.RichSinkFunction) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) FilterFunction(org.apache.flink.api.common.functions.FilterFunction) List(java.util.List) SimpleVersionedSerializer(org.apache.flink.core.io.SimpleVersionedSerializer) Optional(java.util.Optional) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) Source(org.apache.flink.api.connector.source.Source) Iterables.getOnlyElement(org.apache.flink.shaded.guava30.com.google.common.collect.Iterables.getOnlyElement) Time(org.apache.flink.api.common.time.Time) Boundedness(org.apache.flink.api.connector.source.Boundedness) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) IntStream(java.util.stream.IntStream) LongCounter(org.apache.flink.api.common.accumulators.LongCounter) CHECKPOINTING_TIMEOUT(org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions.CHECKPOINTING_TIMEOUT) SavepointConfigOptions(org.apache.flink.runtime.jobgraph.SavepointConfigOptions) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RestartStrategies(org.apache.flink.api.common.restartstrategy.RestartStrategies) RichCoFlatMapFunction(org.apache.flink.streaming.api.functions.co.RichCoFlatMapFunction) Function(java.util.function.Function) SplitsAssignment(org.apache.flink.api.connector.source.SplitsAssignment) ArrayList(java.util.ArrayList) NettyShuffleEnvironmentOptions(org.apache.flink.configuration.NettyShuffleEnvironmentOptions) Partitioner(org.apache.flink.api.common.functions.Partitioner) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) FailsWithAdaptiveScheduler(org.apache.flink.testutils.junit.FailsWithAdaptiveScheduler) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) Collector(org.apache.flink.util.Collector) TestName(org.junit.rules.TestName) IntCounter(org.apache.flink.api.common.accumulators.IntCounter) Iterables(org.apache.flink.shaded.guava30.com.google.common.collect.Iterables) JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) Nullable(javax.annotation.Nullable) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) SourceSplit(org.apache.flink.api.connector.source.SourceSplit) Logger(org.slf4j.Logger) SourceReader(org.apache.flink.api.connector.source.SourceReader) Configuration(org.apache.flink.configuration.Configuration) IOException(java.io.IOException) File(java.io.File) Rule(org.junit.Rule) Comparator(java.util.Comparator) TemporaryFolder(org.junit.rules.TemporaryFolder) StateBackendOptions(org.apache.flink.configuration.StateBackendOptions) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) IOException(java.io.IOException) JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 17 with MiniClusterWithClientResource

use of org.apache.flink.test.util.MiniClusterWithClientResource in project flink by apache.

the class UnalignedCheckpointCompatibilityITCase method setupMiniCluster.

@BeforeClass
public static void setupMiniCluster() throws Exception {
    File folder = temporaryFolder.getRoot();
    final Configuration conf = new Configuration();
    conf.set(CHECKPOINTS_DIRECTORY, folder.toURI().toString());
    // prevent deletion of checkpoint files while it's being checked and used
    conf.set(MAX_RETAINED_CHECKPOINTS, Integer.MAX_VALUE);
    miniCluster = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(conf).build());
    miniCluster.before();
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 18 with MiniClusterWithClientResource

use of org.apache.flink.test.util.MiniClusterWithClientResource in project flink by apache.

the class JdbcExactlyOnceSinkE2eTest method before.

@Before
public void before() throws Exception {
    Configuration configuration = new Configuration();
    // single failover region to allow checkpointing even after some sources have finished and
    // restart all tasks if at least one fails
    configuration.set(EXECUTION_FAILOVER_STRATEGY, "full");
    // cancel tasks eagerly to reduce the risk of running out of memory with many restarts
    configuration.set(TASK_CANCELLATION_TIMEOUT, TASK_CANCELLATION_TIMEOUT_MS);
    configuration.set(CHECKPOINTING_TIMEOUT, Duration.ofMillis(CHECKPOINT_TIMEOUT_MS));
    cluster = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(configuration).setNumberTaskManagers(dbEnv.getParallelism()).build());
    cluster.before();
    dbEnv.start();
    super.before();
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Before(org.junit.Before)

Example 19 with MiniClusterWithClientResource

use of org.apache.flink.test.util.MiniClusterWithClientResource in project flink by apache.

the class HAQueryableStateRocksDBBackendITCase method setup.

@BeforeClass
public static void setup() throws Exception {
    zkServer = new TestingServer();
    // we have to manage this manually because we have to create the ZooKeeper server
    // ahead of this
    miniClusterResource = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(getConfig()).setNumberTaskManagers(NUM_TMS).setNumberSlotsPerTaskManager(NUM_SLOTS_PER_TM).build());
    miniClusterResource.before();
    client = new QueryableStateClient("localhost", QS_PROXY_PORT_RANGE_START);
    clusterClient = miniClusterResource.getClusterClient();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) QueryableStateClient(org.apache.flink.queryablestate.client.QueryableStateClient) BeforeClass(org.junit.BeforeClass)

Example 20 with MiniClusterWithClientResource

use of org.apache.flink.test.util.MiniClusterWithClientResource in project flink by apache.

the class HAQueryableStateFsBackendITCase method setup.

@BeforeClass
public static void setup() throws Exception {
    zkServer = new TestingServer();
    // we have to manage this manually because we have to create the ZooKeeper server
    // ahead of this
    miniClusterResource = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(getConfig()).setNumberTaskManagers(NUM_TMS).setNumberSlotsPerTaskManager(NUM_SLOTS_PER_TM).build());
    miniClusterResource.before();
    client = new QueryableStateClient("localhost", QS_PROXY_PORT_RANGE_START);
    clusterClient = miniClusterResource.getClusterClient();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) QueryableStateClient(org.apache.flink.queryablestate.client.QueryableStateClient) BeforeClass(org.junit.BeforeClass)

Aggregations

MiniClusterWithClientResource (org.apache.flink.test.util.MiniClusterWithClientResource)34 MiniClusterResourceConfiguration (org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration)26 Configuration (org.apache.flink.configuration.Configuration)24 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)14 Before (org.junit.Before)13 Test (org.junit.Test)13 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)12 JobID (org.apache.flink.api.common.JobID)9 File (java.io.File)8 ExecutionException (java.util.concurrent.ExecutionException)7 JobExecutionException (org.apache.flink.runtime.client.JobExecutionException)7 IOException (java.io.IOException)6 Optional (java.util.Optional)6 RichMapFunction (org.apache.flink.api.common.functions.RichMapFunction)6 List (java.util.List)5 CheckpointingOptions (org.apache.flink.configuration.CheckpointingOptions)5 MemorySize (org.apache.flink.configuration.MemorySize)5 StateBackendOptions (org.apache.flink.configuration.StateBackendOptions)5 FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)5 StreamGraph (org.apache.flink.streaming.api.graph.StreamGraph)5