Search in sources :

Example 6 with TestInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel in project flink by apache.

the class StreamTaskFinalCheckpointsTest method testTriggeringCheckpointWithFinishedChannels.

private void testTriggeringCheckpointWithFinishedChannels(CheckpointOptions checkpointOptions) throws Exception {
    ResultPartition[] partitionWriters = new ResultPartition[2];
    try {
        for (int i = 0; i < partitionWriters.length; ++i) {
            partitionWriters[i] = PartitionTestUtils.createPartition(ResultPartitionType.PIPELINED_BOUNDED);
            partitionWriters[i].setup();
        }
        try (StreamTaskMailboxTestHarness<String> testHarness = createTestHarness(partitionWriters, new CompletingCheckpointResponder(), checkpointOptions.isUnalignedCheckpoint() || checkpointOptions.isTimeoutable())) {
            int numChannels = testHarness.inputGates[0].getInputGate().getNumberOfInputChannels();
            int[] resumedCount = new int[numChannels];
            for (int i = 0; i < numChannels; ++i) {
                TestInputChannel inputChannel = (TestInputChannel) testHarness.inputGates[0].getInputGate().getChannel(i);
                inputChannel.setActionOnResumed(() -> resumedCount[inputChannel.getChannelIndex()]++);
            }
            // Tests triggering checkpoint when all the inputs are alive.
            CompletableFuture<Boolean> checkpointFuture = triggerCheckpoint(testHarness, 2, checkpointOptions);
            processMailTillCheckpointSucceeds(testHarness, checkpointFuture);
            assertEquals(2, testHarness.getTaskStateManager().getReportedCheckpointId());
            assertArrayEquals(new int[] { 0, 0, 0 }, resumedCount);
            // Tests triggering checkpoint after some inputs have received EndOfPartition.
            testHarness.processEvent(new EndOfData(StopMode.DRAIN), 0, 0);
            testHarness.processEvent(EndOfPartitionEvent.INSTANCE, 0, 0);
            checkpointFuture = triggerCheckpoint(testHarness, 4, checkpointOptions);
            processMailTillCheckpointSucceeds(testHarness, checkpointFuture);
            assertEquals(4, testHarness.getTaskStateManager().getReportedCheckpointId());
            assertArrayEquals(new int[] { 0, 0, 0 }, resumedCount);
            // Tests triggering checkpoint after received all the inputs have received
            // EndOfPartition.
            testHarness.processEvent(new EndOfData(StopMode.DRAIN), 0, 1);
            testHarness.processEvent(new EndOfData(StopMode.DRAIN), 0, 2);
            testHarness.processEvent(EndOfPartitionEvent.INSTANCE, 0, 1);
            testHarness.processEvent(EndOfPartitionEvent.INSTANCE, 0, 2);
            checkpointFuture = triggerCheckpoint(testHarness, 6, checkpointOptions);
            // Notifies the result partition that all records are processed after the
            // last checkpoint is triggered.
            checkpointFuture.thenAccept((ignored) -> {
                for (ResultPartition resultPartition : partitionWriters) {
                    resultPartition.onSubpartitionAllDataProcessed(0);
                }
            });
            // The checkpoint 6 would be triggered successfully.
            testHarness.finishProcessing();
            assertTrue(checkpointFuture.isDone());
            testHarness.getTaskStateManager().getWaitForReportLatch().await();
            assertEquals(6, testHarness.getTaskStateManager().getReportedCheckpointId());
            assertArrayEquals(new int[] { 0, 0, 0 }, resumedCount);
            // Each result partition should have emitted 3 barriers and 1 EndOfUserRecordsEvent.
            for (ResultPartition resultPartition : partitionWriters) {
                assertEquals(4, resultPartition.getNumberOfQueuedBuffers());
            }
        }
    } finally {
        for (ResultPartitionWriter writer : partitionWriters) {
            if (writer != null) {
                writer.close();
            }
        }
    }
}
Also used : EndOfData(org.apache.flink.runtime.io.network.api.EndOfData) CompletingCheckpointResponder(org.apache.flink.streaming.util.CompletingCheckpointResponder) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) PipelinedResultPartition(org.apache.flink.runtime.io.network.partition.PipelinedResultPartition)

Example 7 with TestInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel in project flink by apache.

the class StreamTaskTest method testBufferSizeRecalculationStartSuccessfully.

