|
16 | 16 |
|
17 | 17 | package org.springframework.amqp.rabbit.connection;
|
18 | 18 |
|
| 19 | +import static org.hamcrest.Matchers.lessThan; |
19 | 20 | import static org.junit.Assert.assertEquals;
|
20 | 21 | import static org.junit.Assert.assertNotNull;
|
21 | 22 | import static org.junit.Assert.assertNotSame;
|
22 | 23 | import static org.junit.Assert.assertNull;
|
23 | 24 | import static org.junit.Assert.assertSame;
|
| 25 | +import static org.junit.Assert.assertThat; |
24 | 26 | import static org.junit.Assert.assertTrue;
|
25 | 27 | import static org.junit.Assert.fail;
|
26 | 28 | import static org.mockito.AdditionalMatchers.aryEq;
|
27 | 29 | import static org.mockito.ArgumentMatchers.any;
|
28 | 30 | import static org.mockito.ArgumentMatchers.anyInt;
|
29 | 31 | import static org.mockito.ArgumentMatchers.anyString;
|
30 | 32 | import static org.mockito.ArgumentMatchers.isNull;
|
| 33 | +import static org.mockito.BDDMockito.given; |
31 | 34 | import static org.mockito.BDDMockito.willAnswer;
|
32 | 35 | import static org.mockito.Mockito.atLeastOnce;
|
33 | 36 | import static org.mockito.Mockito.doAnswer;
|
@@ -1654,4 +1657,23 @@ public void testReturnsNormalCloseDeferredClose() throws Exception {
|
1654 | 1657 | Thread.sleep(6000);
|
1655 | 1658 | }
|
1656 | 1659 |
|
| 1660 | + @Test |
| 1661 | + public void testFirstConnectionDoesntWait() throws IOException, TimeoutException { |
| 1662 | + com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock(com.rabbitmq.client.ConnectionFactory.class); |
| 1663 | + com.rabbitmq.client.Connection mockConnection = mock(com.rabbitmq.client.Connection.class); |
| 1664 | + Channel mockChannel = mock(Channel.class); |
| 1665 | + |
| 1666 | + given(mockConnectionFactory.newConnection((ExecutorService) isNull(), anyString())).willReturn(mockConnection); |
| 1667 | + given(mockConnection.createChannel()).willReturn(mockChannel); |
| 1668 | + given(mockChannel.isOpen()).willReturn(true); |
| 1669 | + given(mockConnection.isOpen()).willReturn(true); |
| 1670 | + |
| 1671 | + CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); |
| 1672 | + ccf.setCacheMode(CacheMode.CONNECTION); |
| 1673 | + ccf.setChannelCheckoutTimeout(60000); |
| 1674 | + long t1 = System.currentTimeMillis(); |
| 1675 | + ccf.createConnection(); |
| 1676 | + assertThat(System.currentTimeMillis() - t1, lessThan(30_000L)); |
| 1677 | + } |
| 1678 | + |
1657 | 1679 | }
|
0 commit comments