Search in sources :

Example 11 with DirectScheduledExecutorService

use of org.apache.flink.runtime.testutils.DirectScheduledExecutorService in project flink by apache.

the class BatchingStateChangeUploaderTest method testClose.

@Test
public void testClose() throws Exception {
    TestingStateChangeUploader probe = new TestingStateChangeUploader();
    DirectScheduledExecutorService scheduler = new DirectScheduledExecutorService();
    DirectScheduledExecutorService retryScheduler = new DirectScheduledExecutorService();
    new BatchingStateChangeUploader(0, 0, MAX_BYTES_IN_FLIGHT, RetryPolicy.NONE, probe, scheduler, new RetryingExecutor(retryScheduler, createUnregisteredChangelogStorageMetricGroup().getAttemptsPerUpload()), createUnregisteredChangelogStorageMetricGroup()).close();
    assertTrue(probe.isClosed());
    assertTrue(scheduler.isShutdown());
    assertTrue(retryScheduler.isShutdown());
}
Also used : DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) Test(org.junit.Test)

Example 12 with DirectScheduledExecutorService

use of org.apache.flink.runtime.testutils.DirectScheduledExecutorService in project flink by apache.

the class BatchingStateChangeUploaderTest method testRetry.

/**
 * Test integration with {@link RetryingExecutor}.
 */
@Test
public void testRetry() throws Exception {
    final int maxAttempts = 5;
    try (BatchingStateChangeUploader store = new BatchingStateChangeUploader(0, 0, MAX_BYTES_IN_FLIGHT, RetryPolicy.fixed(maxAttempts, 0, 0), new TestingStateChangeUploader() {

        final AtomicInteger currentAttempt = new AtomicInteger(0);

        @Override
        public void upload(UploadTask uploadTask) throws IOException {
            if (currentAttempt.getAndIncrement() < maxAttempts - 1) {
                throw new IOException();
            } else {
                uploadTask.complete(emptyList());
            }
        }
    }, new DirectScheduledExecutorService(), new RetryingExecutor(new DirectScheduledExecutorService(), createUnregisteredChangelogStorageMetricGroup().getAttemptsPerUpload()), createUnregisteredChangelogStorageMetricGroup())) {
        CompletableFuture<List<UploadResult>> completionFuture = new CompletableFuture<>();
        store.upload(new UploadTask(getChanges(4), completionFuture::complete, (unused, throwable) -> completionFuture.completeExceptionally(throwable)));
        completionFuture.get();
    }
}
Also used : BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) Arrays(java.util.Arrays) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ExceptionUtils.rethrow(org.apache.flink.util.ExceptionUtils.rethrow) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ExceptionUtils.findThrowable(org.apache.flink.util.ExceptionUtils.findThrowable) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assert.fail(org.junit.Assert.fail) UnregisteredChangelogStorageMetricGroup.createUnregisteredChangelogStorageMetricGroup(org.apache.flink.changelog.fs.UnregisteredChangelogStorageMetricGroup.createUnregisteredChangelogStorageMetricGroup) StateChange(org.apache.flink.runtime.state.changelog.StateChange) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) UploadTask(org.apache.flink.changelog.fs.StateChangeUploader.UploadTask) UUID(java.util.UUID) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Collectors(java.util.stream.Collectors) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) SequenceNumber(org.apache.flink.runtime.state.changelog.SequenceNumber) Assert.assertEquals(org.junit.Assert.assertEquals) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) IOException(java.io.IOException) UploadTask(org.apache.flink.changelog.fs.StateChangeUploader.UploadTask) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Test(org.junit.Test)

Example 13 with DirectScheduledExecutorService

use of org.apache.flink.runtime.testutils.DirectScheduledExecutorService in project flink by apache.

the class DefaultSchedulerTest method setUp.

@Before
public void setUp() throws Exception {
    executor = Executors.newSingleThreadExecutor();
    scheduledExecutorService = new DirectScheduledExecutorService();
    configuration = new Configuration();
    testRestartBackoffTimeStrategy = new TestRestartBackoffTimeStrategy(true, 0);
    testExecutionVertexOperations = new TestExecutionVertexOperationsDecorator(new DefaultExecutionVertexOperations());
    executionVertexVersioner = new ExecutionVertexVersioner();
    executionSlotAllocatorFactory = new TestExecutionSlotAllocatorFactory();
    testExecutionSlotAllocator = executionSlotAllocatorFactory.getTestExecutionSlotAllocator();
    shuffleMaster = new TestingShuffleMaster();
    partitionTracker = new TestingJobMasterPartitionTracker();
    timeout = Time.seconds(60);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) TestRestartBackoffTimeStrategy(org.apache.flink.runtime.executiongraph.failover.flip1.TestRestartBackoffTimeStrategy) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) TestingJobMasterPartitionTracker(org.apache.flink.runtime.io.network.partition.TestingJobMasterPartitionTracker) TestingShuffleMaster(org.apache.flink.runtime.shuffle.TestingShuffleMaster) Before(org.junit.Before)