@Test
public void testBufferSizeRecalculationStartSuccessfully() throws Exception {
    int expectedThroughput = 13333;
    int inputChannels = 3;
    // debloat period doesn't matter, we will schedule debloating manually
    Configuration config = new Configuration().set(BUFFER_DEBLOAT_PERIOD, Duration.ofHours(10)).set(BUFFER_DEBLOAT_TARGET, Duration.ofSeconds(1)).set(BUFFER_DEBLOAT_THRESHOLD_PERCENTAGES, 1).set(BUFFER_DEBLOAT_ENABLED, true);
    try (StreamTaskMailboxTestHarness<String> harness = new StreamTaskMailboxTestHarnessBuilder<>(OneInputStreamTask::new, STRING_TYPE_INFO).setTaskManagerRuntimeInfo(new TestingTaskManagerRuntimeInfo(config)).addInput(STRING_TYPE_INFO, inputChannels).addInput(STRING_TYPE_INFO, inputChannels).modifyGateBuilder(gateBuilder -> gateBuilder.setThroughputCalculator(bufferDebloatConfiguration -> new ThroughputCalculator(SystemClock.getInstance()) {

        @Override
        public long calculateThroughput() {
            return expectedThroughput;
        }
    })).setupOutputForSingletonOperatorChain(new TestBoundedOneInputStreamOperator()).build()) {
        harness.processAll();
        harness.streamTask.debloat();
        long lastBufferSize = -1;
        for (InputGate inputGate : harness.streamTask.getEnvironment().getAllInputGates()) {
            for (int i = 0; i < inputGate.getNumberOfInputChannels(); i++) {
                long currentBufferSize = ((TestInputChannel) inputGate.getChannel(i)).getCurrentBufferSize();
                assertThat(currentBufferSize, lessThan(MEMORY_SEGMENT_SIZE.defaultValue().getBytes()));
                assertThat(currentBufferSize, greaterThan(0L));
                if (lastBufferSize > 0) {
                    assertThat(lastBufferSize, is(currentBufferSize));
                }
                lastBufferSize = currentBufferSize;
            }
        }
    }
}
Also used : InternalTimeServiceManager(org.apache.flink.streaming.api.operators.InternalTimeServiceManager) NettyShuffleDescriptorBuilder(org.apache.flink.runtime.util.NettyShuffleDescriptorBuilder) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) TaskLocalStateStoreImpl(org.apache.flink.runtime.state.TaskLocalStateStoreImpl) Collections.singletonList(java.util.Collections.singletonList) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AvailabilityTestResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.AvailabilityTestResultPartitionWriter) FunctionWithException(org.apache.flink.util.function.FunctionWithException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FatalExitExceptionHandler(org.apache.flink.util.FatalExitExceptionHandler) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) AsynchronousException(org.apache.flink.runtime.taskmanager.AsynchronousException) Assert.assertFalse(org.junit.Assert.assertFalse) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) Mockito.mock(org.mockito.Mockito.mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) OptionalLong(java.util.OptionalLong) MAX_PRIORITY(org.apache.flink.streaming.runtime.tasks.mailbox.TaskMailbox.MAX_PRIORITY) Output(org.apache.flink.streaming.api.operators.Output) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CheckpointableKeyedStateBackend(org.apache.flink.runtime.state.CheckpointableKeyedStateBackend) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) MailboxExecutor(org.apache.flink.api.common.operators.MailboxExecutor) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) MockStreamConfig(org.apache.flink.streaming.util.MockStreamConfig) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) ExecutionException(java.util.concurrent.ExecutionException) Mockito.never(org.mockito.Mockito.never) JobID(org.apache.flink.api.common.JobID) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) CheckpointStreamFactory(org.apache.flink.runtime.state.CheckpointStreamFactory) Assert.assertEquals(org.junit.Assert.assertEquals) TaskStateManagerImpl(org.apache.flink.runtime.state.TaskStateManagerImpl) TestTaskBuilder(org.apache.flink.runtime.taskmanager.TestTaskBuilder) SystemClock(org.apache.flink.util.clock.SystemClock) ThroughputCalculator(org.apache.flink.runtime.throughput.ThroughputCalculator) ShuffleEnvironment(org.apache.flink.runtime.shuffle.ShuffleEnvironment) ObjectInputStream(java.io.ObjectInputStream) ExceptionUtils(org.apache.flink.util.ExceptionUtils) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) TimerGauge(org.apache.flink.runtime.metrics.TimerGauge) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CheckpointStorageLocationReference.getDefault(org.apache.flink.runtime.state.CheckpointStorageLocationReference.getDefault) Matchers.eq(org.mockito.Matchers.eq) BUFFER_DEBLOAT_ENABLED(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_ENABLED) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) CheckpointType(org.apache.flink.runtime.checkpoint.CheckpointType) BUFFER_DEBLOAT_THRESHOLD_PERCENTAGES(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_THRESHOLD_PERCENTAGES) MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Preconditions(org.apache.flink.util.Preconditions) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) CloseableIterable(org.apache.flink.util.CloseableIterable) DEFAULT_OUTPUT_FLUSH_THREAD_NAME(org.apache.flink.runtime.io.network.api.writer.RecordWriter.DEFAULT_OUTPUT_FLUSH_THREAD_NAME) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CheckpointResponder(org.apache.flink.runtime.taskmanager.CheckpointResponder) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) Assert.assertThrows(org.junit.Assert.assertThrows) CoreMatchers.not(org.hamcrest.CoreMatchers.not) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) ArgumentCaptor(org.mockito.ArgumentCaptor) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) StreamTaskStateInitializer(org.apache.flink.streaming.api.operators.StreamTaskStateInitializer) RichParallelSourceFunction(org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction) StreamMap(org.apache.flink.streaming.api.operators.StreamMap) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) StreamInputProcessor(org.apache.flink.streaming.runtime.io.StreamInputProcessor) ExecutorService(java.util.concurrent.ExecutorService) RunnableFuture(java.util.concurrent.RunnableFuture) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) Configuration(org.apache.flink.configuration.Configuration) StreamOperatorParameters(org.apache.flink.streaming.api.operators.StreamOperatorParameters) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) Mockito.when(org.mockito.Mockito.when) Consumer(java.util.function.Consumer) STATE_BACKEND(org.apache.flink.configuration.StateBackendOptions.STATE_BACKEND) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) TaskExecutionState(org.apache.flink.runtime.taskmanager.TaskExecutionState) ProcessingTimeCallback(org.apache.flink.api.common.operators.ProcessingTimeService.ProcessingTimeCallback) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) TaskIOMetricGroup(org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup) Arrays(java.util.Arrays) AbstractStreamOperatorFactory(org.apache.flink.streaming.api.operators.AbstractStreamOperatorFactory) CheckpointListener(org.apache.flink.api.common.state.CheckpointListener) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) Executors(java.util.concurrent.Executors) StopMode(org.apache.flink.runtime.io.network.api.StopMode) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) SnapshotType(org.apache.flink.runtime.checkpoint.SnapshotType) TaskStateManager(org.apache.flink.runtime.state.TaskStateManager) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) StateHandleID(org.apache.flink.runtime.state.StateHandleID) RunnableWithException(org.apache.flink.util.function.RunnableWithException) STRING_TYPE_INFO(org.apache.flink.api.common.typeinfo.BasicTypeInfo.STRING_TYPE_INFO) ArrayList(java.util.ArrayList) MEMORY_SEGMENT_SIZE(org.apache.flink.configuration.TaskManagerOptions.MEMORY_SEGMENT_SIZE) Mockito.timeout(org.mockito.Mockito.timeout) OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ReadableConfig(org.apache.flink.configuration.ReadableConfig) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter) Nullable(javax.annotation.Nullable) SnapshotResult(org.apache.flink.runtime.state.SnapshotResult) TimeCharacteristic(org.apache.flink.streaming.api.TimeCharacteristic) MailboxDefaultAction(org.apache.flink.streaming.runtime.tasks.mailbox.MailboxDefaultAction) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) InMemoryStateChangelogStorage(org.apache.flink.runtime.state.changelog.inmemory.InMemoryStateChangelogStorage) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) Task(org.apache.flink.runtime.taskmanager.Task) SubtaskState(org.apache.flink.runtime.checkpoint.SubtaskState) TestingUncaughtExceptionHandler(org.apache.flink.util.concurrent.TestingUncaughtExceptionHandler) Assert(org.junit.Assert) CoreMatchers(org.hamcrest.CoreMatchers) CheckpointMetricsBuilder(org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder) SavepointType(org.apache.flink.runtime.checkpoint.SavepointType) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) TimeoutException(java.util.concurrent.TimeoutException) StreamTaskUtil.waitTaskIsRunning(org.apache.flink.streaming.util.StreamTaskUtil.waitTaskIsRunning) PartitionDescriptorBuilder(org.apache.flink.runtime.shuffle.PartitionDescriptorBuilder) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) MapFunction(org.apache.flink.api.common.functions.MapFunction) BUFFER_DEBLOAT_PERIOD(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_PERIOD) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) TaskManagerActions(org.apache.flink.runtime.taskmanager.TaskManagerActions) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) MockStateBackend(org.apache.flink.runtime.state.ttl.mock.MockStateBackend) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) BUFFER_DEBLOAT_TARGET(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_TARGET) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) AbstractStateBackend(org.apache.flink.runtime.state.AbstractStateBackend) StateObjectCollection.singleton(org.apache.flink.runtime.checkpoint.StateObjectCollection.singleton) List(java.util.List) ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) Optional(java.util.Optional) StateBackendFactory(org.apache.flink.runtime.state.StateBackendFactory) CheckpointMetrics(org.apache.flink.runtime.checkpoint.CheckpointMetrics) Environment(org.apache.flink.runtime.execution.Environment) SupplierWithException(org.apache.flink.util.function.SupplierWithException) BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) StatePartitionStreamProvider(org.apache.flink.runtime.state.StatePartitionStreamProvider) NoOpTaskManagerActions(org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) TaskInvokable(org.apache.flink.runtime.jobgraph.tasks.TaskInvokable) UNKNOWN_TASK_CHECKPOINT_NOTIFICATION_FAILURE(org.apache.flink.runtime.checkpoint.CheckpointFailureReason.UNKNOWN_TASK_CHECKPOINT_NOTIFICATION_FAILURE) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) Matchers.anyLong(org.mockito.Matchers.anyLong) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) ExpectedException(org.junit.rules.ExpectedException) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) StreamOperatorStateContext(org.apache.flink.streaming.api.operators.StreamOperatorStateContext) Matchers(org.hamcrest.Matchers) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) DoneFuture(org.apache.flink.runtime.state.DoneFuture) Rule(org.junit.Rule) Closeable(java.io.Closeable) Collections(java.util.Collections) StateInitializationContext(org.apache.flink.runtime.state.StateInitializationContext) Configuration(org.apache.flink.configuration.Configuration) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) ThroughputCalculator(org.apache.flink.runtime.throughput.ThroughputCalculator) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) Test(org.junit.Test)

