Moved test of MapDBPersistenceStore into the test unit

This commit is contained in:
andsel
2015-09-29 22:07:45 +02:00
parent 9effc1edb5
commit b7169271ac
3 changed files with 14 additions and 75 deletions
@@ -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);
}
}
@@ -13,7 +13,7 @@
*
* 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.spi.impl.subscriptions.Subscription;
@@ -102,4 +102,12 @@ public class MapDBPersistentStoreTest {
packetId = m_storageService.nextPacketID("CLIENT");
assertEquals(1, packetId);
}
@Test
public void testCloseShutdownCommitTask() {
m_storageService.close();
//verify the executor is shutdown
assertTrue(m_storageService.m_scheduler.isTerminated());
}
}