ServerIntegrationSSLTest: System properties saved
ServerLowlevelMessagesIntegrationTests: timeouts raised osgi: log4j.properties added MoquetteOsgiTest: test imporved storage packages will checked too The state must be active osgi: README added for development log4j: fixed broker/pom.xml: dependencie added osgi config added osgi_test/pom: dependencies added MoquetteOsgiTest: test fixed
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ broker/runner
|
||||
/perf/target/
|
||||
/mapdb_storage/target/
|
||||
*~
|
||||
*log*
|
||||
*.log*
|
||||
.DS_Store
|
||||
.settings/
|
||||
.project
|
||||
|
||||
@@ -100,6 +100,12 @@
|
||||
<version>5.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.librato.metrics</groupId>
|
||||
<artifactId>librato-java</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.bugsnag</groupId>
|
||||
<artifactId>bugsnag</artifactId>
|
||||
@@ -176,6 +182,13 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
@@ -241,6 +254,21 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Export-Package>
|
||||
io.moquette.persistence,
|
||||
io.moquette.server.config,
|
||||
io.moquette.spi,
|
||||
io.moquette.spi.impl.subscriptions,
|
||||
</Export-Package>
|
||||
<Embed-Dependency>
|
||||
com.bugsnag;bugsnag,
|
||||
com.librato.metrics;metrics-librato,
|
||||
com.librato.metrics;librato-java,
|
||||
</Embed-Dependency>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -113,11 +114,21 @@ public class ServerIntegrationSSLClientAuthTest {
|
||||
|
||||
IMqttClient m_client;
|
||||
MessageCollector m_callback;
|
||||
static String backup;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeTests() {
|
||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
s_dataStore = new MqttDefaultFilePersistence(tmpDir);
|
||||
backup = System.getProperty("moquette.path");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterTests() {
|
||||
if (backup == null)
|
||||
System.clearProperty("moquette.path");
|
||||
else
|
||||
System.setProperty("moquette.path", backup);
|
||||
}
|
||||
|
||||
protected void startServer() throws IOException {
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -60,10 +61,21 @@ public class ServerIntegrationSSLTest {
|
||||
IMqttClient m_client;
|
||||
MessageCollector m_callback;
|
||||
|
||||
static String backup;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeTests() {
|
||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
s_dataStore = new MqttDefaultFilePersistence(tmpDir);
|
||||
backup = System.getProperty("moquette.path");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterTests() {
|
||||
if (backup == null)
|
||||
System.clearProperty("moquette.path");
|
||||
else
|
||||
System.setProperty("moquette.path", backup);
|
||||
}
|
||||
|
||||
protected void startServer() throws IOException {
|
||||
|
||||
+13
-6
@@ -27,8 +27,11 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.awaitility.Awaitility;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -81,10 +84,10 @@ public class ServerLowlevelMessagesIntegrationTests {
|
||||
*/
|
||||
m_client.sendMessage(connectMessage);
|
||||
|
||||
// wait 2 times the keepAlive
|
||||
Thread.sleep(keepAlive * 2 * 1000);
|
||||
|
||||
assertTrue(m_client.isConnectionLost());
|
||||
// wait 3 times the keepAlive
|
||||
Awaitility.await()
|
||||
.atMost(3 * keepAlive, TimeUnit.SECONDS)
|
||||
.until(m_client::isConnectionLost);
|
||||
}
|
||||
|
||||
private static MqttConnectMessage createConnectMessage(String clientID, int keepAlive) {
|
||||
@@ -109,14 +112,18 @@ public class ServerLowlevelMessagesIntegrationTests {
|
||||
m_client.clientId("FAKECLNT").connect(willTestamentTopic, willTestamentMsg);
|
||||
long connectTime = System.currentTimeMillis();
|
||||
|
||||
Awaitility.await()
|
||||
.atMost(7, TimeUnit.SECONDS)
|
||||
.untilAsserted(() -> {
|
||||
// but after the 2 KEEP ALIVE timeout expires it gets fired,
|
||||
// NB it's 1,5 * KEEP_ALIVE so 3 secs and some millis to propagate the message
|
||||
org.eclipse.paho.client.mqttv3.MqttMessage msg = m_messageCollector.waitMessage(5);
|
||||
org.eclipse.paho.client.mqttv3.MqttMessage msg = m_messageCollector.getMessageImmediate();
|
||||
assertNotNull("the will message should be fired after keep alive!", msg);
|
||||
// the will message hasn't to be received before the elapsing of Keep Alive timeout
|
||||
assertTrue(System.currentTimeMillis() - connectTime > 3000);
|
||||
assertEquals(willTestamentMsg, new String(msg.getPayload(), StandardCharsets.UTF_8));
|
||||
});
|
||||
|
||||
assertEquals(willTestamentMsg, new String(msg.getPayload()));
|
||||
m_willSubscriber.disconnect();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Development
|
||||
|
||||
to run the osgi tests use:
|
||||
|
||||
mvn clean && mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V && mvn -B test -pl osgi_test
|
||||
@@ -22,6 +22,37 @@
|
||||
<groupId>io.moquette</groupId>
|
||||
<artifactId>moquette-broker</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.moquette</groupId>
|
||||
<artifactId>moquette-h2-storage</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.moquette</groupId>
|
||||
<artifactId>moquette-mapdb-storage</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ package io.moquette.test.osgi;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.ops4j.pax.exam.CoreOptions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.ops4j.pax.exam.Configuration;
|
||||
@@ -26,7 +28,8 @@ import org.ops4j.pax.exam.Option;
|
||||
import org.ops4j.pax.exam.junit.PaxExam;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
@@ -35,6 +38,9 @@ import javax.inject.Inject;
|
||||
*/
|
||||
@RunWith(PaxExam.class)
|
||||
public class MoquetteOsgiTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MoquetteOsgiTest.class);
|
||||
|
||||
@Inject
|
||||
private BundleContext bundleContext;
|
||||
|
||||
@@ -43,7 +49,42 @@ public class MoquetteOsgiTest {
|
||||
|
||||
return options(
|
||||
junitBundles(),
|
||||
mavenBundle("io.moquette", "moquette-broker")
|
||||
|
||||
mavenBundle("com.google.guava", "guava").versionAsInProject(),
|
||||
//mavenBundle("com.google.code.findbugs", "jsr305").versionAsInProject(),
|
||||
|
||||
mavenBundle("com.fasterxml.jackson.core", "jackson-core").versionAsInProject().start(),
|
||||
mavenBundle("com.fasterxml.jackson.core", "jackson-databind").versionAsInProject(),
|
||||
mavenBundle("com.fasterxml.jackson.core", "jackson-annotations").versionAsInProject(),
|
||||
//mavenBundle("com.librato.metrics", "librato-java").versionAsInProject(),
|
||||
//mavenBundle("com.librato.metrics", "metrics-librato").versionAsInProject(),
|
||||
mavenBundle("io.dropwizard.metrics", "metrics-core").versionAsInProject(),
|
||||
mavenBundle("io.dropwizard.metrics", "metrics-jvm").versionAsInProject(),
|
||||
mavenBundle("com.hazelcast", "hazelcast").versionAsInProject(),
|
||||
|
||||
mavenBundle("io.netty", "netty-common").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-buffer").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-transport").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-resolver").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-handler").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-handler").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-codec").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-codec-http").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-codec-mqtt").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-transport-native-epoll").versionAsInProject(),
|
||||
mavenBundle("io.netty", "netty-transport-native-unix-common").versionAsInProject(),
|
||||
|
||||
mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
|
||||
|
||||
mavenBundle("javax.servlet", "javax.servlet-api").versionAsInProject(),
|
||||
|
||||
mavenBundle("io.moquette", "moquette-broker").versionAsInProject(),
|
||||
|
||||
mavenBundle("com.h2database", "h2-mvstore").versionAsInProject(),
|
||||
mavenBundle("io.moquette", "moquette-h2-storage").versionAsInProject(),
|
||||
|
||||
mavenBundle("org.mapdb", "mapdb").versionAsInProject(),
|
||||
mavenBundle("io.moquette", "moquette-mapdb-storage").versionAsInProject()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,15 +96,23 @@ public class MoquetteOsgiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testCanFindOsgiBundle() throws Exception {
|
||||
List<String> list = new LinkedList<>(Arrays.asList("io.moquette.broker", "io.moquette.h2-storage",
|
||||
"io.moquette.mapdb-storage"));
|
||||
|
||||
List<String> inactive = new LinkedList<>();
|
||||
|
||||
for (Bundle b : bundleContext.getBundles()) {
|
||||
String symbolicName = b.getSymbolicName();
|
||||
System.out.format("%s %d\n", symbolicName, b.getState());
|
||||
if (symbolicName != null && symbolicName.indexOf("moquette") != -1) {
|
||||
return;
|
||||
LOG.info("{} {}", symbolicName, b.getState());
|
||||
System.out.println("" + symbolicName);
|
||||
if (symbolicName != null) {
|
||||
list.remove(symbolicName);
|
||||
if (b.getState() != Bundle.ACTIVE)
|
||||
inactive.add(symbolicName);
|
||||
}
|
||||
}
|
||||
|
||||
// If found no bundles with moquette in the name, fail the test.
|
||||
fail();
|
||||
if (!inactive.isEmpty() || !list.isEmpty())
|
||||
fail("This osgi bundles are missing: " + list + " this osgi packages are NOT active" + inactive);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# Set root logger level to DEBUG and its only appender to A1.
|
||||
log4j.rootLogger=ERROR, stdout
|
||||
|
||||
log4j.logger.io.moquette=DEBUG
|
||||
|
||||
# stdout appender is set to be a ConsoleAppender.
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Threshold=DEBUG
|
||||
# for debug trace
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
#log4j.appender.stdout.layout.ConversionPattern=%-4r [%t] %-5p %c{1} %x - %m%n
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss,SSS} [%t] %-5p %c{1} %M %L %x - %m%n
|
||||
Reference in New Issue
Block a user