Moved test of MapDBPersistenceStore into the test unit
This commit is contained in:
@@ -59,7 +59,7 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
|
|||||||
private DB m_db;
|
private DB m_db;
|
||||||
private String m_storePath;
|
private String m_storePath;
|
||||||
|
|
||||||
private final ScheduledExecutorService m_scheduler = Executors.newScheduledThreadPool(1);
|
protected final ScheduledExecutorService m_scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The default constructor will create an in memory store as no file path was specified
|
* The default constructor will create an in memory store as no file path was specified
|
||||||
@@ -311,6 +311,10 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
if (this.m_db.isClosed()) {
|
||||||
|
LOG.debug("already closed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.m_db.commit();
|
this.m_db.commit();
|
||||||
LOG.debug("persisted subscriptions {}", m_persistentSubscriptions);
|
LOG.debug("persisted subscriptions {}", m_persistentSubscriptions);
|
||||||
this.m_db.close();
|
this.m_db.close();
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2012-2015 The original author or authors
|
|
||||||
* ------------------------------------------------------
|
|
||||||
* 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.moquette.server;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This tests that the broker shuts down properly and all the threads it creates are closed.
|
|
||||||
*
|
|
||||||
* @author kazvictor
|
|
||||||
*/
|
|
||||||
public class ServerShutdownTest {
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ServerShutdownTest.class);
|
|
||||||
|
|
||||||
private final ScheduledExecutorService threadCounter = Executors.newScheduledThreadPool(1);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testShutdown() throws IOException, InterruptedException {
|
|
||||||
final int initialThreadCount = Thread.activeCount();
|
|
||||||
LOG.info("*** testShutdown ***");
|
|
||||||
LOG.debug("Initial threads count {}", initialThreadCount);
|
|
||||||
|
|
||||||
//Start the server
|
|
||||||
Server broker = new Server();
|
|
||||||
broker.startServer();
|
|
||||||
//stop the server
|
|
||||||
broker.stopServer();
|
|
||||||
|
|
||||||
//wait till the thread count is back to the initial thread count
|
|
||||||
final CountDownLatch threadsStoppedLatch = new CountDownLatch(1);
|
|
||||||
threadCounter.scheduleAtFixedRate(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
int threadCount = Thread.activeCount();
|
|
||||||
LOG.debug("Current Thread Count = " + threadCount);
|
|
||||||
//plus 1 for this thread
|
|
||||||
if (threadCount == initialThreadCount + 1) {
|
|
||||||
threadsStoppedLatch.countDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, 100, TimeUnit.MILLISECONDS);
|
|
||||||
|
|
||||||
//wait till the countdown latch is triggered. Either the threads stop or the timeout is readed.
|
|
||||||
boolean threadsStopped = threadsStoppedLatch.await(5, TimeUnit.SECONDS);
|
|
||||||
//shutdown the threadCounter.
|
|
||||||
threadCounter.shutdown();
|
|
||||||
|
|
||||||
assertTrue("Broker did not shutdown properly. Not all broker threads were stopped.", threadsStopped);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+9
-1
@@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* You may elect to redistribute this code under either of these licenses.
|
* You may elect to redistribute this code under either of these licenses.
|
||||||
*/
|
*/
|
||||||
package org.eclipse.moquette.spi.impl;
|
package org.eclipse.moquette.spi.persistence;
|
||||||
|
|
||||||
import org.eclipse.moquette.proto.messages.AbstractMessage;
|
import org.eclipse.moquette.proto.messages.AbstractMessage;
|
||||||
import org.eclipse.moquette.spi.impl.subscriptions.Subscription;
|
import org.eclipse.moquette.spi.impl.subscriptions.Subscription;
|
||||||
@@ -102,4 +102,12 @@ public class MapDBPersistentStoreTest {
|
|||||||
packetId = m_storageService.nextPacketID("CLIENT");
|
packetId = m_storageService.nextPacketID("CLIENT");
|
||||||
assertEquals(1, packetId);
|
assertEquals(1, packetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCloseShutdownCommitTask() {
|
||||||
|
m_storageService.close();
|
||||||
|
|
||||||
|
//verify the executor is shutdown
|
||||||
|
assertTrue(m_storageService.m_scheduler.isTerminated());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user