Example 8 with TestInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel in project flink by apache.

the class AlternatingCheckpointsTest method testBarrierHandling.

private void testBarrierHandling(SnapshotType checkpointType) throws Exception {
    final long barrierId = 123L;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    SingleInputGate gate = new SingleInputGateBuilder().setNumberOfChannels(2).build();
    TestInputChannel fast = new TestInputChannel(gate, 0, false, true);
    TestInputChannel slow = new TestInputChannel(gate, 1, false, true);
    gate.setInputChannels(fast, slow);
    SingleCheckpointBarrierHandler barrierHandler = getTestBarrierHandlerFactory(target).create(gate);
    CheckpointedInputGate checkpointedGate = new CheckpointedInputGate(gate, barrierHandler, new SyncMailboxExecutor());
    if (checkpointType.isSavepoint()) {
        fast.setBlocked(true);
        slow.setBlocked(true);
    }
    CheckpointOptions options = checkpointType.isSavepoint() ? alignedNoTimeout(checkpointType, getDefault()) : unaligned(CheckpointType.CHECKPOINT, getDefault());
    Buffer barrier = barrier(barrierId, 1, options);
    send(barrier.retainBuffer(), fast, checkpointedGate);
    assertEquals(checkpointType.isSavepoint(), target.triggeredCheckpoints.isEmpty());
    send(barrier.retainBuffer(), slow, checkpointedGate);
    assertEquals(singletonList(barrierId), target.triggeredCheckpoints);
    if (checkpointType.isSavepoint()) {
        for (InputChannel channel : gate.getInputChannels().values()) {
            assertFalse(String.format("channel %d should be resumed", channel.getChannelIndex()), ((TestInputChannel) channel).isBlocked());
        }
    }
}
Also used : TestBufferFactory.createBuffer(org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) EventSerializer.toBuffer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) InputChannel(org.apache.flink.runtime.io.network.partition.consumer.InputChannel) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)

