Modified: qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/test/unit/client/connection/BrokerClosesClientConnectionTest.java URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/test/unit/client/connection/BrokerClosesClientConnectionTest.java?rev=1736566&r1=1736565&r2=1736566&view=diff ============================================================================== --- qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/test/unit/client/connection/BrokerClosesClientConnectionTest.java (original) +++ qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/test/unit/client/connection/BrokerClosesClientConnectionTest.java Fri Mar 25 13:04:11 2016 @@ -20,27 +20,40 @@ */ package org.apache.qpid.test.unit.client.connection; +import java.util.Collections; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.MessageProducer; import javax.jms.Queue; +import javax.jms.Session; + import org.apache.qpid.AMQConnectionClosedException; +import org.apache.qpid.AMQConnectionFailureException; import org.apache.qpid.AMQDisconnectedException; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.BasicMessageConsumer; import org.apache.qpid.client.BasicMessageProducer; +import org.apache.qpid.server.management.plugin.HttpManagement; +import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Plugin; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.systest.rest.RestTestHelper; import org.apache.qpid.test.utils.QpidBrokerTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.transport.ConnectionException; import javax.jms.Connection; import javax.jms.ExceptionListener; import javax.jms.JMSException; -import javax.jms.Session; /** * Tests the behaviour of the client when the Broker terminates client connection @@ -58,6 +71,21 @@ public class BrokerClosesClientConnectio @Override protected void setUp() throws Exception { + TestBrokerConfiguration config = getBrokerConfiguration(); + config.addHttpManagementConfiguration(); + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, getHttpManagementPort(getPort())); + config.removeObjectConfiguration(Port.class, TestBrokerConfiguration.ENTRY_NAME_JMX_PORT); + config.removeObjectConfiguration(Port.class, TestBrokerConfiguration.ENTRY_NAME_RMI_PORT); + + config.setObjectAttribute(AuthenticationProvider.class, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, + "secureOnlyMechanisms", + "{}"); + + + // set password authentication provider on http port for the tests + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); + config.setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); super.setUp(); _connection = getConnection(); @@ -86,6 +114,68 @@ public class BrokerClosesClientConnectio ensureCanCloseWithoutException(); } + public void testClientCloseOnVirtualHostStop() throws Exception + { + final String virtualHostName = TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST; + RestTestHelper restTestHelper = new RestTestHelper(getHttpManagementPort(getPort())); + restTestHelper.setUsernameAndPassword("webadmin", "webadmin"); + + final CountDownLatch connectionCreatorStarted = new CountDownLatch(1); + final AtomicBoolean shutdown = new AtomicBoolean(false); + final AtomicReference<Exception> clientException = new AtomicReference<>(); + Thread connectionCreator = new Thread(new Runnable(){ + + @Override + public void run() + { + while (!shutdown.get()) + { + try + { + getConnection(); + } + catch (Exception e) + { + clientException.set(e); + shutdown.set(true); + } + connectionCreatorStarted.countDown(); + } + } + }); + + try + { + connectionCreator.start(); + assertTrue("connection creation thread did not start in time", connectionCreatorStarted.await(20, TimeUnit.SECONDS)); + + String restHostUrl = "virtualhost/" + virtualHostName + "/" + virtualHostName; + restTestHelper.submitRequest(restHostUrl, "PUT", Collections.singletonMap("desiredState", (Object) "STOPPED"), 200); + restTestHelper.waitForAttributeChanged(restHostUrl, VirtualHost.STATE, "STOPPED"); + + int connectionCount = 0; + for (int i = 0; i < 20; ++i) + { + Map<String, Object> portObject = restTestHelper.getJsonAsSingletonList("port/" + TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT); + Map<String, Object> portStatistics = (Map<String, Object>) portObject.get("statistics"); + connectionCount = (int) portStatistics.get("connectionCount"); + if (connectionCount == 0) + { + break; + } + Thread.sleep(250); + } + assertEquals("unexpected number of connections after virtual host stopped", 0, connectionCount); + + assertConnectionCloseWasReported(clientException.get(), AMQConnectionFailureException.class); + } + finally + { + shutdown.set(true); + connectionCreator.join(10000); + } + } + public void testClientCloseOnBrokerKill() throws Exception { final Class<? extends Exception> expectedLinkedException = isBroker010() ? ConnectionException.class : AMQDisconnectedException.class; @@ -118,12 +208,11 @@ public class BrokerClosesClientConnectio } } - private void assertConnectionCloseWasReported(JMSException exception, Class<? extends Exception> linkedExceptionClass) + private void assertConnectionCloseWasReported(Exception exception, Class<? extends Exception> linkedExceptionClass) { - assertNotNull("Broker shutdown should be reported to the client via the ExceptionListener", exception); - assertNotNull("JMXException should have linked exception", exception.getLinkedException()); - - assertEquals("Unexpected linked exception", linkedExceptionClass, exception.getLinkedException().getClass()); + assertNotNull("Did not receive exception", exception); + assertNotNull("Exception should have a cause", exception.getCause()); + assertEquals("Unexpected exception cause", linkedExceptionClass, exception.getCause().getClass()); } private void assertJmsObjectsClosed()
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
