Fix TCP Gateway Integration Test

Definitively wait for the connection to be returned instead of a simple sleep.
This commit is contained in:
Gary Russell
2015-05-27 10:19:38 -04:00
parent 22fb524515
commit d17785db12

View File

@@ -43,6 +43,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
@@ -61,6 +62,7 @@ import org.mockito.stubbing.Answer;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.integration.channel.QueueChannel;
@@ -111,6 +113,10 @@ public class CachingClientConnectionFactoryTests {
@Autowired
PollableChannel fromGateway;
@Autowired
@Qualifier("gateway.caching.ccf")
CachingClientConnectionFactory gatewayCF;
@Test
public void testReuse() throws Exception {
AbstractClientConnectionFactory factory = mock(AbstractClientConnectionFactory.class);
@@ -476,8 +482,13 @@ public class CachingClientConnectionFactoryTests {
assertNotNull(m);
assertEquals("foo:" + "Hello, world!", new String((byte[]) m.getPayload()));
// wait a short time to allow the connection to be returned to the pool
Thread.sleep(1000);
BlockingQueue<?> connections = TestUtils
.getPropertyValue(this.gatewayCF, "pool.available", BlockingQueue.class);
// wait until the connection is returned to the pool
int n = 0;
while (n++ < 100 && connections.size() == 0) {
Thread.sleep(100);
}
// assert we use the same connection from the pool
toGateway.send(new GenericMessage<String>("Hello, world2!"));