Search in sources :

Example 76 with Buffer

use of org.apache.flink.runtime.io.network.buffer.Buffer in project flink by apache.

the class AlternatingCheckpointsTest method testAlignedAfterTimedOut.

@Test
public void testAlignedAfterTimedOut() throws Exception {
    int numChannels = 1;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    long alignmentTimeOut = 100L;
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build()) {
        Buffer barrier1 = barrier(1, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut));
        ((RemoteInputChannel) gate.getChannel(0)).onBuffer(barrier1.retainBuffer(), 0, 0);
        assertAnnouncement(gate);
        clock.advanceTime(alignmentTimeOut + 1, TimeUnit.MILLISECONDS);
        assertBarrier(gate);
        assertEquals(1, target.getTriggeredCheckpointCounter());
        Buffer barrier2 = barrier(2, clock.relativeTimeMillis(), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut));
        ((RemoteInputChannel) gate.getChannel(0)).onBuffer(barrier2.retainBuffer(), 1, 0);
        assertAnnouncement(gate);
        assertBarrier(gate);
        assertEquals(2, target.getTriggeredCheckpointCounter());
        assertThat(target.getTriggeredCheckpointOptions(), contains(unaligned(CheckpointType.CHECKPOINT, getDefault()), alignedWithTimeout(CheckpointType.CHECKPOINT, getDefault(), alignmentTimeOut)));
    }
}
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) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) Test(org.junit.Test)

Example 77 with Buffer

use of org.apache.flink.runtime.io.network.buffer.Buffer in project flink by apache.

the class AlternatingCheckpointsTest method testTimeoutAlignmentOnAnnouncementForSecondCheckpoint.

/**
 * This test tries to make sure that the first time out happens after processing {@link
 * EventAnnouncement} but before/during processing the first {@link CheckpointBarrier} of at
 * least second checkpoint.
 */
@Test
public void testTimeoutAlignmentOnAnnouncementForSecondCheckpoint() throws Exception {
    int numChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build();
    long alignmentTimeout = 100;
    performFirstCheckpoint(numChannels, target, gate, alignmentTimeout);
    assertEquals(1, target.getTriggeredCheckpointCounter());
    Buffer checkpointBarrier = withTimeout(2, alignmentTimeout);
    for (int i = 0; i < numChannels; i++) {
        (getChannel(gate, i)).onBuffer(dataBuffer(), 1, 0);
        (getChannel(gate, i)).onBuffer(checkpointBarrier.retainBuffer(), 2, 0);
    }
    assertEquals(1, target.getTriggeredCheckpointCounter());
    for (int i = 0; i < numChannels; i++) {
        assertAnnouncement(gate);
    }
    assertEquals(1, target.getTriggeredCheckpointCounter());
    clock.advanceTime(alignmentTimeout * 4, TimeUnit.MILLISECONDS);
    // the barrier should overtake the data buffers
    assertBarrier(gate);
    assertEquals(2, target.getTriggeredCheckpointCounter());
}
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) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 78 with Buffer

use of org.apache.flink.runtime.io.network.buffer.Buffer in project flink by apache.

the class AlternatingCheckpointsTest method testActiveTimeoutAlignmentOnAnnouncement.

@Test
public void testActiveTimeoutAlignmentOnAnnouncement() throws Exception {
    int numChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    try (CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withRemoteChannels().withMailboxExecutor().build()) {
        long alignmentTimeout = 10;
        Buffer checkpointBarrier = withTimeout(alignmentTimeout);
        getChannel(gate, 0).onBuffer(dataBuffer(), 0, 0);
        getChannel(gate, 0).onBuffer(dataBuffer(), 1, 0);
        getChannel(gate, 0).onBuffer(checkpointBarrier.retainBuffer(), 2, 0);
        getChannel(gate, 1).onBuffer(dataBuffer(), 0, 0);
        getChannel(gate, 1).onBuffer(checkpointBarrier.retainBuffer(), 1, 0);
        assertEquals(0, target.getTriggeredCheckpointCounter());
        assertAnnouncement(gate);
        assertAnnouncement(gate);
        // the announcement should time out causing the barriers to overtake the data buffers
        clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
        assertBarrier(gate);
        assertBarrier(gate);
        assertEquals(1, target.getTriggeredCheckpointCounter());
        assertThat(target.getTriggeredCheckpointOptions(), contains(unaligned(CheckpointType.CHECKPOINT, getDefault())));
        // Followed by overtaken buffers
        assertData(gate);
        assertData(gate);
        assertData(gate);
    }
}
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) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) Test(org.junit.Test)

