Java Code Examples for io.netty.channel.ChannelPromise#await()
The following examples show how to use
io.netty.channel.ChannelPromise#await() .
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: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Test(timeout = 5000) public void test_qos1_release_next_message_on_next_puback() throws Exception { final PUBLISH publish = createPublish("topic", 1, QoS.AT_LEAST_ONCE); final PUBLISH publish2 = createPublish("topic", 2, QoS.AT_LEAST_ONCE); final PUBLISH publish3 = createPublish("topic", 3, QoS.AT_LEAST_ONCE); final ChannelPromise promise1 = channel.newPromise(); final ChannelPromise promise2 = channel.newPromise(); final ChannelPromise promise3 = channel.newPromise(); channel.writeAndFlush(publish, promise1); channel.writeAndFlush(publish2, promise2); channel.writeAndFlush(publish3, promise3); channel.pipeline().fireChannelRead(new PUBACK(1)); channel.pipeline().fireChannelRead(new PUBACK(2)); promise1.await(); promise2.await(); promise3.await(); assertEquals(0, orderedTopicHandler.queue.size()); assertEquals(1, orderedTopicHandler.unacknowledgedMessages().size()); }
Example 2
Source File: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Test(timeout = 5000) public void test_qos1_release_next_message_on_dropped() throws Exception { InternalConfigurations.MAX_INFLIGHT_WINDOW_SIZE = 1; final PUBLISH publish = createPublish("topic", 1, QoS.AT_LEAST_ONCE); final PUBLISH publish2 = createPublish("topic", 2, QoS.AT_LEAST_ONCE); final PUBLISH publish3 = createPublish("topic", 3, QoS.AT_LEAST_ONCE); final ChannelPromise promise1 = channel.newPromise(); final ChannelPromise promise2 = channel.newPromise(); final ChannelPromise promise3 = channel.newPromise(); channel.writeAndFlush(publish, promise1); channel.writeAndFlush(publish2, promise2); channel.writeAndFlush(publish3, promise3); channel.pipeline().fireUserEventTriggered(new PublishDroppedEvent(publish)); channel.pipeline().fireUserEventTriggered(new PublishDroppedEvent(publish2)); promise1.await(); promise2.await(); promise3.await(); }
Example 3
Source File: NettyTransportClient.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Override public ClusterResponse sendRequest(ClusterRequest request) throws Exception { if (!isReady()) { throw new SentinelClusterException(ClusterErrorMessages.CLIENT_NOT_READY); } if (!validRequest(request)) { throw new SentinelClusterException(ClusterErrorMessages.BAD_REQUEST); } int xid = getCurrentId(); try { request.setId(xid); channel.writeAndFlush(request); ChannelPromise promise = channel.newPromise(); TokenClientPromiseHolder.putPromise(xid, promise); if (!promise.await(ClusterClientConfigManager.getRequestTimeout())) { throw new SentinelClusterException(ClusterErrorMessages.REQUEST_TIME_OUT); } SimpleEntry<ChannelPromise, ClusterResponse> entry = TokenClientPromiseHolder.getEntry(xid); if (entry == null || entry.getValue() == null) { // Should not go through here. throw new SentinelClusterException(ClusterErrorMessages.UNEXPECTED_STATUS); } return entry.getValue(); } finally { TokenClientPromiseHolder.remove(xid); } }
Example 4
Source File: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
@Test(timeout = 5000) public void test_qos1_send_puback_queued_messages() throws Exception { final PUBLISH publish = createPublish("topic", 1, QoS.AT_LEAST_ONCE); final PUBLISH publish2 = createPublish("topic", 2, QoS.AT_LEAST_ONCE); final PUBLISH publish3 = createPublish("topic", 3, QoS.AT_LEAST_ONCE); final ChannelPromise promise1 = channel.newPromise(); final ChannelPromise promise2 = channel.newPromise(); final ChannelPromise promise3 = channel.newPromise(); channel.writeAndFlush(publish, promise1); channel.writeAndFlush(publish2, promise2); channel.writeAndFlush(publish3, promise3); assertEquals(0, orderedTopicHandler.queue.size()); assertEquals(3, orderedTopicHandler.unacknowledgedMessages().size()); channel.pipeline().fireChannelRead(new PUBACK(1)); channel.pipeline().fireChannelRead(new PUBACK(1)); channel.pipeline().fireChannelRead(new PUBACK(2)); channel.pipeline().fireChannelRead(new PUBACK(3)); promise1.await(); promise2.await(); promise3.await(); assertEquals(0, orderedTopicHandler.queue.size()); assertEquals(0, orderedTopicHandler.unacknowledgedMessages().size()); }
Example 5
Source File: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
@Test(timeout = 4_000) public void test_remove_messages() throws Exception { InternalConfigurations.MAX_INFLIGHT_WINDOW_SIZE = 1; final PUBLISH publish1 = createPublish("topic", 1, QoS.AT_LEAST_ONCE); final PUBLISH publish2 = createPublish("topic", 2, QoS.AT_LEAST_ONCE); final PUBLISH publish3 = createPublish("topic", 3, QoS.AT_LEAST_ONCE); final PUBLISH publish4 = createPublish("topic", 4, QoS.AT_LEAST_ONCE); final ChannelPromise promise1 = channel.newPromise(); final ChannelPromise promise2 = channel.newPromise(); final ChannelPromise promise3 = channel.newPromise(); final ChannelPromise promise4 = channel.newPromise(); channel.writeAndFlush(publish1, promise1); channel.writeAndFlush(publish2, promise2); channel.writeAndFlush(publish3, promise3); channel.writeAndFlush(publish4, promise4); promise1.await(); assertEquals(3, orderedTopicHandler.queue.size()); channel.pipeline().fireChannelRead(new PUBACK(1)); promise2.await(); assertEquals(2, orderedTopicHandler.queue.size()); channel.pipeline().fireChannelRead(new PUBACK(2)); promise3.await(); channel.pipeline().fireChannelRead(new PUBACK(3)); promise4.await(); assertTrue(orderedTopicHandler.queue.isEmpty()); }
Example 6
Source File: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
@Test(timeout = 5000) public void test_qos2_release_next_message_on_next_pubcomp() throws Exception { InternalConfigurations.MAX_INFLIGHT_WINDOW_SIZE = 1; final PUBLISH publish = createPublish("topic", 1, QoS.EXACTLY_ONCE); final PUBLISH publish2 = createPublish("topic", 2, QoS.EXACTLY_ONCE); final PUBLISH publish3 = createPublish("topic", 3, QoS.EXACTLY_ONCE); final ChannelPromise promise1 = channel.newPromise(); final ChannelPromise promise2 = channel.newPromise(); final ChannelPromise promise3 = channel.newPromise(); channel.writeAndFlush(publish, promise1); channel.writeAndFlush(publish2, promise2); channel.writeAndFlush(publish3, promise3); channel.pipeline().fireChannelRead(new PUBCOMP(1)); channel.pipeline().fireChannelRead(new PUBCOMP(2)); promise1.await(); promise2.await(); promise3.await(); assertEquals(0, orderedTopicHandler.queue.size()); assertEquals(1, orderedTopicHandler.unacknowledgedMessages().size()); }
Example 7
Source File: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
@Test(timeout = 5000) public void test_qos2_release_next_message_on_failed_pubrec() throws Exception { InternalConfigurations.MAX_INFLIGHT_WINDOW_SIZE = 1; final PUBLISH publish = createPublish("topic", 1, QoS.EXACTLY_ONCE); final PUBLISH publish2 = createPublish("topic", 2, QoS.EXACTLY_ONCE); final PUBLISH publish3 = createPublish("topic", 3, QoS.EXACTLY_ONCE); final ChannelPromise promise1 = channel.newPromise(); final ChannelPromise promise2 = channel.newPromise(); final ChannelPromise promise3 = channel.newPromise(); channel.writeAndFlush(publish, promise1); channel.writeAndFlush(publish2, promise2); channel.writeAndFlush(publish3, promise3); channel.pipeline().fireChannelRead(new PUBREC(1, Mqtt5PubRecReasonCode.UNSPECIFIED_ERROR, null, Mqtt5UserProperties.NO_USER_PROPERTIES)); channel.pipeline().fireChannelRead(new PUBREC(2, Mqtt5PubRecReasonCode.UNSPECIFIED_ERROR, null, Mqtt5UserProperties.NO_USER_PROPERTIES)); promise1.await(); promise2.await(); promise3.await(); assertEquals(0, orderedTopicHandler.queue.size()); assertEquals(1, orderedTopicHandler.unacknowledgedMessages().size()); }
Example 8
Source File: NettyTransportClient.java From Sentinel with Apache License 2.0 | 5 votes |
@Override public ClusterResponse sendRequest(ClusterRequest request) throws Exception { if (!isReady()) { throw new SentinelClusterException(ClusterErrorMessages.CLIENT_NOT_READY); } if (!validRequest(request)) { throw new SentinelClusterException(ClusterErrorMessages.BAD_REQUEST); } int xid = getCurrentId(); try { request.setId(xid); channel.writeAndFlush(request); ChannelPromise promise = channel.newPromise(); TokenClientPromiseHolder.putPromise(xid, promise); if (!promise.await(ClusterClientConfigManager.getRequestTimeout())) { throw new SentinelClusterException(ClusterErrorMessages.REQUEST_TIME_OUT); } SimpleEntry<ChannelPromise, ClusterResponse> entry = TokenClientPromiseHolder.getEntry(xid); if (entry == null || entry.getValue() == null) { // Should not go through here. throw new SentinelClusterException(ClusterErrorMessages.UNEXPECTED_STATUS); } return entry.getValue(); } finally { TokenClientPromiseHolder.remove(xid); } }
Example 9
Source File: NettyConnection.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static void waitFor(ChannelPromise promise, long millis) { try { final boolean completed = promise.await(millis); if (!completed) { ActiveMQClientLogger.LOGGER.timeoutFlushingPacket(); } } catch (InterruptedException e) { throw new ActiveMQInterruptedException(e); } }
Example 10
Source File: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 4 votes |
@Test(timeout = 5000) public void test_qos1_send_puback_queued_messages_multiple_pubacks() throws Exception { channel.attr(ChannelAttributes.CLIENT_RECEIVE_MAXIMUM).set(3); final PUBLISH publish = createPublish("topic", 1, QoS.AT_LEAST_ONCE); final PUBLISH publish2 = createPublish("topic", 2, QoS.AT_LEAST_ONCE); final PUBLISH publish3 = createPublish("topic", 3, QoS.AT_LEAST_ONCE); final PUBLISH publish4 = createPublish("topic", 4, QoS.AT_LEAST_ONCE); final PUBLISH publish5 = createPublish("topic", 5, QoS.AT_LEAST_ONCE); final PUBLISH publish6 = createPublish("topic", 6, QoS.AT_LEAST_ONCE); final ChannelPromise promise1 = channel.newPromise(); final ChannelPromise promise2 = channel.newPromise(); final ChannelPromise promise3 = channel.newPromise(); final ChannelPromise promise4 = channel.newPromise(); final ChannelPromise promise5 = channel.newPromise(); final ChannelPromise promise6 = channel.newPromise(); channel.writeAndFlush(publish, promise1); channel.writeAndFlush(publish2, promise2); channel.writeAndFlush(publish3, promise3); channel.writeAndFlush(publish4, promise4); channel.writeAndFlush(publish5, promise5); channel.writeAndFlush(publish6, promise6); assertEquals(3, orderedTopicHandler.queue.size()); assertEquals(3, orderedTopicHandler.unacknowledgedMessages().size()); channel.pipeline().fireChannelRead(new PUBACK(1)); channel.pipeline().fireChannelRead(new PUBACK(1)); channel.pipeline().fireChannelRead(new PUBACK(2)); channel.pipeline().fireChannelRead(new PUBACK(3)); channel.pipeline().fireChannelRead(new PUBACK(4)); channel.pipeline().fireChannelRead(new PUBACK(4)); channel.pipeline().fireChannelRead(new PUBACK(5)); channel.pipeline().fireChannelRead(new PUBACK(5)); channel.pipeline().fireChannelRead(new PUBACK(6)); channel.pipeline().fireChannelRead(new PUBACK(6)); promise1.await(); promise2.await(); promise3.await(); promise4.await(); promise5.await(); promise6.await(); assertEquals(0, orderedTopicHandler.queue.size()); assertEquals(0, orderedTopicHandler.unacknowledgedMessages().size()); }
Example 11
Source File: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 4 votes |
@Test(timeout = 5000) public void test_qos1_return_publish_status_on_puback() throws Exception { final PUBLISH publish = createPublish("topic", 1, QoS.AT_LEAST_ONCE); final PUBLISH internalPublish = TestMessageUtil.createMqtt3Publish("hivemqId", publish); final SettableFuture<PublishStatus> future = SettableFuture.create(); final PublishWithFuture publishWithFuture = new PublishWithFuture(internalPublish, future, true); final ChannelPromise promise1 = channel.newPromise(); channel.writeAndFlush(publishWithFuture, promise1); channel.pipeline().fireChannelRead(new PUBACK(1)); promise1.await(); assertEquals(PublishStatus.DELIVERED, future.get()); }
Example 12
Source File: OrderedTopicHandlerTest.java From hivemq-community-edition with Apache License 2.0 | 4 votes |
@Test(timeout = 5000) public void test_qos2_return_publish_status_on_pubcomp() throws Exception { final PUBLISH publish = createPublish("topic", 1, QoS.EXACTLY_ONCE); final PUBLISH internalPublish = TestMessageUtil.createMqtt3Publish("hivemqId", publish); final SettableFuture<PublishStatus> future = SettableFuture.create(); final PublishWithFuture publishWithFuture = new PublishWithFuture(internalPublish, future, true); final ChannelPromise promise1 = channel.newPromise(); channel.writeAndFlush(publishWithFuture, promise1); channel.pipeline().fireChannelRead(new PUBCOMP(1)); promise1.await(); assertEquals(PublishStatus.DELIVERED, future.get()); }