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