File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
main/java/org/springframework/amqp/rabbit/connection
test/java/org/springframework/amqp/rabbit/connection Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -719,7 +719,7 @@ else if (this.cacheMode == CacheMode.CONNECTION) {
719
719
private Connection connectionFromCache () {
720
720
ChannelCachingConnectionProxy cachedConnection = findIdleConnection ();
721
721
long now = System .currentTimeMillis ();
722
- if (cachedConnection == null ) {
722
+ if (cachedConnection == null && countOpenConnections () >= this . connectionLimit ) {
723
723
cachedConnection = waitForConnection (now );
724
724
}
725
725
if (cachedConnection == null ) {
Original file line number Diff line number Diff line change @@ -1791,4 +1791,23 @@ public void testOrderlyShutDown() throws Exception {
1791
1791
closeExec .shutdownNow ();
1792
1792
}
1793
1793
1794
+ @ Test
1795
+ public void testFirstConnectionDoesntWait () throws IOException , TimeoutException {
1796
+ com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock (com .rabbitmq .client .ConnectionFactory .class );
1797
+ com .rabbitmq .client .Connection mockConnection = mock (com .rabbitmq .client .Connection .class );
1798
+ Channel mockChannel = mock (Channel .class );
1799
+
1800
+ given (mockConnectionFactory .newConnection ((ExecutorService ) isNull (), anyString ())).willReturn (mockConnection );
1801
+ given (mockConnection .createChannel ()).willReturn (mockChannel );
1802
+ given (mockChannel .isOpen ()).willReturn (true );
1803
+ given (mockConnection .isOpen ()).willReturn (true );
1804
+
1805
+ CachingConnectionFactory ccf = new CachingConnectionFactory (mockConnectionFactory );
1806
+ ccf .setCacheMode (CacheMode .CONNECTION );
1807
+ ccf .setChannelCheckoutTimeout (60000 );
1808
+ long t1 = System .currentTimeMillis ();
1809
+ ccf .createConnection ();
1810
+ assertThat (System .currentTimeMillis () - t1 ).isLessThan (30_000 );
1811
+ }
1812
+
1794
1813
}
You can’t perform that action at this time.
0 commit comments