Java Code Examples for org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel#runScheduledPendingTasks()

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel#runScheduledPendingTasks() . 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: CreditBasedPartitionRequestClientHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private void testReadBufferResponseWithReleasingOrRemovingChannel(
	boolean isRemoved,
	boolean readBeforeReleasingOrRemoving) throws Exception {

	int bufferSize = 1024;

	NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, bufferSize, 2);
	SingleInputGate inputGate = createSingleInputGate(1, networkBufferPool);
	RemoteInputChannel inputChannel = new InputChannelBuilder()
		.buildRemoteChannel(inputGate);
	inputGate.setInputChannels(inputChannel);
	inputGate.assignExclusiveSegments();

	CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
	EmbeddedChannel embeddedChannel = new EmbeddedChannel(handler);
	handler.addInputChannel(inputChannel);

	try {
		if (!readBeforeReleasingOrRemoving) {
			// Release the channel.
			inputGate.close();
			if (isRemoved) {
				handler.removeInputChannel(inputChannel);
			}
		}

		BufferResponse bufferResponse = createBufferResponse(
			TestBufferFactory.createBuffer(bufferSize),
			0,
			inputChannel.getInputChannelId(),
			1,
			new NetworkBufferAllocator(handler));

		if (readBeforeReleasingOrRemoving) {
			// Release the channel.
			inputGate.close();
			if (isRemoved) {
				handler.removeInputChannel(inputChannel);
			}
		}

		handler.channelRead(null, bufferResponse);

		assertEquals(0, inputChannel.getNumberOfQueuedBuffers());
		if (!readBeforeReleasingOrRemoving) {
			assertNull(bufferResponse.getBuffer());
		} else {
			assertNotNull(bufferResponse.getBuffer());
			assertTrue(bufferResponse.getBuffer().isRecycled());
		}

		embeddedChannel.runScheduledPendingTasks();
		NettyMessage.CancelPartitionRequest cancelPartitionRequest = embeddedChannel.readOutbound();
		assertNotNull(cancelPartitionRequest);
		assertEquals(inputChannel.getInputChannelId(), cancelPartitionRequest.receiverId);
	} finally {
		releaseResource(inputGate, networkBufferPool);
		embeddedChannel.close();
	}
}
 
Example 2
Source File: PartitionRequestClientTest.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Run all pending scheduled tasks (waits until all tasks have been run or the deadline has passed.
 *
 * @param channel  the channel to execute tasks for
 * @param deadline maximum timestamp in ms to stop waiting further
 * @throws InterruptedException
 */
void runAllScheduledPendingTasks(EmbeddedChannel channel, long deadline) throws InterruptedException {
	// NOTE: we don't have to be super fancy here; busy-polling with 1ms delays is enough
	while (channel.runScheduledPendingTasks() != -1 && System.currentTimeMillis() < deadline) {
		Thread.sleep(1);
	}
}
 
Example 3
Source File: NettyPartitionRequestClientTest.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Run all pending scheduled tasks (waits until all tasks have been run or the deadline has passed.
 *
 * @param channel  the channel to execute tasks for
 * @param deadline maximum timestamp in ms to stop waiting further
 * @throws InterruptedException
 */
void runAllScheduledPendingTasks(EmbeddedChannel channel, long deadline) throws InterruptedException {
	// NOTE: we don't have to be super fancy here; busy-polling with 1ms delays is enough
	while (channel.runScheduledPendingTasks() != -1 && System.currentTimeMillis() < deadline) {
		Thread.sleep(1);
	}
}
 
Example 4
Source File: NettyPartitionRequestClientTest.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Run all pending scheduled tasks (waits until all tasks have been run or the deadline has passed.
 *
 * @param channel  the channel to execute tasks for
 * @param deadline maximum timestamp in ms to stop waiting further
 * @throws InterruptedException
 */
void runAllScheduledPendingTasks(EmbeddedChannel channel, long deadline) throws InterruptedException {
	// NOTE: we don't have to be super fancy here; busy-polling with 1ms delays is enough
	while (channel.runScheduledPendingTasks() != -1 && System.currentTimeMillis() < deadline) {
		Thread.sleep(1);
	}
}