Example 9 with TestInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel in project flink by apache.

the class AlternatingCheckpointsTest method testAllChannelsUnblockedAfterAlignmentTimeout.

@Test
public void testAllChannelsUnblockedAfterAlignmentTimeout() throws Exception {
    int numberOfChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numberOfChannels, getTestBarrierHandlerFactory(target)).withTestChannels().withSyncExecutor().build();
    long alignmentTimeout = 100;
    CheckpointBarrier checkpointBarrier = new CheckpointBarrier(1, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeout));
    Buffer checkpointBarrierBuffer = toBuffer(checkpointBarrier, false);
    // we set timer on announcement and test channels do not produce announcements by themselves
    send(EventSerializer.toBuffer(new EventAnnouncement(checkpointBarrier, 0), true), 0, gate);
    // emulate blocking channels on aligned barriers
    ((TestInputChannel) gate.getChannel(0)).setBlocked(true);
    send(checkpointBarrierBuffer, 0, gate);
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    send(EventSerializer.toBuffer(new EventAnnouncement(checkpointBarrier, 0), true), 1, gate);
    // emulate blocking channels on aligned barriers
    ((TestInputChannel) gate.getChannel(1)).setBlocked(true);
    send(checkpointBarrierBuffer, 1, gate);
    assertThat(target.getTriggeredCheckpointOptions().size(), equalTo(1));
    assertThat(target.getTriggeredCheckpointOptions(), contains(unaligned(CheckpointType.CHECKPOINT, getDefault())));
    assertFalse(((TestInputChannel) gate.getChannel(0)).isBlocked());
    assertFalse(((TestInputChannel) gate.getChannel(1)).isBlocked());
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) TestBufferFactory.createBuffer(org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) EventSerializer.toBuffer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer) EventAnnouncement(org.apache.flink.runtime.io.network.api.EventAnnouncement) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 10 with TestInputChannel

