Skip to content

Commit 69e91eb

Browse files
authored
Merge pull request #223 from jpwsutton/develop
Adding UUIDs to test topics to avoid build clashes
2 parents 65859aa + 334191f commit 69e91eb

10 files changed

Lines changed: 92 additions & 49 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515

1616
import java.io.File;
1717
import java.net.URI;
18+
import java.util.UUID;
1819
import java.util.logging.Level;
1920
import java.util.logging.Logger;
2021

2122
import org.eclipse.paho.client.mqttv3.IMqttClient;
22-
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
23-
import org.eclipse.paho.client.mqttv3.MqttCallback;
24-
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
25-
import org.eclipse.paho.client.mqttv3.MqttException;
26-
import org.eclipse.paho.client.mqttv3.MqttMessage;
2723
import org.eclipse.paho.client.mqttv3.MqttTopic;
2824
import org.eclipse.paho.client.mqttv3.test.client.MqttClientFactoryPaho;
2925
import org.eclipse.paho.client.mqttv3.test.logging.LoggingUtilities;
@@ -51,6 +47,8 @@ public class BasicSSLTest {
5147
private static MqttClientFactoryPaho clientFactory;
5248
private static File keystorePath;
5349
private static int messageSize = 100000;
50+
private static String topicPrefix;
51+
5452

5553
/**
5654
* @throws Exception
@@ -66,6 +64,8 @@ public static void setUpBeforeClass() throws Exception {
6664
serverHost = serverURI.getHost();
6765
clientFactory = new MqttClientFactoryPaho();
6866
clientFactory.open();
67+
topicPrefix = "BasicSSLTest-" + UUID.randomUUID().toString() + "-";
68+
6969
}
7070
catch (Exception exception) {
7171
log.log(Level.SEVERE, "caught exception:", exception);
@@ -118,7 +118,7 @@ public void testSSL() throws Exception {
118118
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName);
119119
mqttClient.connect();
120120

121-
String[] topicNames = new String[]{methodName + "/Topic"};
121+
String[] topicNames = new String[]{topicPrefix + methodName + "/Topic"};
122122
int[] topicQos = {2};
123123
log.info("Subscribing to..." + topicNames[0]);
124124
mqttClient.subscribe(topicNames, topicQos);
@@ -170,7 +170,7 @@ public void testSSLWorkload() throws Exception {
170170
IMqttClient[] mqttPublisher = new IMqttClient[4];
171171
IMqttClient[] mqttSubscriber = new IMqttClient[20];
172172
try {
173-
String[] topicNames = new String[]{methodName + "/Topic"};
173+
String[] topicNames = new String[]{topicPrefix + methodName + "/Topic"};
174174
int[] topicQos = {0};
175175

176176
MqttTopic[] mqttTopic = new MqttTopic[mqttPublisher.length];
@@ -278,7 +278,7 @@ public void testSSLLargeMessage() throws Exception {
278278
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName);
279279
mqttClient.connect();
280280

281-
String[] topicNames = new String[]{methodName + "/Topic"};
281+
String[] topicNames = new String[]{topicPrefix + methodName + "/Topic"};
282282
int[] topicQos = {2};
283283
log.info("Subscribing to..." + topicNames[0]);
284284
mqttClient.subscribe(topicNames, topicQos);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.net.URI;
1717
import java.util.ArrayList;
18+
import java.util.UUID;
1819
import java.util.logging.Level;
1920
import java.util.logging.Logger;
2021

@@ -47,6 +48,8 @@ public class BasicTest {
4748

4849
private static URI serverURI;
4950
private static MqttClientFactoryPaho clientFactory;
51+
private static String topicPrefix;
52+
5053

5154
/**
5255
* @throws Exception
@@ -61,6 +64,8 @@ public static void setUpBeforeClass() throws Exception {
6164
serverURI = TestProperties.getServerURI();
6265
clientFactory = new MqttClientFactoryPaho();
6366
clientFactory.open();
67+
topicPrefix = "BasicTest-" + UUID.randomUUID().toString() + "-";
68+
6469
}
6570
catch (Exception exception) {
6671
log.log(Level.SEVERE, "caught exception:", exception);
@@ -193,7 +198,7 @@ public void testPubSub() throws Exception {
193198

194199
IMqttClient client = null;
195200
try {
196-
String topicStr = "topic" + "_02";
201+
String topicStr = topicPrefix + "topic" + "_02";
197202
String clientId = methodName;
198203
client = clientFactory.createMqttClient(serverURI, clientId);
199204

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

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

33
import java.net.URI;
4+
import java.util.UUID;
45
import java.util.concurrent.CountDownLatch;
56
import java.util.logging.Level;
67
import java.util.logging.Logger;
@@ -28,13 +29,16 @@
2829
public class Bug443142Test {
2930
private static final Logger log = Logger.getLogger(Bug443142Test.class.getName());
3031
private static URI serverURI;
32+
private static String topicPrefix;
3133

3234
@BeforeClass
3335
public static void setUpBeforeClass() throws Exception {
3436
try {
3537
String methodName = Utility.getMethodName();
3638
LoggingUtilities.banner(log, Bug443142Test.class, methodName);
3739
serverURI = TestProperties.getServerURI();
40+
topicPrefix = "Bug443142Test-" + UUID.randomUUID().toString() + "-";
41+
3842
}
3943
catch (Exception exception) {
4044
log.log(Level.SEVERE, "caught exception:", exception);
@@ -45,17 +49,18 @@ public static void setUpBeforeClass() throws Exception {
4549
@Test
4650
public void testBug443142() throws Exception {
4751
CountDownLatch stopLatch = new CountDownLatch(1);
48-
MqttClient client1 = new MqttClient(serverURI.toString(), "foo");
52+
MqttClient client1 = new MqttClient(serverURI.toString(), "Bug443142Test-" + UUID.randomUUID().toString());
4953
client1.connect();
50-
MqttClient client2 = new MqttClient(serverURI.toString(), "bar");
54+
MqttClient client2 = new MqttClient(serverURI.toString(),"Bug443142Test-" + UUID.randomUUID().toString());
5155
client2.setCallback(new MyMqttCallback(stopLatch));
5256
client2.connect();
53-
client2.subscribe("bar");
57+
String barTopic = topicPrefix + "bar";
58+
client2.subscribe( barTopic);
5459

5560
// publish messages until the queue is full > 10
5661
for (int i = 0; i < 16; i++) {
5762
MqttMessage message = new MqttMessage(("foo-" + i).getBytes());
58-
client1.publish("bar", message);
63+
client1.publish(barTopic, message);
5964
log.info("client1 publish: " + message);
6065
}
6166

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.paho.client.mqttv3.test;
1616

1717
import java.net.URI;
18+
import java.util.UUID;
1819
import java.util.logging.Level;
1920
import java.util.logging.Logger;
2021

@@ -41,6 +42,8 @@ public class LiveTakeOverTest {
4142

4243
private static URI serverURI;
4344
private static MqttClientFactoryPaho clientFactory;
45+
private static String topicPrefix;
46+
4447

4548
static enum FirstClientState {
4649
INITIAL,
@@ -51,7 +54,7 @@ static enum FirstClientState {
5154
}
5255

5356
private static String ClientId = "TakeOverClient";
54-
private static String FirstSubTopicString = "FirstClient/Topic";
57+
private static String FirstSubTopicString;
5558

5659
/**
5760
* @throws Exception
@@ -66,6 +69,9 @@ public static void setUpBeforeClass() throws Exception {
6669
serverURI = TestProperties.getServerURI();
6770
clientFactory = new MqttClientFactoryPaho();
6871
clientFactory.open();
72+
topicPrefix = "FirstClientState-" + UUID.randomUUID().toString() + "-";
73+
FirstSubTopicString = topicPrefix + "FirstClient/Topic";
74+
6975
}
7076
catch (Exception exception) {
7177
log.log(Level.SEVERE, "caught exception:", exception);
@@ -132,7 +138,7 @@ public void testLiveTakeOver() throws Exception {
132138
mqttClient.setCallback(mqttV3Receiver);
133139
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
134140
mqttConnectOptions.setCleanSession(false);
135-
mqttConnectOptions.setWill("WillTopic", "payload".getBytes(), 2, true);
141+
mqttConnectOptions.setWill(topicPrefix+"WillTopic", "payload".getBytes(), 2, true);
136142
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + ClientId);
137143
mqttClient.connect(mqttConnectOptions);
138144

@@ -227,7 +233,7 @@ void connectAndSub() {
227233
mqttClient.setCallback(mqttV3Receiver);
228234
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
229235
mqttConnectOptions.setCleanSession(false);
230-
mqttConnectOptions.setWill("WillTopic", "payload".getBytes(), 2, true);
236+
mqttConnectOptions.setWill(topicPrefix + "WillTopic", "payload".getBytes(), 2, true);
231237
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + ClientId);
232238
mqttClient.connect(mqttConnectOptions);
233239
log.info("Subscribing to..." + FirstSubTopicString);

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.net.URI;
2020
import java.util.ArrayList;
21+
import java.util.UUID;
2122
import java.util.logging.Level;
2223
import java.util.logging.Logger;
2324

@@ -46,6 +47,8 @@ public class PerSubscriptionMessageHandlerTest {
4647

4748
private static URI serverURI;
4849
private static MqttClientFactoryPaho clientFactory;
50+
private static String topicPrefix;
51+
4952

5053
/**
5154
* @throws Exception
@@ -60,6 +63,8 @@ public static void setUpBeforeClass() throws Exception {
6063
serverURI = TestProperties.getServerURI();
6164
clientFactory = new MqttClientFactoryPaho();
6265
clientFactory.open();
66+
topicPrefix = "PerSubscriptionMessageHandlerTest-" + UUID.randomUUID().toString() + "-";
67+
6368
}
6469
catch (Exception exception) {
6570
log.log(Level.SEVERE, "caught exception:", exception);
@@ -139,7 +144,7 @@ public void testSyncSubs1() throws Exception {
139144

140145
listener mylistener = new listener();
141146
IMqttClient mqttClient = clientFactory.createMqttClient(serverURI, methodName);
142-
String mytopic = "PerSubscriptionTest/topic";
147+
String mytopic = topicPrefix + "PerSubscriptionTest/topic";
143148

144149
mqttClient.connect();
145150
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName);
@@ -169,7 +174,7 @@ public void testAsyncSubs1() throws Exception {
169174

170175
listener mylistener = new listener();
171176
IMqttAsyncClient mqttClient = clientFactory.createMqttAsyncClient(serverURI, methodName);
172-
String mytopic = "PerSubscriptionTest/topic";
177+
String mytopic = topicPrefix + "PerSubscriptionTest/topic";
173178

174179
IMqttToken token = mqttClient.connect(null, null);
175180
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName);
@@ -207,7 +212,7 @@ public void testSyncCleanSessionFalse() throws Exception {
207212

208213
listener mylistener = new listener();
209214
IMqttClient mqttClient = clientFactory.createMqttClient(serverURI, methodName);
210-
String mytopic = "PerSubscriptionTest/topic";
215+
String mytopic = topicPrefix + "PerSubscriptionTest/topic";
211216

212217
MqttConnectOptions opts = new MqttConnectOptions();
213218
opts.setCleanSession(false);
@@ -259,7 +264,7 @@ public void testAsyncCleanSessionFalse() throws Exception {
259264

260265
listener mylistener = new listener();
261266
IMqttAsyncClient mqttClient = clientFactory.createMqttAsyncClient(serverURI, methodName);
262-
String mytopic = "PerSubscriptionTest/topic";
267+
String mytopic = topicPrefix + "PerSubscriptionTest/topic";
263268

264269
MqttConnectOptions opts = new MqttConnectOptions();
265270
opts.setCleanSession(false);
@@ -322,7 +327,7 @@ public void testSyncUnsubscribeRemove() throws Exception {
322327
323328
listener mylistener = new listener();
324329
IMqttClient mqttClient = clientFactory.createMqttClient(serverURI, methodName);
325-
String mytopic = "PerSubscriptionTest/topic";
330+
String mytopic = topicPrefix + "PerSubscriptionTest/topic";
326331
327332
MqttConnectOptions opts = new MqttConnectOptions();
328333
opts.setCleanSession(false);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.net.URI;
1818
import java.util.ArrayList;
19+
import java.util.UUID;
1920
import java.util.logging.Level;
2021
import java.util.logging.Logger;
2122

@@ -48,9 +49,10 @@ public class SendReceiveAsyncCallbackTest {
4849
private static URI serverURI;
4950
private static MqttClientFactoryPaho clientFactory;
5051
private boolean testFinished = false;
51-
private String topicFilter = "SendReceiveAsyncCallback/topic";
52+
private static String topicFilter;
5253
private listener myListener = new listener();
5354
private onPublish myOnPublish = new onPublish(1);
55+
private static String topicPrefix;
5456

5557
/**
5658
* @throws Exception
@@ -65,6 +67,9 @@ public static void setUpBeforeClass() throws Exception {
6567
serverURI = TestProperties.getServerURI();
6668
clientFactory = new MqttClientFactoryPaho();
6769
clientFactory.open();
70+
topicPrefix = "SendReceiveAsyncCallbackTest-" + UUID.randomUUID().toString() + "-";
71+
topicFilter = topicPrefix + "SendReceiveAsyncCallback/topic";
72+
6873
} catch (Exception exception) {
6974
log.log(Level.SEVERE, "caught exception:", exception);
7075
throw exception;

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.paho.client.mqttv3.test;
1616

1717
import java.net.URI;
18+
import java.util.UUID;
1819
import java.util.logging.Level;
1920
import java.util.logging.Logger;
2021

@@ -44,6 +45,8 @@ public class SendReceiveAsyncTest {
4445

4546
private static URI serverURI;
4647
private static MqttClientFactoryPaho clientFactory;
48+
private static String topicPrefix;
49+
4750

4851
/**
4952
* @throws Exception
@@ -58,6 +61,8 @@ public static void setUpBeforeClass() throws Exception {
5861
serverURI = TestProperties.getServerURI();
5962
clientFactory = new MqttClientFactoryPaho();
6063
clientFactory.open();
64+
topicPrefix = "SendReceiveAsyncTest-" + UUID.randomUUID().toString() + "-";
65+
6166
}
6267
catch (Exception exception) {
6368
log.log(Level.SEVERE, "caught exception:", exception);
@@ -170,7 +175,7 @@ public void testRemoteConnect() throws Exception {
170175
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName + ", cleanSession: false");
171176
connectToken.waitForCompletion();
172177

173-
String[] topicNames = new String[]{methodName + "/Topic"};
178+
String[] topicNames = new String[]{topicPrefix + methodName + "/Topic"};
174179
int[] topicQos = {0};
175180
subToken = mqttClient.subscribe(topicNames, topicQos, null, null);
176181
log.info("Subscribing to..." + topicNames[0]);
@@ -232,7 +237,7 @@ public void testLargeMessage() {
232237
connectToken.waitForCompletion();
233238

234239
int largeSize = 1000;
235-
String[] topicNames = new String[]{methodName + "/Topic"};
240+
String[] topicNames = new String[]{topicPrefix + methodName + "/Topic"};
236241
int[] topicQos = {0};
237242
byte[] message = new byte[largeSize];
238243

@@ -304,7 +309,7 @@ public void testMultipleClients() {
304309
IMqttToken disconnectToken;
305310

306311
try {
307-
String[] topicNames = new String[]{methodName + "/Topic"};
312+
String[] topicNames = new String[]{topicPrefix + methodName + "/Topic"};
308313
int[] topicQos = {0};
309314

310315
for (int i = 0; i < mqttPublisher.length; i++) {
@@ -410,7 +415,7 @@ public void testCleanStart() throws Exception {
410415
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName + ", cleanSession: false");
411416
connectToken.waitForCompletion();
412417

413-
String[] topicNames = new String[]{methodName + "/Topic"};
418+
String[] topicNames = new String[]{topicPrefix + methodName + "/Topic"};
414419
int[] topicQos = {0};
415420
subToken = mqttClient.subscribe(topicNames, topicQos, null, null);
416421
log.info("Subscribing to..." + topicNames[0]);
@@ -548,7 +553,7 @@ public void testVeryLargeMessageWithShortKeepAlive() {
548553
log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + methodName);
549554
connectToken.waitForCompletion();
550555

551-
String topic = "testLargeMsg/Topic";
556+
String topic = topicPrefix + "testLargeMsg/Topic";
552557
//10MB
553558
int largeSize = 20 * (1 << 20);
554559
byte[] message = new byte[largeSize];

0 commit comments

Comments
 (0)