Merge branch 'jetty-9' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project into jetty-9

This commit is contained in:
Joakim Erdfelt 2012-09-17 12:19:13 -07:00
commit 6702a50e48
3 changed files with 67 additions and 3 deletions

View File

@ -253,8 +253,11 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
LOG.debug("{} released", connection);
if (client.isRunning())
{
activeConnections.remove(connection);
process(connection, false);
boolean removed = activeConnections.remove(connection);
if (removed)
process(connection, false);
else
LOG.debug("{} explicit", connection);
}
else
{

View File

@ -0,0 +1,60 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.client;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.client.api.Connection;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.util.BlockingResponseListener;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
public class HttpClientExplicitConnectionTest extends AbstractHttpClientServerTest
{
public HttpClientExplicitConnectionTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Test
public void testExplicitConnection() throws Exception
{
start(new EmptyServerHandler());
Destination destination = client.getDestination(scheme, "localhost", connector.getLocalPort());
try (Connection connection = destination.newConnection().get(5, TimeUnit.SECONDS))
{
Request request = client.newRequest(destination.host(), destination.port()).scheme(scheme);
BlockingResponseListener listener = new BlockingResponseListener();
connection.send(request, listener);
ContentResponse response = listener.get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.status());
HttpDestination httpDestination = (HttpDestination)destination;
Assert.assertTrue(httpDestination.getActiveConnections().isEmpty());
Assert.assertTrue(httpDestination.getIdleConnections().isEmpty());
}
}
}

View File

@ -114,7 +114,7 @@ public class HttpDestinationTest extends AbstractHttpClientServerTest
}
@Test
public void test_Acquire_Release_Acquire_ReturnsSameConnection() throws Exception
public void test_Acquire_Process_Release_Acquire_ReturnsSameConnection() throws Exception
{
HttpDestination destination = new HttpDestination(client, "http", "localhost", connector.getLocalPort());
Connection connection1 = destination.acquire();
@ -122,6 +122,7 @@ public class HttpDestinationTest extends AbstractHttpClientServerTest
connection1 = destination.getIdleConnections().poll(5, TimeUnit.SECONDS);
Assert.assertNotNull(connection1);
destination.process(connection1, false);
destination.release(connection1);
Connection connection2 = destination.acquire();