Skip to content

Commit 7918dc9

Browse files
author
Ian Craggs
committed
Merge branch 'kandrej-fix-ws-disconnect' into develop
2 parents e2414c8 + 5eef8ff commit 7918dc9

5 files changed

Lines changed: 53 additions & 11 deletions

File tree

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2015 IBM Corp.
2+
* Copyright (c) 2009, 2019 IBM Corp.
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v1.0
@@ -16,6 +16,8 @@
1616

1717
import java.net.URI;
1818
import java.util.ArrayList;
19+
import java.util.Arrays;
20+
import java.util.Collection;
1921
import java.util.UUID;
2022
import java.util.logging.Level;
2123
import java.util.logging.Logger;
@@ -35,24 +37,41 @@
3537
import org.junit.Assert;
3638
import org.junit.BeforeClass;
3739
import org.junit.Test;
40+
import org.junit.runner.RunWith;
41+
import org.junit.runners.Parameterized;
42+
import org.junit.runners.Parameterized.Parameters;
3843

3944
/**
4045
*
4146
*/
47+
@RunWith(Parameterized.class)
4248
public class SendReceiveAsyncCallbackTest {
4349

4450
static final Class<?> cclass = SendReceiveAsyncTest.class;
4551
static final String className = cclass.getName();
4652
static final Logger log = Logger.getLogger(className);
4753

4854
private final int messageCount = 5;
49-
private static URI serverURI;
55+
private URI serverURI;
5056
private static MqttClientFactoryPaho clientFactory;
5157
private boolean testFinished = false;
5258
private static String topicFilter;
5359
private listener myListener = new listener();
5460
private onPublish myOnPublish = new onPublish(1);
5561
private static String topicPrefix;
62+
63+
@Parameters
64+
public static Collection<Object[]> data() throws Exception {
65+
66+
return Arrays.asList(new Object[][] {
67+
{ TestProperties.getServerURI() }, { TestProperties.getWebSocketServerURI() }
68+
});
69+
70+
}
71+
72+
public SendReceiveAsyncCallbackTest(URI serverURI) {
73+
this.serverURI = serverURI;
74+
}
5675

5776
/**
5877
* @throws Exception
@@ -64,7 +83,6 @@ public static void setUpBeforeClass() throws Exception {
6483
String methodName = Utility.getMethodName();
6584
LoggingUtilities.banner(log, cclass, methodName);
6685

67-
serverURI = TestProperties.getServerURI();
6886
clientFactory = new MqttClientFactoryPaho();
6987
clientFactory.open();
7088
topicPrefix = "SendReceiveAsyncCallbackTest-" + UUID.randomUUID().toString() + "-";

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2014 IBM Corp.
2+
* Copyright (c) 2009, 2019 IBM Corp.
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v1.0
@@ -15,6 +15,8 @@
1515
package org.eclipse.paho.client.mqttv3.test;
1616

1717
import java.net.URI;
18+
import java.util.Arrays;
19+
import java.util.Collection;
1820
import java.util.UUID;
1921
import java.util.logging.Level;
2022
import java.util.logging.Logger;
@@ -35,19 +37,37 @@
3537
import org.junit.Assert;
3638
import org.junit.BeforeClass;
3739
import org.junit.Test;
40+
import org.junit.runner.RunWith;
41+
import org.junit.runners.Parameterized;
42+
import org.junit.runners.Parameterized.Parameters;
3843

3944
/**
4045
*
4146
*/
47+
@RunWith(Parameterized.class)
4248
public class SendReceiveAsyncTest {
4349

4450
static final Class<?> cclass = SendReceiveAsyncTest.class;
4551
static final String className = cclass.getName();
4652
static final Logger log = Logger.getLogger(className);
4753

48-
private static URI serverURI;
54+
private URI serverURI;
4955
private static MqttClientFactoryPaho clientFactory;
5056
private static String topicPrefix;
57+
58+
59+
@Parameters
60+
public static Collection<Object[]> data() throws Exception {
61+
62+
return Arrays.asList(new Object[][] {
63+
{ TestProperties.getServerURI() }, { TestProperties.getWebSocketServerURI() }
64+
});
65+
66+
}
67+
68+
public SendReceiveAsyncTest(URI serverURI) {
69+
this.serverURI = serverURI;
70+
}
5171

5272

5373
/**
@@ -60,7 +80,6 @@ public static void setUpBeforeClass() throws Exception {
6080
String methodName = Utility.getMethodName();
6181
LoggingUtilities.banner(log, cclass, methodName);
6282

63-
serverURI = TestProperties.getServerURI();
6483
clientFactory = new MqttClientFactoryPaho();
6584
clientFactory.open();
6685
topicPrefix = "SendReceiveAsyncTest-" + UUID.randomUUID().toString() + "-";

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class SendReceiveTest {
4949
private static final String className = cclass.getName();
5050
private static final Logger log = Logger.getLogger(className);
5151

52-
private static URI serverURI;
52+
private URI serverURI;
5353
private static MqttClientFactoryPaho clientFactory;
5454
private static String topicPrefix;
5555

@@ -62,9 +62,9 @@ public static Collection<Object[]> data() throws Exception {
6262

6363
}
6464

65-
public SendReceiveTest(URI serverURI) {
66-
this.serverURI = serverURI;
67-
}
65+
public SendReceiveTest(URI serverURI) {
66+
this.serverURI = serverURI;
67+
}
6868

6969

7070
/**

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/websocket/WebSocketReceiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.InputStream;
2020
import java.io.PipedInputStream;
2121
import java.io.PipedOutputStream;
22+
import java.net.SocketTimeoutException;
2223

2324
import org.eclipse.paho.client.mqttv3.logging.Logger;
2425
import org.eclipse.paho.client.mqttv3.logging.LoggerFactory;
@@ -114,7 +115,8 @@ public void run() {
114115
}
115116

116117
receiving = false;
117-
118+
} catch (SocketTimeoutException ex) {
119+
// Ignore SocketTimeoutException
118120
} catch (IOException ex) {
119121
// Exception occurred whilst reading the stream.
120122
this.stop();

org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/websocket/WebSocketReceiver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.InputStream;
2020
import java.io.PipedInputStream;
2121
import java.io.PipedOutputStream;
22+
import java.net.SocketTimeoutException;
2223

2324
import org.eclipse.paho.mqttv5.client.logging.Logger;
2425
import org.eclipse.paho.mqttv5.client.logging.LoggerFactory;
@@ -115,6 +116,8 @@ public void run() {
115116

116117
receiving = false;
117118

119+
} catch (SocketTimeoutException ex) {
120+
// Ignore SocketTimeoutException
118121
} catch (IOException ex) {
119122
// Exception occurred whilst reading the stream.
120123
this.stop();

0 commit comments

Comments
 (0)