Fix CachingClientConnectionFactoryTests
gatewayIntegrationTest() was stealing integrationTest()'s message. Shutdown its executor and wait for the shutdown. Also add a meaningful toString() to TcpConnectionSupport.
This commit is contained in:
@@ -395,4 +395,9 @@ public abstract class TcpConnectionSupport implements TcpConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ":" + this.connectionId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -458,13 +459,13 @@ public class CachingClientConnectionFactoryTests {
|
||||
new DirectFieldAccessor(this.clientAdapterCf).setPropertyValue("port", this.serverCf.getPort());
|
||||
|
||||
this.outbound.send(new GenericMessage<>("Hello, world!"));
|
||||
Message<?> m = inbound.receive(10000);
|
||||
Message<?> m = inbound.receive(20_000);
|
||||
assertNotNull(m);
|
||||
String connectionId = m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class);
|
||||
|
||||
// assert we use the same connection from the pool
|
||||
outbound.send(new GenericMessage<String>("Hello, world!"));
|
||||
m = inbound.receive(10000);
|
||||
m = inbound.receive(20_000);
|
||||
assertNotNull(m);
|
||||
assertEquals(connectionId, m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class));
|
||||
}
|
||||
@@ -474,7 +475,8 @@ public class CachingClientConnectionFactoryTests {
|
||||
public void gatewayIntegrationTest() throws Exception {
|
||||
final List<String> connectionIds = new ArrayList<String>();
|
||||
final AtomicBoolean okToRun = new AtomicBoolean(true);
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
exec.execute(() -> {
|
||||
while (okToRun.get()) {
|
||||
Message<?> m = inbound.receive(1000);
|
||||
if (m != null) {
|
||||
@@ -511,6 +513,8 @@ public class CachingClientConnectionFactoryTests {
|
||||
assertEquals(connectionIds.get(0), connectionIds.get(1));
|
||||
|
||||
okToRun.set(false);
|
||||
exec.shutdownNow();
|
||||
assertTrue(exec.awaitTermination(20, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user