From 560559fad263696f755bb227ec2f3a95cfcfeff8 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 22 Aug 2015 15:35:11 +0200 Subject: [PATCH] Abstracted configuration part to use filesystem or classpath files --- .../moquette/server/ClasspathConfig.java | 68 +++++++++++++++++++ .../moquette/server/ConfigurationParser.java | 16 +---- .../moquette/server/FilesystemConfig.java | 68 +++++++++++++++++++ .../org/eclipse/moquette/server/IConfig.java | 29 ++++++++ .../eclipse/moquette/server/MemoryConfig.java | 66 ++++++++++++++++++ .../org/eclipse/moquette/server/Server.java | 48 ++++++------- .../moquette/server/ServerAcceptor.java | 2 +- .../moquette/server/netty/NettyAcceptor.java | 15 ++-- .../moquette/spi/impl/SimpleMessaging.java | 7 +- .../server/ConfigurationClassLoaderTest.java | 11 ++- .../server/ConfigurationParserTest.java | 2 +- .../server/ServerIntegrationFuseTest.java | 8 ++- .../server/ServerIntegrationPahoTest.java | 7 +- .../ServerIntegrationQoSValidationTest.java | 7 +- .../ServerIntegrationWebSocketTest.java | 7 +- ...erverLowlevelMessagesIntegrationTests.java | 8 ++- .../server/ServerRestartIntegrationTest.java | 10 +-- .../testembedded/EmbeddedLauncher.java | 6 +- 18 files changed, 309 insertions(+), 76 deletions(-) create mode 100644 broker/src/main/java/org/eclipse/moquette/server/ClasspathConfig.java create mode 100644 broker/src/main/java/org/eclipse/moquette/server/FilesystemConfig.java create mode 100644 broker/src/main/java/org/eclipse/moquette/server/IConfig.java create mode 100644 broker/src/main/java/org/eclipse/moquette/server/MemoryConfig.java diff --git a/broker/src/main/java/org/eclipse/moquette/server/ClasspathConfig.java b/broker/src/main/java/org/eclipse/moquette/server/ClasspathConfig.java new file mode 100644 index 00000000..40e2d1b7 --- /dev/null +++ b/broker/src/main/java/org/eclipse/moquette/server/ClasspathConfig.java @@ -0,0 +1,68 @@ +/* + * 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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.text.ParseException; +import java.util.Properties; + +/** + * Configuration that loads file from the classpath + * + * @author andrea + */ +public class ClasspathConfig implements IConfig { + + private static final Logger LOG = LoggerFactory.getLogger(ClasspathConfig.class); + + private final Properties m_properties; + + public ClasspathConfig() { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + InputStream is = classLoader.getResourceAsStream("config/moquette.conf"); + if (is == null) { + throw new RuntimeException("Can't locate the resourse \"config/moquette.conf\""); + } + Reader configReader = new InputStreamReader(is); + ConfigurationParser confParser = new ConfigurationParser(); + try { + confParser.parse(configReader); + } catch (ParseException pex) { + LOG.warn("An error occurred in parsing configuration, fallback on default configuration", pex); + } + m_properties = confParser.getProperties(); + } + + @Override + public void setProperty(String name, String value) { + m_properties.setProperty(name, value); + } + + @Override + public String getProperty(String name) { + return m_properties.getProperty(name); + } + + @Override + public String getProperty(String name, String defaultValue) { + return m_properties.getProperty(name, defaultValue); + } +} diff --git a/broker/src/main/java/org/eclipse/moquette/server/ConfigurationParser.java b/broker/src/main/java/org/eclipse/moquette/server/ConfigurationParser.java index 5e3a8a31..1a76aecf 100644 --- a/broker/src/main/java/org/eclipse/moquette/server/ConfigurationParser.java +++ b/broker/src/main/java/org/eclipse/moquette/server/ConfigurationParser.java @@ -43,16 +43,6 @@ class ConfigurationParser { createDefaults(); } - /** - * Crate a ConfigurationParser merging the default properties with the provided ones. - * */ - ConfigurationParser(Properties properties) { - this(); - for (Entry entrySet : properties.entrySet()) { - m_properties.put(entrySet.getKey(), entrySet.getValue()); - } - } - private void createDefaults() { m_properties.put(PORT_PROPERTY_NAME, Integer.toString(PORT)); m_properties.put(HOST_PROPERTY_NAME, HOST); @@ -117,9 +107,9 @@ class ConfigurationParser { } //split till the first space - int deilimiterIdx = line.indexOf(' '); - String key = line.substring(0, deilimiterIdx).trim(); - String value = line.substring(deilimiterIdx).trim(); + int delimiterIdx = line.indexOf(' '); + String key = line.substring(0, delimiterIdx).trim(); + String value = line.substring(delimiterIdx).trim(); m_properties.put(key, value); } diff --git a/broker/src/main/java/org/eclipse/moquette/server/FilesystemConfig.java b/broker/src/main/java/org/eclipse/moquette/server/FilesystemConfig.java new file mode 100644 index 00000000..26ca4672 --- /dev/null +++ b/broker/src/main/java/org/eclipse/moquette/server/FilesystemConfig.java @@ -0,0 +1,68 @@ +/* + * 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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.text.ParseException; +import java.util.Properties; + +/** + * Configuration that loads file from the file system + * + * @author andrea + */ +public class FilesystemConfig implements IConfig { + private static final Logger LOG = LoggerFactory.getLogger(FilesystemConfig.class); + + private final Properties m_properties; + + public FilesystemConfig(File file) { + ConfigurationParser confParser = new ConfigurationParser(); + try { + confParser.parse(file); + } catch (ParseException pex) { + LOG.warn("An error occurred in parsing configuration, fallback on default configuration", pex); + } + m_properties = confParser.getProperties(); + } + + public FilesystemConfig() { + this(defaultConfigFile()); + } + + private static File defaultConfigFile() { + String configPath = System.getProperty("moquette.path", null); + return new File(configPath, "config/moquette.conf"); + } + + @Override + public void setProperty(String name, String value) { + m_properties.setProperty(name, value); + } + + @Override + public String getProperty(String name) { + return m_properties.getProperty(name); + } + + @Override + public String getProperty(String name, String defaultValue) { + return m_properties.getProperty(name, defaultValue); + } +} diff --git a/broker/src/main/java/org/eclipse/moquette/server/IConfig.java b/broker/src/main/java/org/eclipse/moquette/server/IConfig.java new file mode 100644 index 00000000..b3281ce9 --- /dev/null +++ b/broker/src/main/java/org/eclipse/moquette/server/IConfig.java @@ -0,0 +1,29 @@ +/* + * 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; + +/** + * Base interface for all configuration implementations (filesystem, memory or classpath) + * + * @author andrea + */ +public interface IConfig { + void setProperty(String name, String value); + + String getProperty(String name); + + String getProperty(String name, String defaultValue); +} diff --git a/broker/src/main/java/org/eclipse/moquette/server/MemoryConfig.java b/broker/src/main/java/org/eclipse/moquette/server/MemoryConfig.java new file mode 100644 index 00000000..8e5150b2 --- /dev/null +++ b/broker/src/main/java/org/eclipse/moquette/server/MemoryConfig.java @@ -0,0 +1,66 @@ +/* + * 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 java.util.Map; +import java.util.Properties; + +import static org.eclipse.moquette.commons.Constants.*; +import static org.eclipse.moquette.commons.Constants.AUTHENTICATOR_CLASS_NAME; +import static org.eclipse.moquette.commons.Constants.AUTHORIZATOR_CLASS_NAME; + +/** + * Configuration backed by memory. + * + * @author andrea + */ +public class MemoryConfig implements IConfig { + + private final Properties m_properties = new Properties(); + + public MemoryConfig(Properties properties) { + createDefaults(); + for (Map.Entry entrySet : properties.entrySet()) { + m_properties.put(entrySet.getKey(), entrySet.getValue()); + } + } + + private void createDefaults() { + m_properties.put(PORT_PROPERTY_NAME, Integer.toString(PORT)); + m_properties.put(HOST_PROPERTY_NAME, HOST); + m_properties.put(WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(WEBSOCKET_PORT)); + m_properties.put(PASSWORD_FILE_PROPERTY_NAME, ""); + m_properties.put(PERSISTENT_STORE_PROPERTY_NAME, DEFAULT_PERSISTENT_PATH); + m_properties.put(ALLOW_ANONYMOUS_PROPERTY_NAME, true); + m_properties.put(AUTHENTICATOR_CLASS_NAME, ""); + m_properties.put(AUTHORIZATOR_CLASS_NAME, ""); + } + + @Override + public void setProperty(String name, String value) { + m_properties.setProperty(name, value); + } + + @Override + public String getProperty(String name) { + return m_properties.getProperty(name); + } + + @Override + public String getProperty(String name, String defaultValue) { + return m_properties.getProperty(name, defaultValue); + } +} diff --git a/broker/src/main/java/org/eclipse/moquette/server/Server.java b/broker/src/main/java/org/eclipse/moquette/server/Server.java index 4cf80b4b..76687270 100644 --- a/broker/src/main/java/org/eclipse/moquette/server/Server.java +++ b/broker/src/main/java/org/eclipse/moquette/server/Server.java @@ -15,7 +15,6 @@ */ package org.eclipse.moquette.server; -import org.eclipse.moquette.interception.InterceptHandler; import org.eclipse.moquette.server.netty.NettyAcceptor; import org.eclipse.moquette.spi.impl.SimpleMessaging; import org.slf4j.Logger; @@ -23,7 +22,6 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.text.ParseException; import java.util.Properties; import static org.eclipse.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; @@ -37,8 +35,7 @@ public class Server { private ServerAcceptor m_acceptor; SimpleMessaging messaging; - Properties m_properties; - + public static void main(String[] args) throws IOException { final Server server = new Server(); server.startServer(); @@ -54,27 +51,20 @@ public class Server { /** * Starts Moquette bringing the configuration from the file - * located at config/moquette.conf + * located at m_config/moquette.conf */ public void startServer() throws IOException { - String configPath = System.getProperty("moquette.path", null); - startServer(new File(configPath, "config/moquette.conf")); + final IConfig config = new FilesystemConfig(); + startServer(config); } /** * Starts Moquette bringing the configuration from the given file */ public void startServer(File configFile) throws IOException { - LOG.info("Using config file: " + configFile.getAbsolutePath()); - - ConfigurationParser confParser = new ConfigurationParser(); - try { - confParser.parse(configFile); - } catch (ParseException pex) { - LOG.warn("An error occurred in parsing configuration, fallback on default configuration", pex); - } - m_properties = confParser.getProperties(); - startServer(m_properties); + LOG.info("Using m_config file: " + configFile.getAbsolutePath()); + final IConfig config = new FilesystemConfig(configFile); + startServer(config); } /** @@ -87,18 +77,24 @@ public class Server { * */ public void startServer(Properties configProps) throws IOException { - ConfigurationParser confParser = new ConfigurationParser(configProps); - m_properties = confParser.getProperties(); + final IConfig config = new MemoryConfig(configProps); + startServer(config); + } + + /** + * Starts Moquette bringing the configuration files from the given Config implementation. + */ + public void startServer(IConfig config) throws IOException { final String handlerProp = System.getProperty("intercept.handler"); if (handlerProp != null) { - m_properties.setProperty("intercept.handler", handlerProp); + config.setProperty("intercept.handler", handlerProp); } - LOG.info("Persistent store file: " + m_properties.get(PERSISTENT_STORE_PROPERTY_NAME)); + LOG.info("Persistent store file: " + config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); messaging = SimpleMessaging.getInstance(); - messaging.init(m_properties); - + messaging.init(config); + m_acceptor = new NettyAcceptor(); - m_acceptor.initialize(messaging, m_properties); + m_acceptor.initialize(messaging, config); } public void stopServer() { @@ -107,8 +103,4 @@ public class Server { messaging.stop(); LOG.info("Server stopped"); } - - public Properties getProperties() { - return m_properties; - } } diff --git a/broker/src/main/java/org/eclipse/moquette/server/ServerAcceptor.java b/broker/src/main/java/org/eclipse/moquette/server/ServerAcceptor.java index 147bcbe9..51e4ea12 100644 --- a/broker/src/main/java/org/eclipse/moquette/server/ServerAcceptor.java +++ b/broker/src/main/java/org/eclipse/moquette/server/ServerAcceptor.java @@ -25,7 +25,7 @@ import org.eclipse.moquette.spi.IMessaging; */ public interface ServerAcceptor { - void initialize(IMessaging messaging, Properties props) throws IOException; + void initialize(IMessaging messaging, IConfig props) throws IOException; void close(); } diff --git a/broker/src/main/java/org/eclipse/moquette/server/netty/NettyAcceptor.java b/broker/src/main/java/org/eclipse/moquette/server/netty/NettyAcceptor.java index 36dd03a7..08c233b8 100644 --- a/broker/src/main/java/org/eclipse/moquette/server/netty/NettyAcceptor.java +++ b/broker/src/main/java/org/eclipse/moquette/server/netty/NettyAcceptor.java @@ -42,14 +42,13 @@ import java.security.*; import java.security.cert.CertificateException; import java.util.List; -import java.util.Properties; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; -import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Future; import org.eclipse.moquette.commons.Constants; +import org.eclipse.moquette.server.IConfig; import org.eclipse.moquette.spi.IMessaging; import org.eclipse.moquette.parser.netty.MQTTDecoder; import org.eclipse.moquette.parser.netty.MQTTEncoder; @@ -101,7 +100,7 @@ public class NettyAcceptor implements ServerAcceptor { MessageMetricsCollector m_metricsCollector = new MessageMetricsCollector(); @Override - public void initialize(IMessaging messaging, Properties props) throws IOException { + public void initialize(IMessaging messaging, IConfig props) throws IOException { m_bossGroup = new NioEventLoopGroup(); m_workerGroup = new NioEventLoopGroup(); @@ -150,7 +149,7 @@ public class NettyAcceptor implements ServerAcceptor { } } - private void initializePlainTCPTransport(IMessaging messaging, Properties props) throws IOException { + private void initializePlainTCPTransport(IMessaging messaging, IConfig props) throws IOException { final NettyMQTTHandler handler = new NettyMQTTHandler(); handler.setMessaging(messaging); String host = props.getProperty(Constants.HOST_PROPERTY_NAME); @@ -170,7 +169,7 @@ public class NettyAcceptor implements ServerAcceptor { }); } - private void initializeWebSocketTransport(IMessaging messaging, Properties props) throws IOException { + private void initializeWebSocketTransport(IMessaging messaging, IConfig props) throws IOException { String webSocketPortProp = props.getProperty(Constants.WEB_SOCKET_PORT_PROPERTY_NAME); if (webSocketPortProp == null) { //Do nothing no WebSocket configured @@ -204,7 +203,7 @@ public class NettyAcceptor implements ServerAcceptor { }); } - private void initializeSSLTCPTransport(IMessaging messaging, Properties props, final SslHandler sslHandler) throws IOException { + private void initializeSSLTCPTransport(IMessaging messaging, IConfig props, final SslHandler sslHandler) throws IOException { String sslPortProp = props.getProperty(Constants.SSL_PORT_PROPERTY_NAME); if (sslPortProp == null) { //Do nothing no SSL configured @@ -234,7 +233,7 @@ public class NettyAcceptor implements ServerAcceptor { }); } - private void initializeWSSTransport(IMessaging messaging, Properties props, final SslHandler sslHandler) throws IOException { + private void initializeWSSTransport(IMessaging messaging, IConfig props, final SslHandler sslHandler) throws IOException { String sslPortProp = props.getProperty(Constants.WSS_PORT_PROPERTY_NAME); if (sslPortProp == null) { //Do nothing no SSL configured @@ -296,7 +295,7 @@ public class NettyAcceptor implements ServerAcceptor { } - private SslHandler initSSLHandler(Properties props) { + private SslHandler initSSLHandler(IConfig props) { final String jksPath = props.getProperty(Constants.JKS_PATH_PROPERTY_NAME); LOG.info("Starting SSL using keystore at {}", jksPath); if (jksPath == null || jksPath.isEmpty()) { diff --git a/broker/src/main/java/org/eclipse/moquette/spi/impl/SimpleMessaging.java b/broker/src/main/java/org/eclipse/moquette/spi/impl/SimpleMessaging.java index 4f7ec458..d61d764b 100644 --- a/broker/src/main/java/org/eclipse/moquette/spi/impl/SimpleMessaging.java +++ b/broker/src/main/java/org/eclipse/moquette/spi/impl/SimpleMessaging.java @@ -22,6 +22,7 @@ import io.netty.util.internal.StringUtil; import org.HdrHistogram.Histogram; import org.eclipse.moquette.interception.InterceptHandler; import org.eclipse.moquette.proto.messages.AbstractMessage; +import org.eclipse.moquette.server.IConfig; import org.eclipse.moquette.spi.impl.security.*; import org.eclipse.moquette.server.ServerChannel; import org.eclipse.moquette.spi.IMessagesStore; @@ -99,7 +100,7 @@ public class SimpleMessaging implements IMessaging, EventHandler { return INSTANCE; } - public void init(Properties configProps) { + public void init(IConfig configProps) { subscriptions = new SubscriptionsStore(); m_executor = Executors.newFixedThreadPool(1); m_disruptor = new Disruptor<>(ValueEvent.EVENT_FACTORY, 1024 * 32, m_executor); @@ -113,10 +114,8 @@ public class SimpleMessaging implements IMessaging, EventHandler { annotationSupport.processAnnotations(m_processor); processInit(configProps); -// disruptorPublish(new InitEvent(configProps)); } - private void disruptorPublish(MessagingEvent msgEvent) { LOG.debug("disruptorPublish publishing event {}", msgEvent); long sequence = m_ringBuffer.next(); @@ -187,7 +186,7 @@ public class SimpleMessaging implements IMessaging, EventHandler { } } - private void processInit(Properties props) { + private void processInit(IConfig props) { benchmarkEnabled = Boolean.parseBoolean(System.getProperty("moquette.processor.benchmark", "false")); //TODO use a property to select the storage path diff --git a/broker/src/test/java/org/eclipse/moquette/server/ConfigurationClassLoaderTest.java b/broker/src/test/java/org/eclipse/moquette/server/ConfigurationClassLoaderTest.java index e75485a5..4c599fe3 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ConfigurationClassLoaderTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ConfigurationClassLoaderTest.java @@ -45,20 +45,19 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat private static final Logger LOG = LoggerFactory.getLogger(ConfigurationClassLoaderTest.class); Server m_server; - MQTT m_mqtt; - BlockingConnection m_subscriber; - BlockingConnection m_publisher; + IConfig m_config; protected void startServer(Properties props) throws IOException { - m_server = new Server(); - m_server.startServer(props); + m_server = new Server(); + m_config = new MemoryConfig(props); + m_server.startServer(m_config); } @After public void tearDown() throws Exception { m_server.stopServer(); - File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } diff --git a/broker/src/test/java/org/eclipse/moquette/server/ConfigurationParserTest.java b/broker/src/test/java/org/eclipse/moquette/server/ConfigurationParserTest.java index 2aeab083..9c452d1e 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ConfigurationParserTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ConfigurationParserTest.java @@ -82,7 +82,7 @@ public class ConfigurationParserTest { @Test public void parseCompleteFile() throws ParseException { - String content = "# This is initial config format \r\n" + String content = "# This is initial m_config format \r\n" + " \r\n" + "port 1234 \r\n" + "host localhost \r\n" diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationFuseTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationFuseTest.java index 3f0ae01a..336ed48c 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationFuseTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationFuseTest.java @@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; +import java.util.Properties; import java.util.concurrent.TimeUnit; import static org.eclipse.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; @@ -40,10 +41,13 @@ public class ServerIntegrationFuseTest { MQTT m_mqtt; BlockingConnection m_subscriber; BlockingConnection m_publisher; + IConfig m_config; protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + final Properties configProps = IntegrationUtils.prepareTestPropeties(); + m_config = new MemoryConfig(configProps); + m_server.startServer(m_config); } @Before @@ -68,7 +72,7 @@ public class ServerIntegrationFuseTest { } m_server.stopServer(); - File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationPahoTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationPahoTest.java index a52f7fbc..c020b7a5 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationPahoTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationPahoTest.java @@ -44,6 +44,7 @@ public class ServerIntegrationPahoTest { Server m_server; IMqttClient m_client; TestCallback m_callback; + IConfig m_config; @BeforeClass public static void beforeTests() { @@ -54,7 +55,9 @@ public class ServerIntegrationPahoTest { protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + final Properties configProps = IntegrationUtils.prepareTestPropeties(); + m_config = new MemoryConfig(configProps); + m_server.startServer(m_config); } @Before @@ -81,7 +84,7 @@ public class ServerIntegrationPahoTest { private void stopServer() { m_server.stopServer(); - File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationQoSValidationTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationQoSValidationTest.java index d7192385..3f813f43 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationQoSValidationTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationQoSValidationTest.java @@ -50,6 +50,7 @@ public class ServerIntegrationQoSValidationTest { IMqttClient m_subscriber; IMqttClient m_publisher; TestCallback m_callback; + IConfig m_config; @BeforeClass public static void beforeTests() { @@ -60,7 +61,9 @@ public class ServerIntegrationQoSValidationTest { protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + final Properties configProps = IntegrationUtils.prepareTestPropeties(); + m_config = new MemoryConfig(configProps); + m_server.startServer(m_config); } @Before @@ -89,7 +92,7 @@ public class ServerIntegrationQoSValidationTest { } m_server.stopServer(); - File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationWebSocketTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationWebSocketTest.java index 7393b02f..9e906971 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationWebSocketTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationWebSocketTest.java @@ -44,10 +44,13 @@ public class ServerIntegrationWebSocketTest { Server m_server; WebSocketClient client; + IConfig m_config; protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + final Properties configProps = IntegrationUtils.prepareTestPropeties(); + m_config = new MemoryConfig(configProps); + m_server.startServer(m_config); } @Before @@ -61,7 +64,7 @@ public class ServerIntegrationWebSocketTest { client.stop(); m_server.stopServer(); - File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerLowlevelMessagesIntegrationTests.java b/broker/src/test/java/org/eclipse/moquette/server/ServerLowlevelMessagesIntegrationTests.java index 83c536c7..ac391abd 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerLowlevelMessagesIntegrationTests.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerLowlevelMessagesIntegrationTests.java @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; +import java.util.Properties; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -45,10 +46,13 @@ public class ServerLowlevelMessagesIntegrationTests { Server m_server; Client m_client; MQTT m_subscriberDef; + IConfig m_config; protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + final Properties configProps = IntegrationUtils.prepareTestPropeties(); + m_config = new MemoryConfig(configProps); + m_server.startServer(m_config); } @Before @@ -67,7 +71,7 @@ public class ServerLowlevelMessagesIntegrationTests { Thread.sleep(300); //to let the close event pass before server stop event m_server.stopServer(); LOG.debug("After asked server to stop"); - File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerRestartIntegrationTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerRestartIntegrationTest.java index 81f4fd77..a656a200 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerRestartIntegrationTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerRestartIntegrationTest.java @@ -18,7 +18,6 @@ package org.eclipse.moquette.server; import org.fusesource.mqtt.client.*; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,10 +42,13 @@ public class ServerRestartIntegrationTest { MQTT m_mqtt; BlockingConnection m_subscriber; BlockingConnection m_publisher; + IConfig m_config; protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + final Properties configProps = IntegrationUtils.prepareTestPropeties(); + m_config = new MemoryConfig(configProps); + m_server.startServer(m_config); } @Before @@ -70,7 +72,7 @@ public class ServerRestartIntegrationTest { } m_server.stopServer(); - File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } @@ -89,7 +91,7 @@ public class ServerRestartIntegrationTest { //shutdown the server m_server.stopServer(); - File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } diff --git a/embedding_moquette/src/main/java/org/eclipse/moquette/testembedded/EmbeddedLauncher.java b/embedding_moquette/src/main/java/org/eclipse/moquette/testembedded/EmbeddedLauncher.java index b99801db..c6399be4 100644 --- a/embedding_moquette/src/main/java/org/eclipse/moquette/testembedded/EmbeddedLauncher.java +++ b/embedding_moquette/src/main/java/org/eclipse/moquette/testembedded/EmbeddedLauncher.java @@ -1,13 +1,17 @@ package org.eclipse.moquette.testembedded; +import org.eclipse.moquette.server.ClasspathConfig; +import org.eclipse.moquette.server.IConfig; import org.eclipse.moquette.server.Server; import java.io.IOException; public class EmbeddedLauncher { public static void main(String[] args) throws InterruptedException, IOException { + final IConfig classPathConfig = new ClasspathConfig(); + final Server mqttBroker = new Server(); - mqttBroker.startServer(); + mqttBroker.startServer(classPathConfig); System.out.println("Broker started"); Thread.sleep(1000); System.out.println("Stopping broker");