Example 79 with Buffer

use of org.apache.flink.runtime.io.network.buffer.Buffer in project flink by apache.

the class AlternatingCheckpointsTest method testTimeoutAlignmentBeforeFirstBarrier.

@Test
public void testTimeoutAlignmentBeforeFirstBarrier() throws Exception {
    // given: Local channels.
    int numChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numChannels, getTestBarrierHandlerFactory(target)).withTestChannels().withMailboxExecutor().build();
    long alignedCheckpointTimeout = 100;
    // when: Aligned checkpoint timeout expired before the first barrier received.
    Buffer checkpointBarrier = withTimeout(1, alignedCheckpointTimeout);
    clock.advanceTime(alignedCheckpointTimeout + 1, TimeUnit.MILLISECONDS);
    ((TestInputChannel) gate.getChannel(0)).read(checkpointBarrier.retainBuffer());
    // then: The UC is triggered as soon as the first barrier is received.
    assertBarrier(gate);
    assertEquals(1, target.getTriggeredCheckpointCounter());
}
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) Test(org.junit.Test)

Example 80 with Buffer

use of org.apache.flink.runtime.io.network.buffer.Buffer in project flink by apache.

the class AlternatingCheckpointsTest method testNoActiveTimeoutAlignmentAfterAbort.

@Test
public void testNoActiveTimeoutAlignmentAfterAbort() throws Exception {
    int numberOfChannels = 2;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    CheckpointedInputGate gate = new TestCheckpointedInputGateBuilder(numberOfChannels, getTestBarrierHandlerFactory(target)).withTestChannels().withSyncExecutor().build();
    long alignmentTimeout = 100;
    Buffer checkpointBarrier = withTimeout(alignmentTimeout);
    send(checkpointBarrier, 0, gate);
    send(toBuffer(new CancelCheckpointMarker(1L), true), 0, gate);
    send(toBuffer(new CancelCheckpointMarker(1L), true), 1, gate);
    clock.advanceTime(alignmentTimeout + 1, TimeUnit.MILLISECONDS);
    assertThat(target.getTriggeredCheckpointOptions().size(), equalTo(0));
}
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) TestCheckpointedInputGateBuilder(org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder) CancelCheckpointMarker(org.apache.flink.runtime.io.network.api.CancelCheckpointMarker) Test(org.junit.Test)

Aggregations

Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)172 Test (org.junit.Test)91 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)45 ByteBuffer (java.nio.ByteBuffer)44 TestBufferFactory.createBuffer (org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer)35 EventSerializer.toBuffer (org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer)34 IOException (java.io.IOException)27 MemorySegment (org.apache.flink.core.memory.MemorySegment)27 BufferPool (org.apache.flink.runtime.io.network.buffer.BufferPool)18 TestCheckpointedInputGateBuilder (org.apache.flink.streaming.util.TestCheckpointedInputGateBuilder)18 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)16 ArrayList (java.util.ArrayList)15 Nullable (javax.annotation.Nullable)15 BufferBuilderTestUtils.buildSingleBuffer (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.buildSingleBuffer)14 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)13 Random (java.util.Random)12 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)10 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)9 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)9 BufferProvider (org.apache.flink.runtime.io.network.buffer.BufferProvider)9