|
15 | 15 |
|
16 | 16 | package com.rabbitmq.client.test;
|
17 | 17 |
|
| 18 | +import com.rabbitmq.client.AMQP;import com.rabbitmq.client.Command; |
18 | 19 | import com.rabbitmq.client.Method;
|
| 20 | +import com.rabbitmq.client.TrafficListener; |
19 | 21 | import com.rabbitmq.client.impl.*;
|
20 | 22 | import org.junit.jupiter.api.AfterEach;
|
21 | 23 | import org.junit.jupiter.api.BeforeEach;
|
22 | 24 | import org.junit.jupiter.api.Test;
|
23 | 25 | import org.mockito.Mockito;
|
24 | 26 |
|
25 | 27 | import java.io.IOException;
|
26 |
| -import java.util.concurrent.ExecutorService; |
27 |
| -import java.util.concurrent.Executors; |
28 |
| -import java.util.concurrent.atomic.AtomicReference; |
29 |
| -import java.util.stream.Stream; |
| 28 | +import java.util.concurrent.*; |
| 29 | +import java.util.concurrent.atomic.AtomicReference;import java.util.stream.Stream; |
30 | 30 |
|
31 | 31 | import static org.assertj.core.api.Assertions.assertThat;
|
32 | 32 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
| 33 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
33 | 34 |
|
34 | 35 | public class ChannelNTest {
|
35 | 36 |
|
@@ -67,7 +68,7 @@ public void callingBasicCancelForUnknownConsumerThrowsException() throws Excepti
|
67 | 68 | @Test
|
68 | 69 | public void qosShouldBeUnsignedShort() {
|
69 | 70 | AMQConnection connection = Mockito.mock(AMQConnection.class);
|
70 |
| - AtomicReference<com.rabbitmq.client.AMQP.Basic.Qos> qosMethod = new AtomicReference<>(); |
| 71 | + AtomicReference<AMQP.Basic.Qos> qosMethod = new AtomicReference<>(); |
71 | 72 | ChannelN channel = new ChannelN(connection, 1, consumerWorkService) {
|
72 | 73 | @Override
|
73 | 74 | public AMQCommand exnWrappingRpc(Method m) {
|
@@ -106,6 +107,30 @@ public TestConfig(int value, Consumer call, int expected) {
|
106 | 107 | });
|
107 | 108 | }
|
108 | 109 |
|
| 110 | + @Test |
| 111 | + public void confirmSelectOnlySendsRPCCallOnce() throws Exception { |
| 112 | + AMQConnection connection = Mockito.mock(AMQConnection.class); |
| 113 | + TrafficListener trafficListener = Mockito.mock(TrafficListener.class); |
| 114 | + |
| 115 | + Mockito.when(connection.getTrafficListener()).thenReturn(trafficListener); |
| 116 | + |
| 117 | + ChannelN channel = new ChannelN(connection, 1, consumerWorkService); |
| 118 | + |
| 119 | + Future<AMQImpl.Confirm.SelectOk> future = executorService.submit(() -> { |
| 120 | + try { |
| 121 | + return channel.confirmSelect(); |
| 122 | + } catch (IOException e) { |
| 123 | + throw new RuntimeException(e); |
| 124 | + } |
| 125 | + }); |
| 126 | + |
| 127 | + channel.handleCompleteInboundCommand(new AMQCommand(new AMQImpl.Confirm.SelectOk())); |
| 128 | + |
| 129 | + assertNotNull(future.get(1, TimeUnit.SECONDS)); |
| 130 | + assertNotNull(channel.confirmSelect()); |
| 131 | + Mockito.verify(trafficListener, Mockito.times(1)).write(Mockito.any(Command.class)); |
| 132 | + } |
| 133 | + |
109 | 134 | interface Consumer {
|
110 | 135 |
|
111 | 136 | void apply(int value) throws Exception;
|
|
0 commit comments