Merge pull request #350 from AndreasMager/test_setup_improvement
Test setup improvement
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ broker/runner
|
|||||||
/perf/target/
|
/perf/target/
|
||||||
/mapdb_storage/target/
|
/mapdb_storage/target/
|
||||||
*~
|
*~
|
||||||
*log*
|
*.log*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.settings/
|
.settings/
|
||||||
.project
|
.project
|
||||||
|
|||||||
@@ -100,6 +100,12 @@
|
|||||||
<version>5.1.0</version>
|
<version>5.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.librato.metrics</groupId>
|
||||||
|
<artifactId>librato-java</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.bugsnag</groupId>
|
<groupId>com.bugsnag</groupId>
|
||||||
<artifactId>bugsnag</artifactId>
|
<artifactId>bugsnag</artifactId>
|
||||||
@@ -176,6 +182,13 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.awaitility</groupId>
|
||||||
|
<artifactId>awaitility</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
@@ -241,6 +254,21 @@
|
|||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</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>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</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.MqttException;
|
||||||
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -113,11 +114,21 @@ public class ServerIntegrationSSLClientAuthTest {
|
|||||||
|
|
||||||
IMqttClient m_client;
|
IMqttClient m_client;
|
||||||
MessageCollector m_callback;
|
MessageCollector m_callback;
|
||||||
|
static String backup;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeTests() {
|
public static void beforeTests() {
|
||||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||||
s_dataStore = new MqttDefaultFilePersistence(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 {
|
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.MemoryPersistence;
|
||||||
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -60,10 +61,21 @@ public class ServerIntegrationSSLTest {
|
|||||||
IMqttClient m_client;
|
IMqttClient m_client;
|
||||||
MessageCollector m_callback;
|
MessageCollector m_callback;
|
||||||
|
|
||||||
|
static String backup;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeTests() {
|
public static void beforeTests() {
|
||||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||||
s_dataStore = new MqttDefaultFilePersistence(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 {
|
protected void startServer() throws IOException {
|
||||||
|
|||||||
+18
-11
@@ -27,8 +27,11 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.awaitility.Awaitility;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*;
|
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -81,10 +84,10 @@ public class ServerLowlevelMessagesIntegrationTests {
|
|||||||
*/
|
*/
|
||||||
m_client.sendMessage(connectMessage);
|
m_client.sendMessage(connectMessage);
|
||||||
|
|
||||||
// wait 2 times the keepAlive
|
// wait 3 times the keepAlive
|
||||||
Thread.sleep(keepAlive * 2 * 1000);
|
Awaitility.await()
|
||||||
|
.atMost(3 * keepAlive, TimeUnit.SECONDS)
|
||||||
assertTrue(m_client.isConnectionLost());
|
.until(m_client::isConnectionLost);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MqttConnectMessage createConnectMessage(String clientID, int keepAlive) {
|
private static MqttConnectMessage createConnectMessage(String clientID, int keepAlive) {
|
||||||
@@ -109,14 +112,18 @@ public class ServerLowlevelMessagesIntegrationTests {
|
|||||||
m_client.clientId("FAKECLNT").connect(willTestamentTopic, willTestamentMsg);
|
m_client.clientId("FAKECLNT").connect(willTestamentTopic, willTestamentMsg);
|
||||||
long connectTime = System.currentTimeMillis();
|
long connectTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// but after the 2 KEEP ALIVE timeout expires it gets fired,
|
Awaitility.await()
|
||||||
// NB it's 1,5 * KEEP_ALIVE so 3 secs and some millis to propagate the message
|
.atMost(7, TimeUnit.SECONDS)
|
||||||
org.eclipse.paho.client.mqttv3.MqttMessage msg = m_messageCollector.waitMessage(5);
|
.untilAsserted(() -> {
|
||||||
assertNotNull("the will message should be fired after keep alive!", msg);
|
// but after the 2 KEEP ALIVE timeout expires it gets fired,
|
||||||
// the will message hasn't to be received before the elapsing of Keep Alive timeout
|
// NB it's 1,5 * KEEP_ALIVE so 3 secs and some millis to propagate the message
|
||||||
assertTrue(System.currentTimeMillis() - connectTime > 3000);
|
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();
|
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>
|
<groupId>io.moquette</groupId>
|
||||||
<artifactId>moquette-broker</artifactId>
|
<artifactId>moquette-broker</artifactId>
|
||||||
<version>${project.version}</version>
|
<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>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ package io.moquette.test.osgi;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.ops4j.pax.exam.CoreOptions.*;
|
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.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.ops4j.pax.exam.Configuration;
|
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.ops4j.pax.exam.junit.PaxExam;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,6 +38,9 @@ import javax.inject.Inject;
|
|||||||
*/
|
*/
|
||||||
@RunWith(PaxExam.class)
|
@RunWith(PaxExam.class)
|
||||||
public class MoquetteOsgiTest {
|
public class MoquetteOsgiTest {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(MoquetteOsgiTest.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BundleContext bundleContext;
|
private BundleContext bundleContext;
|
||||||
|
|
||||||
@@ -43,7 +49,42 @@ public class MoquetteOsgiTest {
|
|||||||
|
|
||||||
return options(
|
return options(
|
||||||
junitBundles(),
|
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
|
@Test
|
||||||
public void testCanFindOsgiBundle() throws Exception {
|
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()) {
|
for (Bundle b : bundleContext.getBundles()) {
|
||||||
String symbolicName = b.getSymbolicName();
|
String symbolicName = b.getSymbolicName();
|
||||||
System.out.format("%s %d\n", symbolicName, b.getState());
|
LOG.info("{} {}", symbolicName, b.getState());
|
||||||
if (symbolicName != null && symbolicName.indexOf("moquette") != -1) {
|
System.out.println("" + symbolicName);
|
||||||
return;
|
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.
|
if (!inactive.isEmpty() || !list.isEmpty())
|
||||||
fail();
|
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