Example 14 with DirectScheduledExecutorService

use of org.apache.flink.runtime.testutils.DirectScheduledExecutorService in project flink by splunk.

the class BatchingStateChangeUploadSchedulerTest method testRetry.

/**
 * Test integration with {@link RetryingExecutor}.
 */
@Test
public void testRetry() throws Exception {
    final int maxAttempts = 5;
    try (BatchingStateChangeUploadScheduler store = new BatchingStateChangeUploadScheduler(0, 0, MAX_BYTES_IN_FLIGHT, RetryPolicy.fixed(maxAttempts, 0, 0), new TestingStateChangeUploader() {

        final AtomicInteger currentAttempt = new AtomicInteger(0);

        @Override
        public UploadTasksResult upload(Collection<UploadTask> tasks) throws IOException {
            for (UploadTask uploadTask : tasks) {
                if (currentAttempt.getAndIncrement() < maxAttempts - 1) {
                    throw new IOException();
                } else {
                    uploadTask.complete(emptyList());
                }
            }
            return null;
        }
    }, new DirectScheduledExecutorService(), new RetryingExecutor(new DirectScheduledExecutorService(), createUnregisteredChangelogStorageMetricGroup().getAttemptsPerUpload()), createUnregisteredChangelogStorageMetricGroup())) {
        CompletableFuture<List<UploadResult>> completionFuture = new CompletableFuture<>();
        store.upload(new UploadTask(getChanges(4), completionFuture::complete, (unused, throwable) -> completionFuture.completeExceptionally(throwable)));
        completionFuture.get();
    }
}
Also used : BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) Deadline(org.apache.flink.api.common.time.Deadline) Arrays(java.util.Arrays) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ExceptionUtils.rethrow(org.apache.flink.util.ExceptionUtils.rethrow) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ExceptionUtils.findThrowable(org.apache.flink.util.ExceptionUtils.findThrowable) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) HashSet(java.util.HashSet) ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) UploadTask(org.apache.flink.changelog.fs.StateChangeUploadScheduler.UploadTask) Collectors.toMap(java.util.stream.Collectors.toMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assert.fail(org.junit.Assert.fail) UnregisteredChangelogStorageMetricGroup.createUnregisteredChangelogStorageMetricGroup(org.apache.flink.changelog.fs.UnregisteredChangelogStorageMetricGroup.createUnregisteredChangelogStorageMetricGroup) StateChange(org.apache.flink.runtime.state.changelog.StateChange) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) UUID(java.util.UUID) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) Function.identity(java.util.function.Function.identity) SequenceNumber(org.apache.flink.runtime.state.changelog.SequenceNumber) EmptyStreamStateHandle(org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle) Assert.assertEquals(org.junit.Assert.assertEquals) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) IOException(java.io.IOException) UploadTask(org.apache.flink.changelog.fs.StateChangeUploadScheduler.UploadTask) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Test(org.junit.Test)

Example 15 with DirectScheduledExecutorService

use of org.apache.flink.runtime.testutils.DirectScheduledExecutorService in project flink by splunk.

the class RetryingExecutorTest method testRetryDelay.

@Test
public void testRetryDelay() throws Exception {
    int delayAfterFailure = 123;
    int numAttempts = 2;
    testPolicy(numAttempts, RetryPolicy.fixed(Integer.MAX_VALUE, 0, delayAfterFailure), a -> {
        if (a < numAttempts) {
            throw new IOException();
        }
    }, new DirectScheduledExecutorService() {

        @Override
        public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
            assertEquals(delayAfterFailure, delay);
            command.run();
            return CompletedScheduledFuture.create(null);
        }
    });
}
Also used : DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) TimeUnit(java.util.concurrent.TimeUnit) IOException(java.io.IOException) ScheduledFuture(java.util.concurrent.ScheduledFuture) CompletedScheduledFuture(org.apache.flink.core.testutils.CompletedScheduledFuture) Test(org.junit.Test)

Aggregations

DirectScheduledExecutorService (org.apache.flink.runtime.testutils.DirectScheduledExecutorService)46 Test (org.junit.Test)32 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)17 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)15 SchedulerBase (org.apache.flink.runtime.scheduler.SchedulerBase)15 ArrayList (java.util.ArrayList)14 CompletableFuture (java.util.concurrent.CompletableFuture)10 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)10 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)9 Configuration (org.apache.flink.configuration.Configuration)8 IOException (java.io.IOException)7 Arrays (java.util.Arrays)7 Collection (java.util.Collection)7 List (java.util.List)7 TaskExecutionState (org.apache.flink.runtime.taskmanager.TaskExecutionState)7 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)6 RpcTaskManagerGateway (org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway)6 TestingPhysicalSlot (org.apache.flink.runtime.scheduler.TestingPhysicalSlot)6 TestingPhysicalSlotProvider (org.apache.flink.runtime.scheduler.TestingPhysicalSlotProvider)6 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)6