Fixed failing tests after moving to H2 as default store
This commit is contained in:
@@ -33,6 +33,7 @@ dependencies {
|
||||
testCompile group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version:'1.12'
|
||||
testCompile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version:'1.2.0'
|
||||
testCompile group: 'org.eclipse.jetty.websocket', name: 'websocket-client', version:'9.2.0.M1'
|
||||
testCompile group: 'com.h2database', name: 'h2', version:'1.4.191'
|
||||
|
||||
testRuntime group: 'io.netty', name: 'netty-tcnative', version: '2.0.10.Final', classifier: 'linux-x86_64'
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ public final class BrokerConstants {
|
||||
public static final String PASSWORD_FILE_PROPERTY_NAME = "password_file";
|
||||
public static final String PORT_PROPERTY_NAME = "port";
|
||||
public static final String HOST_PROPERTY_NAME = "host";
|
||||
public static final String DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME = "moquette_store.mapdb";
|
||||
public static final String DEFAULT_MOQUETTE_STORE_H2_DB_FILENAME = "moquette_store.h2";
|
||||
public static final String DEFAULT_PERSISTENT_PATH = System.getProperty("user.dir") + File.separator
|
||||
+ DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
|
||||
+ DEFAULT_MOQUETTE_STORE_H2_DB_FILENAME;
|
||||
public static final String WEB_SOCKET_PORT_PROPERTY_NAME = "websocket_port";
|
||||
public static final String WSS_PORT_PROPERTY_NAME = "secure_websocket_port";
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ public class Server {
|
||||
private volatile boolean initialized;
|
||||
private PostOffice dispatcher;
|
||||
private BrokerInterceptor interceptor;
|
||||
private H2Builder h2Builder;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
final Server server = new Server();
|
||||
@@ -162,7 +163,8 @@ public class Server {
|
||||
final ISubscriptionsRepository subscriptionsRepository;
|
||||
if (persistencePath != null && !persistencePath.isEmpty()) {
|
||||
LOG.trace("Configuring H2 subscriptions store to {}", persistencePath);
|
||||
subscriptionsRepository = new H2Builder(config, scheduler).initStore().subscriptionsRepository();
|
||||
h2Builder = new H2Builder(config, scheduler);
|
||||
subscriptionsRepository = h2Builder.initStore().subscriptionsRepository();
|
||||
} else {
|
||||
LOG.trace("Configuring in-memory subscriptions store");
|
||||
subscriptionsRepository = new MemorySubscriptionsRepository();
|
||||
@@ -324,6 +326,11 @@ public class Server {
|
||||
// and SessionsRepository does not stop its tasks. Thus shutdownNow().
|
||||
scheduler.shutdownNow();
|
||||
|
||||
if (h2Builder != null) {
|
||||
LOG.trace("Shutting down H2 persistence {}");
|
||||
h2Builder.closeStore();
|
||||
}
|
||||
|
||||
LOG.info("Moquette integration has been stopped.");
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ public final class BrokerInterceptor implements Interceptor {
|
||||
public void notifyMessageAcknowledged(final InterceptAcknowledgedMessage msg) {
|
||||
for (final InterceptHandler handler : this.handlers.get(InterceptAcknowledgedMessage.class)) {
|
||||
LOG.debug("Notifying MQTT ACK message to interceptor. CId={}, messageId={}, topic={}, interceptorId={}",
|
||||
msg.getMsg().getClientID(), msg.getPacketID(), msg.getTopic(), handler.getID());
|
||||
msg.getMsg()/*.getClientID()*/, msg.getPacketID(), msg.getTopic(), handler.getID());
|
||||
executor.execute(() -> handler.onMessageAcknowledged(msg));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,8 @@ public class H2Builder {
|
||||
public ISubscriptionsRepository subscriptionsRepository() {
|
||||
return new H2SubscriptionsRepository(mvStore);
|
||||
}
|
||||
|
||||
public void closeStore() {
|
||||
mvStore.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,54 +18,37 @@ package io.moquette.integration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Properties;
|
||||
import static io.moquette.BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
|
||||
import static io.moquette.BrokerConstants.DEFAULT_MOQUETTE_STORE_H2_DB_FILENAME;
|
||||
import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME;
|
||||
import static io.moquette.BrokerConstants.PORT_PROPERTY_NAME;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* Used to carry integration configurations.
|
||||
*/
|
||||
public final class IntegrationUtils {
|
||||
|
||||
static String localMapDBPath() {
|
||||
static String localH2MvStoreDBPath() {
|
||||
String currentDir = System.getProperty("user.dir");
|
||||
return currentDir + File.separator + "target" + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
|
||||
}
|
||||
|
||||
static String localClusterMapDBPath(int port) {
|
||||
String currentDir = System.getProperty("user.dir");
|
||||
return currentDir + File.separator + "target" + File.separator + port + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
|
||||
return currentDir + File.separator + "target" + File.separator + DEFAULT_MOQUETTE_STORE_H2_DB_FILENAME;
|
||||
}
|
||||
|
||||
public static Properties prepareTestProperties() {
|
||||
Properties testProperties = new Properties();
|
||||
testProperties.put(PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath());
|
||||
testProperties.put(PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localH2MvStoreDBPath());
|
||||
testProperties.put(PORT_PROPERTY_NAME, "1883");
|
||||
return testProperties;
|
||||
}
|
||||
|
||||
public static Properties prepareTestClusterProperties(int port) {
|
||||
Properties testProperties = new Properties();
|
||||
testProperties.put(PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localClusterMapDBPath(port));
|
||||
testProperties.put(PORT_PROPERTY_NAME, Integer.toString(port));
|
||||
return testProperties;
|
||||
}
|
||||
|
||||
/*public static void cleanPersistenceFile(IConfig config) {
|
||||
String fileName = config.getProperty(PERSISTENT_STORE_PROPERTY_NAME);
|
||||
cleanPersistenceFile(fileName);
|
||||
}
|
||||
|
||||
public static void cleanPersistenceFile(String fileName) {
|
||||
File dbFile = new File(fileName);
|
||||
if (dbFile.exists()) {
|
||||
dbFile.delete();
|
||||
new File(fileName + ".p").delete();
|
||||
new File(fileName + ".t").delete();
|
||||
}
|
||||
assertFalse(dbFile.exists());
|
||||
}*/
|
||||
|
||||
private IntegrationUtils() {
|
||||
}
|
||||
|
||||
public static void clearTestStorage() {
|
||||
String dbPath = localH2MvStoreDBPath();
|
||||
File dbFile = new File(dbPath);
|
||||
if (dbFile.exists()) {
|
||||
dbFile.delete();
|
||||
}
|
||||
assertFalse(dbFile.exists());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServerIntegrationDBAuthenticatorTest {
|
||||
@@ -99,6 +101,8 @@ public class ServerIntegrationDBAuthenticatorTest {
|
||||
}
|
||||
|
||||
stopServer();
|
||||
|
||||
IntegrationUtils.clearTestStorage();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
||||
@@ -68,6 +68,8 @@ public class ServerIntegrationFuseTest {
|
||||
}
|
||||
|
||||
m_server.stopServer();
|
||||
|
||||
IntegrationUtils.clearTestStorage();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ServerIntegrationOpenSSLTest extends ServerIntegrationSSLTest {
|
||||
sslProps.put(BrokerConstants.JKS_PATH_PROPERTY_NAME, "serverkeystore.jks");
|
||||
sslProps.put(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME, "passw0rdsrv");
|
||||
sslProps.put(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "passw0rdsrv");
|
||||
sslProps.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath());
|
||||
sslProps.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localH2MvStoreDBPath());
|
||||
m_server.startServer(sslProps);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@ public class ServerIntegrationPahoTest {
|
||||
}
|
||||
|
||||
stopServer();
|
||||
|
||||
IntegrationUtils.clearTestStorage();
|
||||
}
|
||||
|
||||
private void stopServer() {
|
||||
|
||||
@@ -82,6 +82,8 @@ public class ServerIntegrationRestartTest {
|
||||
}
|
||||
|
||||
m_server.stopServer();
|
||||
|
||||
IntegrationUtils.clearTestStorage();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-8
@@ -142,14 +142,14 @@ public class ServerIntegrationSSLClientAuthTest {
|
||||
sslProps.put(BrokerConstants.JKS_PATH_PROPERTY_NAME, "signedserverkeystore.jks");
|
||||
sslProps.put(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME, "passw0rdsrv");
|
||||
sslProps.put(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "passw0rdsrv");
|
||||
sslProps.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath());
|
||||
sslProps.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localH2MvStoreDBPath());
|
||||
sslProps.put(BrokerConstants.NEED_CLIENT_AUTH, "true");
|
||||
m_server.startServer(sslProps);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
String dbPath = IntegrationUtils.localMapDBPath();
|
||||
String dbPath = IntegrationUtils.localH2MvStoreDBPath();
|
||||
File dbFile = new File(dbPath);
|
||||
assertFalse(String.format("The DB storagefile %s already exists", dbPath), dbFile.exists());
|
||||
|
||||
@@ -171,12 +171,7 @@ public class ServerIntegrationSSLClientAuthTest {
|
||||
if (m_server != null) {
|
||||
m_server.stopServer();
|
||||
}
|
||||
String dbPath = IntegrationUtils.localMapDBPath();
|
||||
File dbFile = new File(dbPath);
|
||||
if (dbFile.exists()) {
|
||||
dbFile.delete();
|
||||
}
|
||||
assertFalse(dbFile.exists());
|
||||
IntegrationUtils.clearTestStorage();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -90,13 +90,13 @@ public class ServerIntegrationSSLTest {
|
||||
sslProps.put(BrokerConstants.JKS_PATH_PROPERTY_NAME, "serverkeystore.jks");
|
||||
sslProps.put(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME, "passw0rdsrv");
|
||||
sslProps.put(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "passw0rdsrv");
|
||||
sslProps.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath());
|
||||
sslProps.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localH2MvStoreDBPath());
|
||||
m_server.startServer(sslProps);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
String dbPath = IntegrationUtils.localMapDBPath();
|
||||
String dbPath = IntegrationUtils.localH2MvStoreDBPath();
|
||||
File dbFile = new File(dbPath);
|
||||
assertFalse(String.format("The DB storagefile %s already exists", dbPath), dbFile.exists());
|
||||
|
||||
@@ -118,12 +118,7 @@ public class ServerIntegrationSSLTest {
|
||||
if (m_server != null) {
|
||||
m_server.stopServer();
|
||||
}
|
||||
String dbPath = IntegrationUtils.localMapDBPath();
|
||||
File dbFile = new File(dbPath);
|
||||
if (dbFile.exists()) {
|
||||
dbFile.delete();
|
||||
}
|
||||
assertFalse(dbFile.exists());
|
||||
IntegrationUtils.clearTestStorage();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user