Skip to content

Commit 88a95b4

Browse files
authored
Numerous changes to fix tests in travis (#372)
* Numerous changes to improve testing on Travis CI - Local Mosquitto instance - Removing Test timeouts as they didn't really help - Adjusting a few Tests * Fixing Test POM * Issue #297 - Adding ability to force close connection, and a few other Sonar improvements * Removing timeout * Resolving Issue #384 - Incorrect Log message Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent a6faf77 commit 88a95b4

25 files changed

Lines changed: 521 additions & 58 deletions

File tree

.travis.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1+
sudo: true
12
language: java
2-
script: mvn test -Dtest.server_ssl_port=18885 -Dtest.server_uri=tcp://mqtt.iotree.co.uk:1883 -Dtest.server_websocket_uri=ws://mqtt.iotree.co.uk:8080 -B
3+
4+
matrix:
5+
include:
6+
- os: linux
7+
dist: trusty
8+
sudo: required
9+
# - os: osx
10+
11+
sudo: required
12+
13+
before_install:
14+
- ./travis-install.sh
15+
16+
script: mvn --projects org.eclipse.paho.client.mqttv3,org.eclipse.paho.client.mqttv3.test test -Dtest.server_ssl_port=18885 -Dtest.server_uri=tcp://localhost:1883 -Dtest.server_websocket_uri=ws://localhost:8080 -B
17+
18+
addons:
19+
apt:
20+
sources:
21+
- sourceline: 'ppa:mosquitto-dev/mosquitto-ppa'
22+
packages:
23+
- mosquitto

org.eclipse.paho.client.mqttv3.test/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@
4747
<artifactId>maven-surefire-plugin</artifactId>
4848
<version>2.15</version>
4949
<configuration>
50-
<reuseForks>false</reuseForks>
51-
<forkCount>1</forkCount>
5250
<systemPropertyVariables>
5351
<SERVER_URI>${test.server_uri}</SERVER_URI>
5452
<SERVER_SSL_PORT>${test.server_ssl_port}</SERVER_SSL_PORT>
55-
<SERVER_WEBSOCKET_URI>${test.server_websocket_url}</SERVER_WEBSOCKET_URI>
53+
<SERVER_WEBSOCKET_URI>${test.server_websocket_uri}</SERVER_WEBSOCKET_URI>
5654
</systemPropertyVariables>
5755
<excludes>
5856
<exclude>${test.exclude}</exclude>
5957
</excludes>
58+
<runOrder>alphabetical</runOrder>
6059
</configuration>
6160
</plugin>
6261
</plugins>

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/BasicTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static void tearDownAfterClass() throws Exception {
9595
/**
9696
* @throws Exception
9797
*/
98-
@Test(timeout=10000)
98+
@Test
9999
public void testConnect() throws Exception {
100100
String methodName = Utility.getMethodName();
101101
LoggingUtilities.banner(log, cclass, methodName);
@@ -141,7 +141,7 @@ public void testConnect() throws Exception {
141141
/**
142142
* @throws Exception
143143
*/
144-
@Test(timeout=10000)
144+
@Test
145145
public void testHAConnect() throws Exception {
146146
String methodName = Utility.getMethodName();
147147
LoggingUtilities.banner(log, cclass, methodName);
@@ -191,7 +191,7 @@ public void testHAConnect() throws Exception {
191191
/**
192192
* @throws Exception
193193
*/
194-
@Test(timeout=10000)
194+
@Test
195195
public void testPubSub() throws Exception {
196196
String methodName = Utility.getMethodName();
197197
LoggingUtilities.banner(log, cclass, methodName);
@@ -241,7 +241,7 @@ public void testPubSub() throws Exception {
241241
/**
242242
* @throws Exception
243243
*/
244-
@Test(timeout=10000)
244+
@Test
245245
public void testMsgProperties() throws Exception {
246246
String methodName = Utility.getMethodName();
247247
LoggingUtilities.banner(log, cclass, methodName);
@@ -309,7 +309,7 @@ public void testMsgProperties() throws Exception {
309309
/**
310310
* @throws Exception
311311
*/
312-
@Test(timeout=10000)
312+
@Test
313313
public void testConnOptDefaults() throws Exception {
314314
String methodName = Utility.getMethodName();
315315
LoggingUtilities.banner(log, cclass, methodName);

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/ModelTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public static void tearDownAfterClass() throws Exception {
167167
/**
168168
* @throws Exception
169169
*/
170-
@Test(timeout=150000)
170+
//@Test(timeout=150000)
171171
public void testRunModel() throws Exception {
172172
log.info("Test core operations and parameters by random selection");
173173
log.info("See file: " + logFilename + " for details of selected test sequence");

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/PerSubscriptionMessageHandlerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void messageArrived(String topic, MqttMessage message) throws Exception {
136136
*
137137
* @throws Exception
138138
*/
139-
@Test(timeout=10000)
139+
@Test
140140
public void testSyncSubs1() throws Exception {
141141
final String methodName = Utility.getMethodName();
142142
LoggingUtilities.banner(log, cclass, methodName);
@@ -166,7 +166,7 @@ public void testSyncSubs1() throws Exception {
166166

167167
}
168168

169-
@Test(timeout=10000)
169+
@Test
170170
public void testAsyncSubs1() throws Exception {
171171
final String methodName = Utility.getMethodName();
172172
LoggingUtilities.banner(log, cclass, methodName);
@@ -204,7 +204,7 @@ public void testAsyncSubs1() throws Exception {
204204
* Check handlers still exist after reconnection non-cleansession
205205
*/
206206

207-
@Test(timeout=10000)
207+
@Test
208208
public void testSyncCleanSessionFalse() throws Exception {
209209
final String methodName = Utility.getMethodName();
210210
LoggingUtilities.banner(log, cclass, methodName);
@@ -256,7 +256,7 @@ public void testSyncCleanSessionFalse() throws Exception {
256256
mqttClient.close();
257257
}
258258

259-
@Test(timeout=10000)
259+
@Test
260260
public void testAsyncCleanSessionFalse() throws Exception {
261261
final String methodName = Utility.getMethodName();
262262
LoggingUtilities.banner(log, cclass, methodName);

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/SendReceiveAsyncTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static void tearDownAfterClass() throws Exception {
9595
*
9696
* @throws Exception
9797
*/
98-
@Test(timeout=10000)
98+
@Test
9999
public void testConnect() throws Exception {
100100
final String methodName = Utility.getMethodName();
101101
LoggingUtilities.banner(log, cclass, methodName);
@@ -142,7 +142,7 @@ public void testConnect() throws Exception {
142142
*
143143
* @throws Exception
144144
*/
145-
@Test(timeout=10000)
145+
@Test
146146
public void testRemoteConnect() throws Exception {
147147
final String methodName = Utility.getMethodName();
148148
LoggingUtilities.banner(log, cclass, methodName);
@@ -214,7 +214,7 @@ public void testRemoteConnect() throws Exception {
214214
/**
215215
* Test client pubSub using very large messages
216216
*/
217-
@Test(timeout=10000)
217+
@Test
218218
public void testLargeMessage() {
219219
final String methodName = Utility.getMethodName();
220220
LoggingUtilities.banner(log, cclass, methodName);
@@ -291,7 +291,7 @@ public void testLargeMessage() {
291291
/**
292292
* Multiple publishers and subscribers.
293293
*/
294-
@Test(timeout=20000)
294+
@Test
295295
public void testMultipleClients() {
296296
final String methodName = Utility.getMethodName();
297297
LoggingUtilities.banner(log, cclass, methodName);
@@ -386,7 +386,7 @@ public void testMultipleClients() {
386386
* Test the behaviour of the cleanStart flag, used to clean up before
387387
* re-connecting.
388388
*/
389-
@Test(timeout=10000)
389+
@Test
390390
public void testCleanStart() throws Exception {
391391
final String methodName = Utility.getMethodName();
392392
LoggingUtilities.banner(log, cclass, methodName);
@@ -532,7 +532,7 @@ public void testCleanStart() throws Exception {
532532
*
533533
* Since no other activity (messages from the client to the broker) is generated, the broker disconnects the client.
534534
*/
535-
@Test(timeout=300000)
535+
@Test
536536
public void testVeryLargeMessageWithShortKeepAlive() {
537537
final String methodName = Utility.getMethodName();
538538
LoggingUtilities.banner(log, cclass, methodName);
@@ -601,7 +601,7 @@ public void testVeryLargeMessageWithShortKeepAlive() {
601601
* Test the behavior of the connection timeout when connecting to a non MQTT server.
602602
* i.e. ssh port 22
603603
*/
604-
@Test(timeout=60000)
604+
@Test
605605
public void testConnectTimeout() throws Exception {
606606
final String methodName = Utility.getMethodName();
607607
LoggingUtilities.banner(log, cclass, methodName);

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/SendReceiveTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static void tearDownAfterClass() throws Exception {
9393
* service
9494
* @throws Exception
9595
*/
96-
@Test(timeout=10000)
96+
@Test
9797
public void testConnect() throws Exception {
9898
final String methodName = Utility.getMethodName();
9999
LoggingUtilities.banner(log, cclass, methodName);
@@ -129,7 +129,7 @@ public void testConnect() throws Exception {
129129
* Test connection using a remote host name for the local host.
130130
* @throws Exception
131131
*/
132-
@Test(timeout=10000)
132+
@Test
133133
public void testRemoteConnect() throws Exception {
134134
final String methodName = Utility.getMethodName();
135135
LoggingUtilities.banner(log, cclass, methodName);
@@ -184,7 +184,7 @@ public void testRemoteConnect() throws Exception {
184184
/**
185185
* Test client pubSub using largish messages
186186
*/
187-
@Test(timeout=10000)
187+
@Test
188188
public void testLargeMessage() {
189189
final String methodName = Utility.getMethodName();
190190
LoggingUtilities.banner(log, cclass, methodName);
@@ -245,7 +245,7 @@ public void testLargeMessage() {
245245
/**
246246
* Test that QOS values are preserved between MQTT publishers and subscribers.
247247
*/
248-
@Test(timeout=10000)
248+
@Test
249249
public void testQoSPreserved() {
250250
final String methodName = Utility.getMethodName();
251251
LoggingUtilities.banner(log, cclass, methodName);
@@ -305,7 +305,7 @@ public void testQoSPreserved() {
305305
* Multiple publishers and subscribers.
306306
* @throws Exception
307307
*/
308-
@Test(timeout=30000)
308+
@Test
309309
public void testMultipleClients() throws Exception {
310310
final String methodName = Utility.getMethodName();
311311
LoggingUtilities.banner(log, cclass, methodName);
@@ -388,7 +388,7 @@ public void testMultipleClients() throws Exception {
388388
* Test the behaviour of the cleanStart flag, used to clean up before re-connecting.
389389
* @throws Exception
390390
*/
391-
@Test(timeout=10000)
391+
@Test
392392
public void testCleanStart() throws Exception {
393393
final String methodName = Utility.getMethodName();
394394
LoggingUtilities.banner(log, cclass, methodName);

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/automaticReconnect/OfflineBufferingTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void setUpBeforeClass() throws Exception {
5050
topicPrefix = "OfflineBufferingTest-" + UUID.randomUUID().toString() + "-";
5151

5252
// Use 0 for the first time.
53-
proxy = new ConnectionManipulationProxyServer(serverURI.getHost(), serverURI.getPort(), 0);
53+
proxy = new ConnectionManipulationProxyServer(serverURI.getHost(), serverURI.getPort(), 2883);
5454
proxy.startProxy();
5555
while (!proxy.isPortSet()) {
5656
Thread.sleep(0);
@@ -68,7 +68,7 @@ public static void setUpBeforeClass() throws Exception {
6868
* disconnected state and is then delivered once the client has reconnected
6969
* automatically.
7070
*/
71-
@Test(timeout=60000)
71+
@Test
7272
public void testSingleMessageBufferAndDeliver() throws Exception {
7373
String methodName = Utility.getMethodName();
7474
LoggingUtilities.banner(log, cclass, methodName);
@@ -139,7 +139,7 @@ public void testSingleMessageBufferAndDeliver() throws Exception {
139139
* disconnected state and that they are all then delivered once the client
140140
* has connected automatically.
141141
*/
142-
@Test(timeout=60000)
142+
@Test
143143
public void testManyMessageBufferAndDeliver() throws Exception {
144144
String methodName = Utility.getMethodName();
145145
LoggingUtilities.banner(log, cclass, methodName);
@@ -231,7 +231,7 @@ public void testManyMessageBufferAndDeliver() throws Exception {
231231
* Tests that the buffer correctly handles messages being buffered when the
232232
* buffer is full and deleteOldestBufferedMessage is set to true.
233233
*/
234-
@Test(timeout=60000)
234+
@Test
235235
public void testDeleteOldestBufferedMessages() throws Exception {
236236
String methodName = Utility.getMethodName();
237237
LoggingUtilities.banner(log, cclass, methodName);
@@ -288,7 +288,7 @@ public void testDeleteOldestBufferedMessages() throws Exception {
288288
* Tests that A message cannot be buffered when the buffer is full and
289289
* deleteOldestBufferedMessage is set to false.
290290
*/
291-
@Test(timeout=60000)
291+
@Test
292292
public void testNoDeleteOldestBufferedMessages() throws Exception {
293293
String methodName = Utility.getMethodName();
294294
LoggingUtilities.banner(log, cclass, methodName);
@@ -347,7 +347,7 @@ public void testNoDeleteOldestBufferedMessages() throws Exception {
347347
* Tests that if enabled, buffered messages are persisted to the persistence
348348
* layer
349349
*/
350-
@Test(timeout=60000)
350+
@Test
351351
public void testPersistBufferedMessages() throws Exception {
352352
String methodName = Utility.getMethodName();
353353
LoggingUtilities.banner(log, cclass, methodName);
@@ -407,7 +407,7 @@ public void testPersistBufferedMessages() throws Exception {
407407
* Tests that persisted buffered messages are published correctly when the
408408
* client connects for the first time and are un persisted.
409409
*/
410-
@Test(timeout=60000)
410+
@Test
411411
public void testUnPersistBufferedMessagesOnNewClient() throws Exception {
412412
String methodName = Utility.getMethodName();
413413
LoggingUtilities.banner(log, cclass, methodName);

org.eclipse.paho.client.mqttv3/src/main/java-templates/org/eclipse/paho/client/mqttv3/internal/ClientComms.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ public void sendNoWait(MqttWireMessage message, MqttToken token) throws MqttExce
207207
* store which normally survives a disconnect.
208208
* @throws MqttException if not disconnected
209209
*/
210-
public void close() throws MqttException {
210+
public void close(boolean force) throws MqttException {
211211
final String methodName = "close";
212212
synchronized (conLock) {
213213
if (!isClosed()) {
214-
// Must be disconnected before close can take place
215-
if (!isDisconnected()) {
214+
// Must be disconnected before close can take place or if we are being forced
215+
if (!isDisconnected() || force) {
216216
//@TRACE 224=failed: not disconnected
217217
log.fine(CLASS_NAME, methodName, "224");
218218

@@ -427,7 +427,7 @@ public void shutdownConnection(MqttToken token, MqttException reason) {
427427
synchronized(conLock) {
428428
if (closePending) {
429429
try {
430-
close();
430+
close(true);
431431
} catch (Exception e) { // ignore any errors as closing
432432
}
433433
}

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/DisconnectedBufferOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class DisconnectedBufferOptions {
5151
* More information about these values can be found in the setter methods.
5252
*/
5353
public DisconnectedBufferOptions() {
54+
// Do Nothing.
5455
}
5556

5657
public int getBufferSize() {

0 commit comments

Comments
 (0)