Search in sources :

Example 1 with EventSerializer.toBuffer

use of org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer in project flink by apache.

the class RemoteInputChannelTest method testOnUpstreamBlockedAndResumed.

@Test
public void testOnUpstreamBlockedAndResumed() throws Exception {
    BufferPool bufferPool = new TestBufferPool();
    SingleInputGate inputGate = createSingleInputGate(bufferPool);
    RemoteInputChannel remoteChannel1 = createRemoteInputChannel(inputGate, 0, 2);
    RemoteInputChannel remoteChannel2 = createRemoteInputChannel(inputGate, 1, 0);
    inputGate.setup();
    remoteChannel1.requestSubpartition();
    remoteChannel2.requestSubpartition();
    remoteChannel1.onSenderBacklog(2);
    remoteChannel2.onSenderBacklog(2);
    assertEquals(4, remoteChannel1.getNumberOfAvailableBuffers());
    assertEquals(2, remoteChannel2.getNumberOfAvailableBuffers());
    Buffer barrier = EventSerializer.toBuffer(new CheckpointBarrier(1L, 123L, alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), Integer.MAX_VALUE)), false);
    remoteChannel1.onBuffer(barrier, 0, 0);
    remoteChannel2.onBuffer(barrier, 0, 0);
    assertEquals(4, remoteChannel1.getNumberOfAvailableBuffers());
    assertEquals(0, remoteChannel2.getNumberOfAvailableBuffers());
    remoteChannel1.resumeConsumption();
    remoteChannel2.resumeConsumption();
    assertEquals(4, remoteChannel1.getUnannouncedCredit());
    assertEquals(0, remoteChannel2.getUnannouncedCredit());
    remoteChannel1.onSenderBacklog(4);
    remoteChannel2.onSenderBacklog(4);
    assertEquals(6, remoteChannel1.getNumberOfAvailableBuffers());
    assertEquals(4, remoteChannel2.getNumberOfAvailableBuffers());
    assertEquals(6, remoteChannel1.getUnannouncedCredit());
    assertEquals(4, remoteChannel2.getUnannouncedCredit());
}
Also used : NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) 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) BufferBuilderTestUtils.buildSingleBuffer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.buildSingleBuffer) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) NoOpBufferPool(org.apache.flink.runtime.io.network.buffer.NoOpBufferPool) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) Test(org.junit.Test)

Example 2 with EventSerializer.toBuffer

use of org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer 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)

Aggregations

CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)2 EventSerializer.toBuffer (org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer)2 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)2 TestBufferFactory.createBuffer (org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer)2 Test (org.junit.Test)2 EventAnnouncement (org.apache.flink.runtime.io.network.api.EventAnnouncement)1 BufferBuilderTestUtils.buildSingleBuffer (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.buildSingleBuffer)1 BufferPool (org.apache.flink.runtime.io.network.buffer.BufferPool)1 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)1 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)1 NoOpBufferPool (org.apache.flink.runtime.io.network.buffer.NoOpBufferPool)1 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)1 TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)1 TestCheckpointedInputGateBuilder (org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder)1