|
15 | 15 |
|
16 | 16 | package com.rabbitmq.client.test;
|
17 | 17 |
|
| 18 | +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;
|
|
26 | 28 | import java.util.concurrent.Executors;
|
27 | 29 | import java.util.stream.Stream;
|
28 | 30 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
| 31 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
29 | 32 |
|
30 | 33 | public class ChannelNTest {
|
31 | 34 |
|
@@ -81,6 +84,29 @@ public TestConfig(int value, Consumer call) {
|
81 | 84 | .forEach(config -> assertThatThrownBy(() -> config.call.apply(config.value)).isInstanceOf(IllegalArgumentException.class));
|
82 | 85 | }
|
83 | 86 |
|
| 87 | + @Test |
| 88 | + public void confirmSelectOnlySendsRPCCallOnce() throws Exception { |
| 89 | + AMQConnection connection = Mockito.mock(AMQConnection.class); |
| 90 | + TrafficListener trafficListener = Mockito.mock(TrafficListener.class); |
| 91 | + |
| 92 | + Mockito.when(connection.getTrafficListener()).thenReturn(trafficListener); |
| 93 | + |
| 94 | + ChannelN channel = new ChannelN(connection, 1, consumerWorkService); |
| 95 | + |
| 96 | + new Thread(() -> { |
| 97 | + try { |
| 98 | + Thread.sleep(15); |
| 99 | + channel.handleCompleteInboundCommand(new AMQCommand(new AMQImpl.Confirm.SelectOk())); |
| 100 | + } catch (Exception e) { |
| 101 | + throw new RuntimeException(e); |
| 102 | + } |
| 103 | + }).start(); |
| 104 | + |
| 105 | + assertNotNull(channel.confirmSelect()); |
| 106 | + assertNotNull(channel.confirmSelect()); |
| 107 | + Mockito.verify(trafficListener, Mockito.times(1)).write(Mockito.any(Command.class)); |
| 108 | + } |
| 109 | + |
84 | 110 | interface Consumer {
|
85 | 111 |
|
86 | 112 | void apply(int value) throws Exception;
|
|
0 commit comments