|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.activemq.transport.ws; |
| 18 | + |
| 19 | +import org.apache.activemq.broker.BrokerService; |
| 20 | +import org.apache.activemq.broker.jmx.ConnectorViewMBean; |
| 21 | +import org.apache.activemq.util.Wait; |
| 22 | +import org.junit.Before; |
| 23 | +import org.junit.Test; |
| 24 | + |
| 25 | +import javax.management.ObjectName; |
| 26 | +import java.util.concurrent.TimeUnit; |
| 27 | + |
| 28 | +import static org.junit.Assert.assertTrue; |
| 29 | + |
| 30 | +public class WSConnectorJMXTest { |
| 31 | + |
| 32 | + private BrokerService broker; |
| 33 | + |
| 34 | + @Before |
| 35 | + public void setUp() throws Exception { |
| 36 | + broker = new BrokerService(); |
| 37 | + broker.setDeleteAllMessagesOnStartup(true); |
| 38 | + broker.setPersistent(true); |
| 39 | + broker.setUseJmx(true); |
| 40 | + broker.addConnector("ws://localhost:0").setName("Default"); |
| 41 | + broker.setBrokerName("localhost"); |
| 42 | + broker.start(); |
| 43 | + broker.waitUntilStarted(30_000); |
| 44 | + broker.deleteAllMessages(); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testRestartConnection() throws Exception { |
| 49 | + Thread.currentThread().setContextClassLoader(new ClassLoader(null) {}); |
| 50 | + |
| 51 | + ConnectorViewMBean connectionView = getProxyToConnectionView(); |
| 52 | + connectionView.stop(); |
| 53 | + assertTrue("Connection should close", Wait.waitFor(() -> !connectionView.isStarted(), |
| 54 | + TimeUnit.SECONDS.toMillis(60), 500)); |
| 55 | + connectionView.start(); |
| 56 | + assertTrue("Connection should open", Wait.waitFor(connectionView::isStarted, |
| 57 | + TimeUnit.SECONDS.toMillis(60), 500)); |
| 58 | + } |
| 59 | + |
| 60 | + protected ConnectorViewMBean getProxyToConnectionView() throws Exception { |
| 61 | + ObjectName connectorQuery = new ObjectName( |
| 62 | + "org.apache.activemq:type=Broker,brokerName=localhost,connector=clientConnectors,connectorName=Default"); |
| 63 | + |
| 64 | + return (ConnectorViewMBean) broker.getManagementContext() |
| 65 | + .newProxyInstance(connectorQuery, ConnectorViewMBean.class, true); |
| 66 | + } |
| 67 | +} |
0 commit comments