Search in sources :

Example 1 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class BatchingStateChangeUploaderTest method testDelay.

@Test
public void testDelay() throws Exception {
    int delayMs = 50;
    ManuallyTriggeredScheduledExecutorService scheduler = new ManuallyTriggeredScheduledExecutorService();
    withStore(delayMs, MAX_BYTES_IN_FLIGHT, MAX_BYTES_IN_FLIGHT, scheduler, (store, probe) -> {
        scheduler.triggerAll();
        List<StateChangeSet> changeSets = getChanges(4);
        upload(store, changeSets);
        assertTrue(probe.getUploaded().isEmpty());
        assertTrue(scheduler.getAllNonPeriodicScheduledTask().stream().anyMatch(scheduled -> scheduled.getDelay(MILLISECONDS) == delayMs));
        scheduler.triggerAllNonPeriodicTasks();
        assertEquals(changeSets, probe.getUploaded());
    });
}
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) ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) Test(org.junit.Test)

Example 2 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class ChangelogStorageMetricsTest method testQueueSize.

@Test
public void testQueueSize() throws Exception {
    AtomicReference<Gauge<Integer>> queueSizeGauge = new AtomicReference<>();
    ChangelogStorageMetricGroup metrics = new ChangelogStorageMetricGroup(new TaskManagerJobMetricGroup(TestingMetricRegistry.builder().setRegisterConsumer((metric, name, unused) -> {
        if (name.equals(CHANGELOG_STORAGE_UPLOAD_QUEUE_SIZE)) {
            queueSizeGauge.set((Gauge<Integer>) metric);
        }
    }).build(), createUnregisteredTaskManagerMetricGroup(), new JobID(), "test"));
    Path path = Path.fromLocalFile(temporaryFolder.newFolder());
    StateChangeFsUploader delegate = new StateChangeFsUploader(path, path.getFileSystem(), false, 100, metrics);
    ManuallyTriggeredScheduledExecutorService scheduler = new ManuallyTriggeredScheduledExecutorService();
    BatchingStateChangeUploader batcher = new BatchingStateChangeUploader(Long.MAX_VALUE, Long.MAX_VALUE, Long.MAX_VALUE, RetryPolicy.NONE, delegate, scheduler, new RetryingExecutor(1, metrics.getAttemptsPerUpload()), metrics);
    try (FsStateChangelogStorage storage = new FsStateChangelogStorage(batcher, Long.MAX_VALUE)) {
        FsStateChangelogWriter writer = storage.createWriter("writer", EMPTY_KEY_GROUP_RANGE);
        int numUploads = 11;
        for (int i = 0; i < numUploads; i++) {
            SequenceNumber from = writer.nextSequenceNumber();
            writer.append(0, new byte[] { 0 });
            writer.persist(from);
        }
        assertEquals(numUploads, (int) queueSizeGauge.get().getValue());
        scheduler.triggerScheduledTasks();
        assertEquals(0, (int) queueSizeGauge.get().getValue());
    }
}
Also used : HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) CHANGELOG_STORAGE_UPLOAD_QUEUE_SIZE(org.apache.flink.changelog.fs.ChangelogStorageMetricGroup.CHANGELOG_STORAGE_UPLOAD_QUEUE_SIZE) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) Path(org.apache.flink.core.fs.Path) Map(java.util.Map) Gauge(org.apache.flink.metrics.Gauge) HistogramStatistics(org.apache.flink.metrics.HistogramStatistics) Assert.assertTrue(org.junit.Assert.assertTrue) TaskManagerJobMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerJobMetricGroup) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) JobID(org.apache.flink.api.common.JobID) Rule(org.junit.Rule) UnregisteredMetricGroups.createUnregisteredTaskManagerJobMetricGroup(org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups.createUnregisteredTaskManagerJobMetricGroup) SequenceNumber(org.apache.flink.runtime.state.changelog.SequenceNumber) EmptyStreamStateHandle(org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle) EMPTY_KEY_GROUP_RANGE(org.apache.flink.runtime.state.KeyGroupRange.EMPTY_KEY_GROUP_RANGE) UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) Path(org.apache.flink.core.fs.Path) TaskManagerJobMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerJobMetricGroup) UnregisteredMetricGroups.createUnregisteredTaskManagerJobMetricGroup(org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups.createUnregisteredTaskManagerJobMetricGroup) AtomicReference(java.util.concurrent.atomic.AtomicReference) Gauge(org.apache.flink.metrics.Gauge) ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) SequenceNumber(org.apache.flink.runtime.state.changelog.SequenceNumber) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 3 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class DefaultTimerServiceTest method testUnregisterAllTimeouts.

