mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-03 20:39:18 +00:00
Fixed test.
This commit is contained in:
parent
27beeff164
commit
b86ab56cfc
@ -23,7 +23,9 @@ import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.client.AbstractHttpClientServerTest;
|
||||
import org.eclipse.jetty.client.ConnectionPool;
|
||||
import org.eclipse.jetty.client.EmptyServerHandler;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.Origin;
|
||||
import org.eclipse.jetty.client.api.Connection;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
@ -33,7 +35,6 @@ import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpHeaderValue;
|
||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
@ -90,35 +91,49 @@ public class HttpDestinationOverHTTPTest extends AbstractHttpClientServerTest
|
||||
@Test
|
||||
public void test_SecondAcquire_ConcurrentWithFirstAcquire_WithEmptyQueue_CreatesTwoConnections() throws Exception
|
||||
{
|
||||
final CountDownLatch idleLatch = new CountDownLatch(1);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", connector.getLocalPort()))
|
||||
{
|
||||
@Override
|
||||
public void process(HttpConnectionOverHTTP connection)
|
||||
protected ConnectionPool newConnectionPool(HttpClient client)
|
||||
{
|
||||
try
|
||||
return new ConnectionPool(this, client.getMaxConnectionsPerDestination(), this)
|
||||
{
|
||||
latch.await(5, TimeUnit.SECONDS);
|
||||
super.process(connection);
|
||||
}
|
||||
catch (InterruptedException x)
|
||||
{
|
||||
x.printStackTrace();
|
||||
}
|
||||
@Override
|
||||
protected boolean idle(Connection connection, boolean created)
|
||||
{
|
||||
try
|
||||
{
|
||||
idleLatch.countDown();
|
||||
latch.await(5, TimeUnit.SECONDS);
|
||||
return super.idle(connection, created);
|
||||
}
|
||||
catch (InterruptedException x)
|
||||
{
|
||||
x.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
Connection connection1 = destination.acquire();
|
||||
|
||||
// There are no available existing connections, so acquire()
|
||||
// returns null because we delayed process() above
|
||||
// Make sure we entered idle().
|
||||
Assert.assertTrue(idleLatch.await(5, TimeUnit.SECONDS));
|
||||
|
||||
// There are no available existing connections, so
|
||||
// acquire() returns null because we delayed idle() above.
|
||||
Assert.assertNull(connection1);
|
||||
|
||||
// Second attempt also returns null because we delayed idle() above.
|
||||
Connection connection2 = destination.acquire();
|
||||
Assert.assertNull(connection2);
|
||||
|
||||
latch.countDown();
|
||||
|
||||
// There must be 2 idle connections
|
||||
// There must be 2 idle connections.
|
||||
Connection connection = destination.getConnectionPool().getIdleConnections().poll(5, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(connection);
|
||||
connection = destination.getConnectionPool().getIdleConnections().poll(5, TimeUnit.SECONDS);
|
||||
@ -149,7 +164,6 @@ public class HttpDestinationOverHTTPTest extends AbstractHttpClientServerTest
|
||||
Assert.assertSame(connection1, connection2);
|
||||
}
|
||||
|
||||
@Slow
|
||||
@Test
|
||||
public void test_IdleConnection_IdleTimeout() throws Exception
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user