mirror of https://github.com/apache/activemq.git
fix for https://issues.apache.org/jira/browse/AMQ-4519 - MasterLevelDBStore does not shutdown its protocol server when stopped
made fix and added test git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1480060 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ee97df7422
commit
5a299b76eb
|
@ -58,7 +58,7 @@ class MasterLevelDBStore extends LevelDBStore with ReplicatedLevelDBStoreTrait {
|
|||
|
||||
override def doStop(stopper: ServiceStopper): Unit = {
|
||||
if( transport_server!=null ) {
|
||||
transport_server.start(NOOP)
|
||||
stop_protocol_server
|
||||
transport_server = null
|
||||
}
|
||||
super.doStop(stopper)
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.leveldb.test;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.activemq.leveldb.replicated.MasterLevelDBStore;
|
||||
|
||||
import java.net.BindException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
|
||||
*/
|
||||
public class MasterLevelDBStoreTest extends TestCase {
|
||||
|
||||
public void testStoppingStoreStopsTransport() throws Exception {
|
||||
final MasterLevelDBStore store = new MasterLevelDBStore();
|
||||
store.setReplicas(0);
|
||||
|
||||
ExecutorService threads = Executors.newFixedThreadPool(1);
|
||||
threads.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
store.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// give some time to come up..
|
||||
Thread.sleep(2000);
|
||||
String address = store.transport_server().getBoundAddress();
|
||||
URI bindAddress = new URI(address);
|
||||
System.out.println(address);
|
||||
Socket socket = new Socket();
|
||||
try {
|
||||
socket.bind(new InetSocketAddress(bindAddress.getHost(), bindAddress.getPort()));
|
||||
fail("We should not have been able to connect...");
|
||||
} catch (BindException e) {
|
||||
System.out.println("Good. We cannot bind.");
|
||||
}
|
||||
|
||||
|
||||
threads.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
store.stop();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Thread.sleep(2000);
|
||||
try {
|
||||
socket.bind(new InetSocketAddress(bindAddress.getHost(), bindAddress.getPort()));
|
||||
System.out.println("Can bind, so protocol server must have been shut down.");
|
||||
|
||||
} catch (IllegalStateException e) {
|
||||
fail("Server protocol port is still opened..");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue