Skip to content

Commit 7ab3656

Browse files
committed
Fix CachingClientConnectionFactoryTests
gatewayIntegrationTest() was stealing integrationTest()'s message. Shutdown its executor and wait for the shutdown. Also add a meaningful toString() to TcpConnectionSupport.
1 parent c4bbc3b commit 7ab3656

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,9 @@ else if (logger.isWarnEnabled()) {
402402
}
403403
}
404404

405+
@Override
406+
public String toString() {
407+
return getClass().getSimpleName() + ":" + this.connectionId;
408+
}
409+
405410
}

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactoryTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.List;
4747
import java.util.concurrent.BlockingQueue;
4848
import java.util.concurrent.CountDownLatch;
49+
import java.util.concurrent.ExecutorService;
4950
import java.util.concurrent.Executors;
5051
import java.util.concurrent.Semaphore;
5152
import java.util.concurrent.TimeUnit;
@@ -457,13 +458,13 @@ public void integrationTest() throws Exception {
457458
new DirectFieldAccessor(this.clientAdapterCf).setPropertyValue("port", this.serverCf.getPort());
458459

459460
this.outbound.send(new GenericMessage<>("Hello, world!"));
460-
Message<?> m = inbound.receive(10000);
461+
Message<?> m = inbound.receive(20000);
461462
assertNotNull(m);
462463
String connectionId = m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class);
463464

464465
// assert we use the same connection from the pool
465466
outbound.send(new GenericMessage<String>("Hello, world!"));
466-
m = inbound.receive(10000);
467+
m = inbound.receive(20000);
467468
assertNotNull(m);
468469
assertEquals(connectionId, m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class));
469470
}
@@ -473,7 +474,8 @@ public void integrationTest() throws Exception {
473474
public void gatewayIntegrationTest() throws Exception {
474475
final List<String> connectionIds = new ArrayList<String>();
475476
final AtomicBoolean okToRun = new AtomicBoolean(true);
476-
Executors.newSingleThreadExecutor().execute(new Runnable() {
477+
ExecutorService exec = Executors.newSingleThreadExecutor();
478+
exec.execute(new Runnable() {
477479

478480
@Override
479481
public void run() {
@@ -515,6 +517,8 @@ public void run() {
515517
assertEquals(connectionIds.get(0), connectionIds.get(1));
516518

517519
okToRun.set(false);
520+
exec.shutdownNow();
521+
assertTrue(exec.awaitTermination(20, TimeUnit.SECONDS));
518522
}
519523

520524
@Test

0 commit comments

Comments
 (0)