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