Skip to content

Commit fa66f22

Browse files
author
Ranjan Dasgupta
authored
Merge pull request #765 from eclipse/develop
Develop to master
2 parents a11cce9 + d3aa7f4 commit fa66f22

27 files changed

Lines changed: 405 additions & 78 deletions

File tree

.github/ISSUE_TEMPLATE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Please fill out the form below before submitting, thank you!
22

3-
- [ ] Bug exists Release Version 1.2.2 ( Master Branch)
4-
- [ ] Bug exists in MQTTv3 Client on Snapshot Version 1.2.3-SNAPSHOT (Develop Branch)
3+
- [ ] Bug exists Release Version 1.2.3 ( Master Branch)
4+
- [ ] Bug exists in MQTTv3 Client on Snapshot Version 1.2.4-SNAPSHOT (Develop Branch)
55
- [ ] Bug exists in MQTTv5 Client on Snapshot Version 1.2.3-SNAPSHOT (Develop Branch)
66

7+
78
If this is a bug regarding the Android Service, please raise the bug here instead: https://github.com/eclipse/paho.mqtt.android/issues/new

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Please make sure that the following boxes are checked before submitting your Pul
22

33
- [ ] This change is against the develop branch, **not** master.
44
- [ ] You have signed the [Eclipse ECA](https://wiki.eclipse.org/ECA)
5-
- [ ] All of your commits have been signed-off with the correct email address (The same one that you used to sign the CLA) _Hint: use the -s argument when committing_.
6-
- [ ] If This PR fixes an issue, that you reference the issue below. OR if this is a new issue that you are fixing straight away that you add some Description about the bug and how this will fix it.
5+
- [ ] All of your commits have been signed-off with the correct email address (the same one that you
6+
used to sign the CLA) _Hint: use the -s argument when committing_.
7+
- [ ] If This PR fixes an issue, that you reference the issue below. OR if this is a new issue that
8+
you are fixing straight away that you add some Description about the bug and how this will fix it.
79
- [ ] If this is new functionality, You have added the appropriate Unit tests.

MQTTv3.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Eclipse hosts a Nexus repository for those who want to use Maven to manage their
1111
Add the repository definition and the dependency definition shown below to your pom.xml.
1212

1313
Replace %REPOURL% with either ``` https://repo.eclipse.org/content/repositories/paho-releases/ ``` for the official releases, or ``` https://repo.eclipse.org/content/repositories/paho-snapshots/ ``` for the nightly snapshots. Replace %VERSION% with the level required .
14-
The latest release version is ```1.2.2``` and the current snapshot version is ```1.2.3-SNAPSHOT```.
14+
15+
The latest release version is ```1.2.3``` and the current snapshot version is ```1.2.4-SNAPSHOT```.
16+
1517

1618
```
1719
<project ...>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Add the repository definition and the dependency definition shown below to your
3232

3333
Replace %REPOURL% with either ``` https://repo.eclipse.org/content/repositories/paho-releases/ ``` for the official releases, or ``` https://repo.eclipse.org/content/repositories/paho-snapshots/ ``` for the nightly snapshots. Replace %VERSION% with the level required .
3434

35-
The latest release version is ```1.2.2``` and the current snapshot version is ```1.2.3-SNAPSHOT```.
35+
The latest release version is ```1.2.3``` and the current snapshot version is ```1.2.4-SNAPSHOT```.
3636

3737

3838
```

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,43 @@ public void test402a() throws Exception {
487487
Assert.assertEquals(after_count, before_thread_count + pool_size);
488488
}
489489

490+
@Test
491+
public void testDisconnectForcibly() throws Exception {
492+
String methodName = Utility.getMethodName();
493+
LoggingUtilities.banner(log, cclass, methodName);
494+
495+
IMqttClient client = null;
496+
try {
497+
String clientId = methodName;
498+
client = clientFactory.createMqttClient(serverURI, clientId);
499+
500+
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + clientId);
501+
client.connect();
502+
boolean isConnected = client.isConnected();
503+
log.info("isConnected = " + isConnected);
504+
log.info("Disconnecting Forcibly with no timeout");
505+
client.disconnectForcibly();
506+
507+
log.info("Re-Connecting...");
508+
client.connect();
509+
isConnected = client.isConnected();
510+
log.info("isConnected = " + isConnected);
511+
log.info("Disconnecting Forcibly with 2 sec timeout");
512+
client.disconnectForcibly(2000, 2000);
513+
}
514+
catch (MqttException exception) {
515+
log.log(Level.SEVERE, "caught exception:", exception);
516+
Assert.fail("Unexpected exception: " + exception);
517+
}
518+
finally {
519+
if (client != null) {
520+
log.info("Close...");
521+
client.close();
522+
}
523+
}
524+
}
525+
526+
490527

491528
// -------------------------------------------------------------
492529
// Helper methods/classes

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package org.eclipse.paho.client.mqttv3.test;
22

3-
import java.io.BufferedReader;
4-
import java.io.ByteArrayInputStream;
5-
import java.io.ByteArrayOutputStream;
6-
import java.io.DataInputStream;
7-
import java.io.DataOutputStream;
8-
import java.io.File;
9-
import java.io.FileReader;
10-
import java.io.IOException;
3+
import java.io.*;
4+
import java.nio.charset.Charset;
5+
import java.nio.charset.StandardCharsets;
116

127
import org.eclipse.paho.client.mqttv3.MqttException;
138
import org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage;
@@ -127,7 +122,18 @@ public void TestEncodeAndDecodeComplexUTF8String() throws MqttException {
127122
@Test
128123
public void testICanEatGlass() throws IOException, MqttException {
129124
ClassLoader classLoader = getClass().getClassLoader();
130-
File file = new File(classLoader.getResource("i_can_eat_glass.txt").getFile());
125+
String encodedFileName = classLoader.getResource("i_can_eat_glass.txt").getFile();
126+
String decodedFileName;
127+
try {
128+
decodedFileName = java.net.URLDecoder.decode( encodedFileName, StandardCharsets.UTF_8.name() );
129+
}
130+
catch ( UnsupportedEncodingException e ) {
131+
// can't decode the URL, passing on the encoded name hoping that it
132+
// actually contains something that exists in the filesystem with
133+
// that name.
134+
decodedFileName = encodedFileName;
135+
}
136+
File file = new File(decodedFileName);
131137

132138
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
133139
for (String line; (line = br.readLine()) != null;) {

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ public void testValidTopicFilterWildcards() throws Exception {
6060
public void testMatchedTopicFilterWildcards() throws Exception {
6161
String methodName = Utility.getMethodName();
6262
LoggingUtilities.banner(log, cclass, methodName);
63-
String[][] matchingTopics = new String[][] { { "sport/tennis/player1/#", "sport/tennis/player1" },
64-
{ "sport/tennis/player1/#", "sport/tennis/player1/ranking" },
65-
{ "sport/tennis/player1/#", "sport/tennis/player1/score/wimbledon" }, { "sport/#", "sport" },
66-
{ "#", "sport/tennis/player1" } };
63+
String[][] matchingTopics = new String[][] {
64+
{ "+/+", "sport/hockey" },
65+
{ "/+", "/sport" },
66+
{ "sport/tennis/player1/#", "sport/tennis/player1" },
67+
{ "sport/tennis/player1/#", "sport/tennis/player1/ranking" },
68+
{ "sport/tennis/player1/#", "sport/tennis/player1/score/wimbledon" },
69+
{ "sport/#", "sport" },
70+
{ "#", "sport/tennis/player1" },
71+
{ "sport/tennis/player1/#", "sport/tennis/player1//wimbledon" },
72+
{ "sport/+/player1/#", "sport/tennis/player1/wimbledon" },
73+
{ "sport/+/player1/#", "sport/soccer/player1/UEFA" }
74+
};
6775

6876
for (String[] pair : matchingTopics) {
6977
Assert.assertTrue(pair[0] + " should match " + pair[1], MqttTopic.isMatched(pair[0], pair[1]));
@@ -74,8 +82,15 @@ public void testMatchedTopicFilterWildcards() throws Exception {
7482
public void testNonMatchedTopicFilterWildcards() throws Exception {
7583
String methodName = Utility.getMethodName();
7684
LoggingUtilities.banner(log, cclass, methodName);
77-
String[][] matchingTopics = new String[][] { { "sport/tennis/player1/#", "sport/tennis/player2" },
78-
{ "sport1/#", "sport2" }, { "sport/tennis1/player/#", "sport/tennis2/player" } };
85+
String[][] matchingTopics = new String[][] {
86+
{ "+/+", "/sport" },
87+
{ "+/+", "a/b/c" },
88+
{ "/sport/+", "/sport/" },
89+
{ "sport/tennis/player1/#", "sport/tennis/player2" },
90+
{ "sport1/#", "sport2" },
91+
{ "sport/tennis1/player/#", "sport/tennis2/player" },
92+
{ "sport//tennis/player1/#", "sport/tennis/player1//wimbledon" }
93+
};
7994

8095
for (String[] pair : matchingTopics) {
8196
Assert.assertFalse(pair[0] + " should NOT match " + pair[1], MqttTopic.isMatched(pair[0], pair[1]));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static void setUpBeforeClass() throws Exception {
8282
*
8383
* @throws Exception
8484
*/
85-
@Test(timeout=30000)
85+
@Test(timeout=60000)
8686
public void testSSLSessionInvalidated() throws Exception {
8787
//System.setProperty("javax.net.debug", "all");
8888

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

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,40 @@ public void testConnect() throws Exception {
158158
log.exiting(className, methodName);
159159
}
160160

161+
@Test
162+
public void testConAndDiscon() throws Exception {
163+
String methodName = Utility.getMethodName();
164+
LoggingUtilities.banner(log, cclass, methodName);
165+
166+
IMqttAsyncClient client = null;
167+
int max_loop_count = 100;
168+
169+
try {
170+
String clientId = methodName;
171+
client = new MqttAsyncClient(serverURI.toString(), clientId);
172+
log.info("Connecting: [serverURI: " + serverURI + ", ClientId: " + clientId + "]");
173+
IMqttToken token = null;
174+
175+
for (int i = 0 ; i < max_loop_count; i++ ) {
176+
token = client.connect();
177+
token.waitForCompletion();
178+
token = client.disconnect();
179+
token.waitForCompletion();
180+
}
181+
}
182+
catch(Exception e) {
183+
e.printStackTrace();
184+
Assert.fail();
185+
}
186+
finally {
187+
if (client.isConnected()) {
188+
client.disconnectForcibly();;
189+
}
190+
client.close();
191+
}
192+
}
193+
194+
161195
/**
162196
* Test connection using a remote host name for the local host.
163197
*
@@ -640,9 +674,12 @@ public void testConnectTimeout() throws Exception {
640674
Assert.fail("Should throw an timeout exception.");
641675
}
642676
catch (Exception exception) {
643-
log.log(Level.INFO, "Connect action failed at expected.");
677+
log.log(Level.INFO, "Connect action failed as expected.");
644678
Assert.assertTrue(exception instanceof MqttException);
645-
Assert.assertEquals(MqttException.REASON_CODE_CLIENT_TIMEOUT, ((MqttException) exception).getReasonCode());
679+
Assert.assertEquals((
680+
MqttException.REASON_CODE_CLIENT_TIMEOUT == ((MqttException) exception).getReasonCode() ||
681+
MqttException.REASON_CODE_CLIENT_EXCEPTION == ((MqttException) exception).getReasonCode()),
682+
true);
646683
}
647684
finally {
648685
if (mqttClient != null) {
@@ -658,12 +695,13 @@ public void testConnectTimeout() throws Exception {
658695
connectToken.waitForCompletion(5000);
659696
}
660697
catch (Exception exception) {
661-
log.log(Level.INFO, "Connect action failed at expected.");
698+
log.log(Level.INFO, "Connect action failed as expected.");
662699
Assert.assertTrue(exception instanceof MqttException);
663-
Assert.assertEquals(
664-
(MqttException.REASON_CODE_CLIENT_TIMEOUT == ((MqttException) exception).getReasonCode() ||
665-
MqttException.REASON_CODE_CONNECT_IN_PROGRESS == ((MqttException) exception).getReasonCode())
666-
, true);
700+
Assert.assertEquals((
701+
MqttException.REASON_CODE_CLIENT_TIMEOUT == ((MqttException) exception).getReasonCode() ||
702+
MqttException.REASON_CODE_CLIENT_EXCEPTION == ((MqttException) exception).getReasonCode() ||
703+
MqttException.REASON_CODE_CONNECT_IN_PROGRESS == ((MqttException) exception).getReasonCode()),
704+
true);
667705
}
668706
finally {
669707
if (mqttClient != null) {

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
3030
import org.eclipse.paho.client.mqttv3.MqttException;
3131
import org.eclipse.paho.client.mqttv3.MqttMessage;
32+
import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
3233
import org.eclipse.paho.client.mqttv3.internal.wire.MqttPublish;
3334
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
3435
import org.eclipse.paho.client.mqttv3.test.logging.LoggingUtilities;
@@ -312,6 +313,75 @@ public void testDeleteOldestBufferedMessages() throws Exception {
312313
proxy.disableProxy();
313314
}
314315

316+
317+
/**
318+
* Tests that the buffer correctly handles persisted messages being buffered when the
319+
* buffer is full and deleteOldestBufferedMessage is set to true.
320+
*/
321+
@Test
322+
public void testDeleteOldestBufferedMessagesWithPersistance() throws Exception {
323+
String methodName = Utility.getMethodName();
324+
LoggingUtilities.banner(log, cclass, methodName);
325+
int maxMessages = 10;
326+
327+
// Tokens
328+
IMqttToken connectToken;
329+
330+
MqttClientPersistence persistence = new MemoryPersistence();
331+
332+
// Client Options
333+
MqttConnectOptions options = new MqttConnectOptions();
334+
options.setCleanSession(false);
335+
options.setAutomaticReconnect(false);
336+
MqttAsyncClient client = new MqttAsyncClient("tcp://localhost:" + proxy.getLocalPort(), methodName, persistence);
337+
DisconnectedBufferOptions disconnectedOpts = new DisconnectedBufferOptions();
338+
disconnectedOpts.setBufferEnabled(true);
339+
// Set buffer to 100 to save time
340+
disconnectedOpts.setBufferSize(maxMessages);
341+
disconnectedOpts.setPersistBuffer(true);
342+
disconnectedOpts.setDeleteOldestMessages(true);
343+
client.setBufferOpts(disconnectedOpts);
344+
345+
// Enable Proxy & Connect to server
346+
proxy.enableProxy();
347+
connectToken = client.connect(options);
348+
connectToken.waitForCompletion();
349+
boolean isConnected = client.isConnected();
350+
log.info("First Connection isConnected: " + isConnected);
351+
Assert.assertTrue(isConnected);
352+
353+
// Disable Proxy and cause disconnect
354+
proxy.disableProxy();
355+
isConnected = client.isConnected();
356+
log.info("Proxy Disconnect isConnected: " + isConnected);
357+
Assert.assertFalse(isConnected);
358+
359+
int x;
360+
361+
// Publish 10 messages
362+
for (x = 0; x < maxMessages; x++) {
363+
MqttMessage message = new MqttMessage(Integer.toString(x).getBytes());
364+
client.publish(topicPrefix + methodName, message);
365+
}
366+
367+
// Publish one message too many
368+
log.info("About to publish one message too many");
369+
client.publish(topicPrefix + methodName, new MqttMessage(Integer.toString(x).getBytes()));
370+
371+
Assert.assertFalse(persistence.containsKey("sb-1"));
372+
Assert.assertTrue(persistence.containsKey("sb-2"));
373+
Assert.assertTrue(persistence.containsKey("sb-11"));
374+
375+
// Make sure that the message now at index 0 in the buffer is '1'
376+
// instead of '0'
377+
MqttMessage messageAt0 = client.getBufferedMessage(0);
378+
String msg = new String(messageAt0.getPayload());
379+
Assert.assertEquals("1", msg);
380+
client.close();
381+
client = null;
382+
proxy.disableProxy();
383+
}
384+
315385
/**
316386
* Tests that A message cannot be buffered when the buffer is full and
317387
* deleteOldestBufferedMessage is set to false.

0 commit comments

Comments
 (0)