Search in sources :

Example 36 with DirectScheduledExecutorService

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

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) 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) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) 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 37 with DirectScheduledExecutorService

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

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 38 with DirectScheduledExecutorService

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

the class RetryingExecutorTest method testNoRetryDelayIfTimeout.

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

        @Override
        public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
            fail("task should be executed directly without delay after timeout");
            return CompletedScheduledFuture.create(null);
        }
    });
}
Also used : DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) TimeUnit(java.util.concurrent.TimeUnit) ScheduledFuture(java.util.concurrent.ScheduledFuture) CompletedScheduledFuture(org.apache.flink.core.testutils.CompletedScheduledFuture) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 39 with DirectScheduledExecutorService

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

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)

Example 40 with DirectScheduledExecutorService

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

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)

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