|
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;
|
22 | 24 | import org.junit.jupiter.api.Test;
|
23 | 25 | import org.mockito.Mockito;
|
24 | 26 |
|
25 |
| -import java.util.concurrent.ExecutorService; |
26 |
| -import java.util.concurrent.Executors; |
| 27 | +import java.io.IOException; |
| 28 | +import java.util.concurrent.*; |
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,30 @@ 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 | + Future<AMQImpl.Confirm.SelectOk> future = executorService.submit(() -> { |
| 97 | + try { |
| 98 | + return channel.confirmSelect(); |
| 99 | + } catch (IOException e) { |
| 100 | + throw new RuntimeException(e); |
| 101 | + } |
| 102 | + }); |
| 103 | + |
| 104 | + channel.handleCompleteInboundCommand(new AMQCommand(new AMQImpl.Confirm.SelectOk())); |
| 105 | + |
| 106 | + assertNotNull(future.get(1, TimeUnit.SECONDS)); |
| 107 | + assertNotNull(channel.confirmSelect()); |
| 108 | + Mockito.verify(trafficListener, Mockito.times(1)).write(Mockito.any(Command.class)); |
| 109 | + } |
| 110 | + |
84 | 111 | interface Consumer {
|
85 | 112 |
|
86 | 113 | void apply(int value) throws Exception;
|
|
0 commit comments