/**
 * Tests that all registered timeouts can be unregistered.
 */
@Test
public void testUnregisterAllTimeouts() throws Exception {
    final ManuallyTriggeredScheduledExecutorService scheduledExecutorService = new ManuallyTriggeredScheduledExecutorService();
    DefaultTimerService<AllocationID> timerService = new DefaultTimerService<>(scheduledExecutorService, 100L);
    timerService.start((ignoredA, ignoredB) -> {
    });
    timerService.registerTimeout(new AllocationID(), 10, TimeUnit.SECONDS);
    timerService.registerTimeout(new AllocationID(), 10, TimeUnit.SECONDS);
    timerService.unregisterAllTimeouts();
    Map<?, ?> timeouts = timerService.getTimeouts();
    assertTrue(timeouts.isEmpty());
    for (ScheduledFuture<?> scheduledTask : scheduledExecutorService.getAllScheduledTasks()) {
        assertThat(scheduledTask.isCancelled(), is(true));
    }
}
Also used : ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Test(org.junit.Test)

Example 4 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class ChangelogStorageMetricsTest method testUploadBatchSizes.

@Test
public void testUploadBatchSizes() throws Exception {
    int numWriters = 5, numUploads = 5;
    ChangelogStorageMetricGroup metrics = new ChangelogStorageMetricGroup(createUnregisteredTaskManagerJobMetricGroup());
    Path basePath = Path.fromLocalFile(temporaryFolder.newFolder());
    StateChangeFsUploader uploader = new StateChangeFsUploader(basePath, basePath.getFileSystem(), false, 100, metrics);
    ManuallyTriggeredScheduledExecutorService scheduler = new ManuallyTriggeredScheduledExecutorService();
    BatchingStateChangeUploader batcher = new BatchingStateChangeUploader(Long.MAX_VALUE, Long.MAX_VALUE, Long.MAX_VALUE, RetryPolicy.NONE, uploader, scheduler, new RetryingExecutor(1, metrics.getAttemptsPerUpload()), metrics);
    FsStateChangelogStorage storage = new FsStateChangelogStorage(batcher, Integer.MAX_VALUE);
    FsStateChangelogWriter[] writers = new FsStateChangelogWriter[numWriters];
    for (int i = 0; i < numWriters; i++) {
        writers[i] = storage.createWriter(Integer.toString(i), EMPTY_KEY_GROUP_RANGE);
    }
    try {
        for (int upload = 0; upload < numUploads; upload++) {
            for (int writer = 0; writer < numWriters; writer++) {
                // with all thresholds on MAX and manually triggered executor, this shouldn't
                // cause actual uploads
                SequenceNumber from = writers[writer].nextSequenceNumber();
                writers[writer].append(0, new byte[] { 0, 1, 2, 3 });
                writers[writer].persist(from);
            }
            // now the uploads should be grouped and executed at once
            scheduler.triggerScheduledTasks();
        }
        assertEquals(numWriters, metrics.getUploadBatchSizes().getStatistics().getMin());
        assertEquals(numWriters, metrics.getUploadBatchSizes().getStatistics().getMax());
    } finally {
        storage.close();
    }
}
Also used : Path(org.apache.flink.core.fs.Path) ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) SequenceNumber(org.apache.flink.runtime.state.changelog.SequenceNumber) Test(org.junit.Test)

Example 5 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class DefaultTimerServiceTest method createAndStartTimerService.

private static DefaultTimerService<AllocationID> createAndStartTimerService() {
    final ManuallyTriggeredScheduledExecutorService scheduledExecutorService = new ManuallyTriggeredScheduledExecutorService();
    DefaultTimerService<AllocationID> timerService = new DefaultTimerService<>(scheduledExecutorService, 100L);
    timerService.start((ignoredA, ignoredB) -> {
    });
    return timerService;
}
Also used : ManuallyTriggeredScheduledExecutorService(org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID)

Aggregations

ManuallyTriggeredScheduledExecutorService (org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService)8 Test (org.junit.Test)7 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 JobID (org.apache.flink.api.common.JobID)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 TestingMetricRegistry (org.apache.flink.runtime.metrics.util.TestingMetricRegistry)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 Executor (java.util.concurrent.Executor)2