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());
}
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();
}
}
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);
}
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();
}
}
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);
}
});
}
Aggregations