|
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;
|
| 29 | +import static org.mockito.BDDMockito.given; |
27 | 30 | import static org.mockito.Matchers.any;
|
28 | 31 | import static org.mockito.Matchers.anyInt;
|
29 | 32 | import static org.mockito.Matchers.anyString;
|
@@ -1597,4 +1600,23 @@ public void testReturnsNormalCloseDeferredClose() throws Exception {
|
1597 | 1600 | Thread.sleep(6000);
|
1598 | 1601 | }
|
1599 | 1602 |
|
| 1603 | + @Test |
| 1604 | + public void testFirstConnectionDoesntWait() throws IOException, TimeoutException { |
| 1605 | + com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock(com.rabbitmq.client.ConnectionFactory.class); |
| 1606 | + com.rabbitmq.client.Connection mockConnection = mock(com.rabbitmq.client.Connection.class); |
| 1607 | + Channel mockChannel = mock(Channel.class); |
| 1608 | + |
| 1609 | + given(mockConnectionFactory.newConnection((ExecutorService) isNull(), anyString())).willReturn(mockConnection); |
| 1610 | + given(mockConnection.createChannel()).willReturn(mockChannel); |
| 1611 | + given(mockChannel.isOpen()).willReturn(true); |
| 1612 | + given(mockConnection.isOpen()).willReturn(true); |
| 1613 | + |
| 1614 | + CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); |
| 1615 | + ccf.setCacheMode(CacheMode.CONNECTION); |
| 1616 | + ccf.setChannelCheckoutTimeout(60000); |
| 1617 | + long t1 = System.currentTimeMillis(); |
| 1618 | + ccf.createConnection(); |
| 1619 | + assertThat(System.currentTimeMillis() - t1, lessThan(30_000L)); |
| 1620 | + } |
| 1621 | + |
1600 | 1622 | }
|
0 commit comments