use of org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel in project flink by apache.

the class AlternatingCheckpointsTest method testTimeoutAlignmentWhenLocalBarrierFirst.

@Test
public void testTimeoutAlignmentWhenLocalBarrierFirst() throws Exception {
    // given: Gate with remote and local channels.
    int numChannels = 3;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withMixedChannels(0).withMailboxExecutor().build();
    long alignmentTimeout = 100;
    Buffer checkpointBarrier = withTimeout(1, alignmentTimeout);
    // when: Execute the first checkpoint when announcement received first.
    ((TestInputChannel) gate.getChannel(0)).read(checkpointBarrier.retainBuffer());
    (getChannel(gate, 1)).onBuffer(checkpointBarrier.retainBuffer(), 0, 0);
    (getChannel(gate, 2)).onBuffer(checkpointBarrier.retainBuffer(), 0, 0);
    assertAnnouncement(gate);
    assertAnnouncement(gate);
    assertBarrier(gate);
    assertBarrier(gate);
    assertBarrier(gate);
    // then: The checkpoint executed successfully.
    assertEquals(1, target.getTriggeredCheckpointCounter());
    // given: The time in the future.
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    checkpointBarrier = withTimeout(2, alignmentTimeout);
    // when: Execute the second checkpoint when barrier from local channel without announcement
    // received first.
    ((TestInputChannel) gate.getChannel(0)).read(checkpointBarrier.retainBuffer());
    assertBarrier(gate);
    // then: Nothing happens because the alignment timeout should only start after this barrier.
    assertEquals(1, target.getTriggeredCheckpointCounter());
    // when: Receiving the barrier from second channel(with/without) announcement after time
    // more than alignment timeout.
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    (getChannel(gate, 1)).onBuffer(checkpointBarrier.retainBuffer(), 1, 0);
    assertAnnouncement(gate);
    assertBarrier(gate);
    // then: The checkpoint should started as unaligned.
    assertEquals(2, target.getTriggeredCheckpointCounter());
    List<CheckpointOptions> checkpointOptions = target.getTriggeredCheckpointOptions();
    assertEquals(AlignmentType.UNALIGNED, checkpointOptions.get(checkpointOptions.size() - 1).getAlignment());
}
Also used : TestBufferFactory.createBuffer(org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) EventSerializer.toBuffer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Test(org.junit.Test)

Aggregations

TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)12 Test (org.junit.Test)8 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)6 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)6 EventSerializer.toBuffer (org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer)5 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)5 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)5 TestBufferFactory.createBuffer (org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer)5 TestCheckpointedInputGateBuilder (org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder)4 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)3 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)3 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1