org.apache.flink.runtime.io.network.partition.ResultPartitionProvider Java Examples
The following examples show how to use
org.apache.flink.runtime.io.network.partition.ResultPartitionProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartitionRequestQueueTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private void testBufferWriting(ResultSubpartitionView view) throws IOException { // setup ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; final InputChannelID receiverId = new InputChannelID(); final PartitionRequestQueue queue = new PartitionRequestQueue(); final SequenceNumberingViewReader reader = new SequenceNumberingViewReader(receiverId, queue); final EmbeddedChannel channel = new EmbeddedChannel(queue); reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // notify about buffer availability and encode one buffer reader.notifyDataAvailable(); channel.runPendingTasks(); Object read = channel.readOutbound(); assertNotNull(read); if (read instanceof NettyMessage.ErrorResponse) { ((NettyMessage.ErrorResponse) read).cause.printStackTrace(); } assertThat(read, instanceOf(NettyMessage.BufferResponse.class)); read = channel.readOutbound(); assertNull(read); }
Example #2
Source File: PartitionRequestQueueTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testProducerFailedException() throws Exception { PartitionRequestQueue queue = new PartitionRequestQueue(); ResultSubpartitionView view = new ReleasedResultSubpartitionView(); ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; EmbeddedChannel ch = new EmbeddedChannel(queue); CreditBasedSequenceNumberingViewReader seqView = new CreditBasedSequenceNumberingViewReader(new InputChannelID(), 2, queue); seqView.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // Add available buffer to trigger enqueue the erroneous view seqView.notifyDataAvailable(); ch.runPendingTasks(); // Read the enqueued msg Object msg = ch.readOutbound(); assertEquals(msg.getClass(), NettyMessage.ErrorResponse.class); NettyMessage.ErrorResponse err = (NettyMessage.ErrorResponse) msg; assertTrue(err.cause instanceof CancelTaskException); }
Example #3
Source File: CreditBasedSequenceNumberingViewReader.java From flink with Apache License 2.0 | 6 votes |
@Override public void requestSubpartitionView( ResultPartitionProvider partitionProvider, ResultPartitionID resultPartitionId, int subPartitionIndex) throws IOException { synchronized (requestLock) { if (subpartitionView == null) { // This this call can trigger a notification we have to // schedule a separate task at the event loop that will // start consuming this. Otherwise the reference to the // view cannot be available in getNextBuffer(). this.subpartitionView = partitionProvider.createSubpartitionView( resultPartitionId, subPartitionIndex, this); } else { throw new IllegalStateException("Subpartition already requested"); } } }
Example #4
Source File: SequenceNumberingViewReader.java From flink with Apache License 2.0 | 6 votes |
@Override public void requestSubpartitionView( ResultPartitionProvider partitionProvider, ResultPartitionID resultPartitionId, int subPartitionIndex) throws IOException { synchronized (requestLock) { if (subpartitionView == null) { // This this call can trigger a notification we have to // schedule a separate task at the event loop that will // start consuming this. Otherwise the reference to the // view cannot be available in getNextBuffer(). this.subpartitionView = partitionProvider.createSubpartitionView( resultPartitionId, subPartitionIndex, this); } else { throw new IllegalStateException("Subpartition already requested"); } } }
Example #5
Source File: PartitionRequestQueueTest.java From flink with Apache License 2.0 | 6 votes |
private void testBufferWriting(ResultSubpartitionView view) throws IOException { // setup ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; final InputChannelID receiverId = new InputChannelID(); final PartitionRequestQueue queue = new PartitionRequestQueue(); final SequenceNumberingViewReader reader = new SequenceNumberingViewReader(receiverId, queue); final EmbeddedChannel channel = new EmbeddedChannel(queue); reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // notify about buffer availability and encode one buffer reader.notifyDataAvailable(); channel.runPendingTasks(); Object read = channel.readOutbound(); assertNotNull(read); if (read instanceof NettyMessage.ErrorResponse) { ((NettyMessage.ErrorResponse) read).cause.printStackTrace(); } assertThat(read, instanceOf(NettyMessage.BufferResponse.class)); read = channel.readOutbound(); assertNull(read); }
Example #6
Source File: CreditBasedSequenceNumberingViewReader.java From flink with Apache License 2.0 | 6 votes |
@Override public void requestSubpartitionView( ResultPartitionProvider partitionProvider, ResultPartitionID resultPartitionId, int subPartitionIndex) throws IOException { synchronized (requestLock) { if (subpartitionView == null) { // This this call can trigger a notification we have to // schedule a separate task at the event loop that will // start consuming this. Otherwise the reference to the // view cannot be available in getNextBuffer(). this.subpartitionView = partitionProvider.createSubpartitionView( resultPartitionId, subPartitionIndex, this); } else { throw new IllegalStateException("Subpartition already requested"); } } }
Example #7
Source File: PartitionRequestQueueTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testProducerFailedException() throws Exception { PartitionRequestQueue queue = new PartitionRequestQueue(); ResultSubpartitionView view = new ReleasedResultSubpartitionView(); ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; EmbeddedChannel ch = new EmbeddedChannel(queue); CreditBasedSequenceNumberingViewReader seqView = new CreditBasedSequenceNumberingViewReader(new InputChannelID(), 2, queue); seqView.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // Add available buffer to trigger enqueue the erroneous view seqView.notifyDataAvailable(); ch.runPendingTasks(); // Read the enqueued msg Object msg = ch.readOutbound(); assertEquals(msg.getClass(), NettyMessage.ErrorResponse.class); NettyMessage.ErrorResponse err = (NettyMessage.ErrorResponse) msg; assertTrue(err.cause instanceof CancelTaskException); }
Example #8
Source File: PartitionRequestQueueTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testProducerFailedException() throws Exception { PartitionRequestQueue queue = new PartitionRequestQueue(); ResultSubpartitionView view = new ReleasedResultSubpartitionView(); ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; EmbeddedChannel ch = new EmbeddedChannel(queue); CreditBasedSequenceNumberingViewReader seqView = new CreditBasedSequenceNumberingViewReader(new InputChannelID(), 2, queue); seqView.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // Add available buffer to trigger enqueue the erroneous view seqView.notifyDataAvailable(); ch.runPendingTasks(); // Read the enqueued msg Object msg = ch.readOutbound(); assertEquals(msg.getClass(), NettyMessage.ErrorResponse.class); NettyMessage.ErrorResponse err = (NettyMessage.ErrorResponse) msg; assertTrue(err.cause instanceof CancelTaskException); }
Example #9
Source File: CreditBasedSequenceNumberingViewReader.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void requestSubpartitionView( ResultPartitionProvider partitionProvider, ResultPartitionID resultPartitionId, int subPartitionIndex) throws IOException { synchronized (requestLock) { if (subpartitionView == null) { // This this call can trigger a notification we have to // schedule a separate task at the event loop that will // start consuming this. Otherwise the reference to the // view cannot be available in getNextBuffer(). this.subpartitionView = partitionProvider.createSubpartitionView( resultPartitionId, subPartitionIndex, this); } else { throw new IllegalStateException("Subpartition already requested"); } } }
Example #10
Source File: SequenceNumberingViewReader.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void requestSubpartitionView( ResultPartitionProvider partitionProvider, ResultPartitionID resultPartitionId, int subPartitionIndex) throws IOException { synchronized (requestLock) { if (subpartitionView == null) { // This this call can trigger a notification we have to // schedule a separate task at the event loop that will // start consuming this. Otherwise the reference to the // view cannot be available in getNextBuffer(). this.subpartitionView = partitionProvider.createSubpartitionView( resultPartitionId, subPartitionIndex, this); } else { throw new IllegalStateException("Subpartition already requested"); } } }
Example #11
Source File: PartitionRequestQueueTest.java From flink with Apache License 2.0 | 5 votes |
private void testBufferWriting(ResultSubpartitionView view) throws IOException { // setup ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; final InputChannelID receiverId = new InputChannelID(); final PartitionRequestQueue queue = new PartitionRequestQueue(); final CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader( receiverId, Integer.MAX_VALUE, queue); final EmbeddedChannel channel = new EmbeddedChannel(queue); reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // notify about buffer availability and encode one buffer reader.notifyDataAvailable(); channel.runPendingTasks(); Object read = channel.readOutbound(); assertNotNull(read); if (read instanceof NettyMessage.ErrorResponse) { ((NettyMessage.ErrorResponse) read).cause.printStackTrace(); } assertThat(read, instanceOf(NettyMessage.BufferResponse.class)); read = channel.readOutbound(); assertNull(read); }
Example #12
Source File: NettyConnectionManager.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public void start(ResultPartitionProvider partitionProvider, TaskEventDispatcher taskEventDispatcher) throws IOException { NettyProtocol partitionRequestProtocol = new NettyProtocol( partitionProvider, taskEventDispatcher, client.getConfig().isCreditBasedEnabled()); client.init(partitionRequestProtocol, bufferPool); server.init(partitionRequestProtocol, bufferPool); }
Example #13
Source File: PartitionRequestQueueTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests {@link PartitionRequestQueue#enqueueAvailableReader(NetworkSequenceViewReader)}, * verifying the reader would be enqueued in the pipeline if the next sending buffer is an event * even though it has no available credits. */ @Test public void testEnqueueReaderByNotifyingEventBuffer() throws Exception { // setup final ResultSubpartitionView view = new NextIsEventResultSubpartitionView(); ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; final InputChannelID receiverId = new InputChannelID(); final PartitionRequestQueue queue = new PartitionRequestQueue(); final CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader(receiverId, 0, queue); final EmbeddedChannel channel = new EmbeddedChannel(queue); reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // block the channel so that we see an intermediate state in the test ByteBuf channelBlockingBuffer = blockChannel(channel); assertNull(channel.readOutbound()); // Notify an available event buffer to trigger enqueue the reader reader.notifyDataAvailable(); channel.runPendingTasks(); // The reader is enqueued in the pipeline because the next buffer is an event, even though no credits are available assertThat(queue.getAvailableReaders(), contains(reader)); // contains only (this) one! assertEquals(0, reader.getNumCreditsAvailable()); // Flush the buffer to make the channel writable again and see the final results channel.flush(); assertSame(channelBlockingBuffer, channel.readOutbound()); assertEquals(0, queue.getAvailableReaders().size()); assertEquals(0, reader.getNumCreditsAvailable()); assertNull(channel.readOutbound()); }
Example #14
Source File: PartitionRequestServerHandler.java From flink with Apache License 2.0 | 5 votes |
PartitionRequestServerHandler( ResultPartitionProvider partitionProvider, TaskEventPublisher taskEventPublisher, PartitionRequestQueue outboundQueue) { this.partitionProvider = partitionProvider; this.taskEventPublisher = taskEventPublisher; this.outboundQueue = outboundQueue; }
Example #15
Source File: NettyConnectionManager.java From flink with Apache License 2.0 | 5 votes |
public NettyConnectionManager( ResultPartitionProvider partitionProvider, TaskEventPublisher taskEventPublisher, NettyConfig nettyConfig) { this.server = new NettyServer(nettyConfig); this.client = new NettyClient(nettyConfig); this.bufferPool = new NettyBufferPool(nettyConfig.getNumberOfArenas()); this.partitionRequestClientFactory = new PartitionRequestClientFactory(client); this.nettyProtocol = new NettyProtocol(checkNotNull(partitionProvider), checkNotNull(taskEventPublisher)); }
Example #16
Source File: ClientTransportErrorHandlingTest.java From flink with Apache License 2.0 | 5 votes |
private EmbeddedChannel createEmbeddedChannel() { NettyProtocol protocol = new NettyProtocol( mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class), true); return new EmbeddedChannel(protocol.getClientChannelHandlers()); }
Example #17
Source File: PartitionRequestQueueTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests {@link PartitionRequestQueue#enqueueAvailableReader(NetworkSequenceViewReader)}, * verifying the reader would be enqueued in the pipeline if the next sending buffer is an event * even though it has no available credits. */ @Test public void testEnqueueReaderByNotifyingEventBuffer() throws Exception { // setup final ResultSubpartitionView view = new NextIsEventResultSubpartitionView(); ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; final InputChannelID receiverId = new InputChannelID(); final PartitionRequestQueue queue = new PartitionRequestQueue(); final CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader(receiverId, 0, queue); final EmbeddedChannel channel = new EmbeddedChannel(queue); reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // block the channel so that we see an intermediate state in the test ByteBuf channelBlockingBuffer = blockChannel(channel); assertNull(channel.readOutbound()); // Notify an available event buffer to trigger enqueue the reader reader.notifyDataAvailable(); channel.runPendingTasks(); // The reader is enqueued in the pipeline because the next buffer is an event, even though no credits are available assertThat(queue.getAvailableReaders(), contains(reader)); // contains only (this) one! assertEquals(0, reader.getNumCreditsAvailable()); // Flush the buffer to make the channel writable again and see the final results channel.flush(); assertSame(channelBlockingBuffer, channel.readOutbound()); assertEquals(0, queue.getAvailableReaders().size()); assertEquals(0, reader.getNumCreditsAvailable()); assertNull(channel.readOutbound()); }
Example #18
Source File: PartitionRequestQueueTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests {@link PartitionRequestQueue#enqueueAvailableReader(NetworkSequenceViewReader)}, * verifying the reader would be enqueued in the pipeline after resuming data consumption if there * are credit and data available. */ @Test public void testEnqueueReaderByResumingConsumption() throws Exception { PipelinedSubpartition subpartition = PipelinedSubpartitionTest.createPipelinedSubpartition(); Buffer.DataType dataType1 = Buffer.DataType.ALIGNED_EXACTLY_ONCE_CHECKPOINT_BARRIER; Buffer.DataType dataType2 = Buffer.DataType.DATA_BUFFER; subpartition.add(createEventBufferConsumer(4096, dataType1)); subpartition.add(createEventBufferConsumer(4096, dataType2)); BufferAvailabilityListener bufferAvailabilityListener = new NoOpBufferAvailablityListener(); PipelinedSubpartitionView view = subpartition.createReadView(bufferAvailabilityListener); ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; InputChannelID receiverId = new InputChannelID(); PartitionRequestQueue queue = new PartitionRequestQueue(); CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader(receiverId, 0, queue); EmbeddedChannel channel = new EmbeddedChannel(queue); reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); queue.notifyReaderCreated(reader); // we have adequate credits reader.addCredit(Integer.MAX_VALUE); assertTrue(reader.isAvailable()); reader.notifyDataAvailable(); channel.runPendingTasks(); assertFalse(reader.isAvailable()); assertEquals(1, subpartition.unsynchronizedGetNumberOfQueuedBuffers()); queue.addCreditOrResumeConsumption(receiverId, NetworkSequenceViewReader::resumeConsumption); assertFalse(reader.isAvailable()); assertEquals(0, subpartition.unsynchronizedGetNumberOfQueuedBuffers()); Object data1 = channel.readOutbound(); assertEquals(dataType1, ((NettyMessage.BufferResponse) data1).buffer.getDataType()); Object data2 = channel.readOutbound(); assertEquals(dataType2, ((NettyMessage.BufferResponse) data2).buffer.getDataType()); }
Example #19
Source File: ClientTransportErrorHandlingTest.java From flink with Apache License 2.0 | 5 votes |
private EmbeddedChannel createEmbeddedChannel() { NettyProtocol protocol = new NettyProtocol( mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class)); return new EmbeddedChannel(protocol.getClientChannelHandlers()); }
Example #20
Source File: PartitionRequestServerHandler.java From flink with Apache License 2.0 | 5 votes |
PartitionRequestServerHandler( ResultPartitionProvider partitionProvider, TaskEventPublisher taskEventPublisher, PartitionRequestQueue outboundQueue, boolean creditBasedEnabled) { this.partitionProvider = partitionProvider; this.taskEventPublisher = taskEventPublisher; this.outboundQueue = outboundQueue; this.creditBasedEnabled = creditBasedEnabled; }
Example #21
Source File: NettyConnectionManager.java From flink with Apache License 2.0 | 5 votes |
public NettyConnectionManager( ResultPartitionProvider partitionProvider, TaskEventPublisher taskEventPublisher, NettyConfig nettyConfig, boolean isCreditBased) { this.server = new NettyServer(nettyConfig); this.client = new NettyClient(nettyConfig); this.bufferPool = new NettyBufferPool(nettyConfig.getNumberOfArenas()); this.partitionRequestClientFactory = new PartitionRequestClientFactory(client); this.nettyProtocol = new NettyProtocol(checkNotNull(partitionProvider), checkNotNull(taskEventPublisher), isCreditBased); }
Example #22
Source File: PartitionRequestServerHandler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
PartitionRequestServerHandler( ResultPartitionProvider partitionProvider, TaskEventDispatcher taskEventDispatcher, PartitionRequestQueue outboundQueue, boolean creditBasedEnabled) { this.partitionProvider = partitionProvider; this.taskEventDispatcher = taskEventDispatcher; this.outboundQueue = outboundQueue; this.creditBasedEnabled = creditBasedEnabled; }
Example #23
Source File: ClientTransportErrorHandlingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private EmbeddedChannel createEmbeddedChannel() { NettyProtocol protocol = new NettyProtocol( mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class), true); return new EmbeddedChannel(protocol.getClientChannelHandlers()); }
Example #24
Source File: PartitionRequestQueueTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests {@link PartitionRequestQueue#enqueueAvailableReader(NetworkSequenceViewReader)}, * verifying the reader would be enqueued in the pipeline if the next sending buffer is an event * even though it has no available credits. */ @Test public void testEnqueueReaderByNotifyingEventBuffer() throws Exception { // setup final ResultSubpartitionView view = new NextIsEventResultSubpartitionView(); ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; final InputChannelID receiverId = new InputChannelID(); final PartitionRequestQueue queue = new PartitionRequestQueue(); final CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader(receiverId, 0, queue); final EmbeddedChannel channel = new EmbeddedChannel(queue); reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); // block the channel so that we see an intermediate state in the test ByteBuf channelBlockingBuffer = blockChannel(channel); assertNull(channel.readOutbound()); // Notify an available event buffer to trigger enqueue the reader reader.notifyDataAvailable(); channel.runPendingTasks(); // The reader is enqueued in the pipeline because the next buffer is an event, even though no credits are available assertThat(queue.getAvailableReaders(), contains(reader)); // contains only (this) one! assertEquals(0, reader.getNumCreditsAvailable()); // Flush the buffer to make the channel writable again and see the final results channel.flush(); assertSame(channelBlockingBuffer, channel.readOutbound()); assertEquals(0, queue.getAvailableReaders().size()); assertEquals(0, reader.getNumCreditsAvailable()); assertNull(channel.readOutbound()); }
Example #25
Source File: ConnectionManager.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
void start(ResultPartitionProvider partitionProvider, TaskEventDispatcher taskEventDispatcher) throws IOException;
Example #26
Source File: NetworkSequenceViewReader.java From flink with Apache License 2.0 | 4 votes |
void requestSubpartitionView( ResultPartitionProvider partitionProvider, ResultPartitionID resultPartitionId, int subPartitionIndex) throws IOException;
Example #27
Source File: ClientTransportErrorHandlingTest.java From flink with Apache License 2.0 | 4 votes |
/** * Verifies that failed client requests via {@link PartitionRequestClient} are correctly * attributed to the respective {@link RemoteInputChannel}. */ @Test public void testExceptionOnWrite() throws Exception { NettyProtocol protocol = new NettyProtocol( mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class)) { @Override public ChannelHandler[] getServerChannelHandlers() { return new ChannelHandler[0]; } }; // We need a real server and client in this test, because Netty's EmbeddedChannel is // not failing the ChannelPromise of failed writes. NettyServerAndClient serverAndClient = initServerAndClient(protocol, createConfig()); Channel ch = connect(serverAndClient); NetworkClientHandler handler = getClientHandler(ch); // Last outbound handler throws Exception after 1st write ch.pipeline().addFirst(new ChannelOutboundHandlerAdapter() { int writeNum = 0; @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (writeNum >= 1) { throw new RuntimeException("Expected test exception."); } writeNum++; ctx.write(msg, promise); } }); PartitionRequestClient requestClient = new NettyPartitionRequestClient( ch, handler, mock(ConnectionID.class), mock(PartitionRequestClientFactory.class)); // Create input channels RemoteInputChannel[] rich = new RemoteInputChannel[] { createRemoteInputChannel(), createRemoteInputChannel()}; final CountDownLatch sync = new CountDownLatch(1); // Do this with explicit synchronization. Otherwise this is not robust against slow timings // of the callback (e.g. we cannot just verify that it was called once, because there is // a chance that we do this too early). doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { sync.countDown(); return null; } }).when(rich[1]).onError(isA(LocalTransportException.class)); // First request is successful requestClient.requestSubpartition(new ResultPartitionID(), 0, rich[0], 0); // Second request is *not* successful requestClient.requestSubpartition(new ResultPartitionID(), 0, rich[1], 0); // Wait for the notification and it could confirm all the request operations are done if (!sync.await(TestingUtils.TESTING_DURATION().toMillis(), TimeUnit.MILLISECONDS)) { fail("Timed out after waiting for " + TestingUtils.TESTING_DURATION().toMillis() + " ms to be notified about the channel error."); } // Only the second channel should be notified about the error verify(rich[0], times(0)).onError(any(LocalTransportException.class)); shutdown(serverAndClient); }
Example #28
Source File: PartitionRequestQueueTest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests {@link PartitionRequestQueue#enqueueAvailableReader(NetworkSequenceViewReader)}, * verifying the reader would be enqueued in the pipeline iff it has both available credits and buffers. */ @Test public void testEnqueueReaderByNotifyingBufferAndCredit() throws Exception { // setup final ResultSubpartitionView view = new DefaultBufferResultSubpartitionView(10); ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view; final InputChannelID receiverId = new InputChannelID(); final PartitionRequestQueue queue = new PartitionRequestQueue(); final CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader(receiverId, 0, queue); final EmbeddedChannel channel = new EmbeddedChannel(queue); reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0); queue.notifyReaderCreated(reader); // block the channel so that we see an intermediate state in the test ByteBuf channelBlockingBuffer = blockChannel(channel); assertNull(channel.readOutbound()); // Notify available buffers to trigger enqueue the reader final int notifyNumBuffers = 5; for (int i = 0; i < notifyNumBuffers; i++) { reader.notifyDataAvailable(); } channel.runPendingTasks(); // the reader is not enqueued in the pipeline because no credits are available // -> it should still have the same number of pending buffers assertEquals(0, queue.getAvailableReaders().size()); assertTrue(reader.hasBuffersAvailable()); assertFalse(reader.isRegisteredAsAvailable()); assertEquals(0, reader.getNumCreditsAvailable()); // Notify available credits to trigger enqueue the reader again final int notifyNumCredits = 3; for (int i = 1; i <= notifyNumCredits; i++) { queue.addCreditOrResumeConsumption(receiverId, viewReader -> viewReader.addCredit(1)); // the reader is enqueued in the pipeline because it has both available buffers and credits // since the channel is blocked though, we will not process anything and only enqueue the // reader once assertTrue(reader.isRegisteredAsAvailable()); assertThat(queue.getAvailableReaders(), contains(reader)); // contains only (this) one! assertEquals(i, reader.getNumCreditsAvailable()); assertTrue(reader.hasBuffersAvailable()); } // Flush the buffer to make the channel writable again and see the final results channel.flush(); assertSame(channelBlockingBuffer, channel.readOutbound()); assertEquals(0, queue.getAvailableReaders().size()); assertEquals(0, reader.getNumCreditsAvailable()); assertTrue(reader.hasBuffersAvailable()); assertFalse(reader.isRegisteredAsAvailable()); for (int i = 1; i <= notifyNumCredits; i++) { assertThat(channel.readOutbound(), instanceOf(NettyMessage.BufferResponse.class)); } assertNull(channel.readOutbound()); }
Example #29
Source File: NettyProtocol.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
NettyProtocol(ResultPartitionProvider partitionProvider, TaskEventDispatcher taskEventDispatcher, boolean creditBasedEnabled) { this.partitionProvider = partitionProvider; this.taskEventDispatcher = taskEventDispatcher; this.creditBasedEnabled = creditBasedEnabled; }
Example #30
Source File: NetworkSequenceViewReader.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
void requestSubpartitionView( ResultPartitionProvider partitionProvider, ResultPartitionID resultPartitionId, int subPartitionIndex) throws IOException;