Skip to content

Commit 100fa35

Browse files
committed
Addressed comments from Code-Review-1. ConnectionLoss tests have been marked as ManualTests and they have been excluded from surefire.
Signed-off-by: Marco Carrer <marco.carrer@eurotech.com>
1 parent 2bd8a39 commit 100fa35

4 files changed

Lines changed: 66 additions & 14 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<excludes>
5454
<exclude>${test.exclude}</exclude>
5555
</excludes>
56+
<excludedGroups>org.eclipse.paho.client.mqttv3.test.ManualTest</excludedGroups>
5657
</configuration>
5758
</plugin>
5859
</plugins>

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/connectionLoss/ConnectionLossTest.java renamed to org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/connectionLoss/ConnectionLossManualTest.java

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2014 IBM Corp.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* and Eclipse Distribution License v1.0 which accompany this distribution.
7+
*
8+
* The Eclipse Public License is available at
9+
* http://www.eclipse.org/legal/epl-v10.html
10+
* and the Eclipse Distribution License is available at
11+
* http://www.eclipse.org/org/documents/edl-v10.php.
12+
*
13+
*******************************************************************************/
14+
115
package org.eclipse.paho.client.mqttv3.test.connectionLoss;
216

317
import java.util.Date;
@@ -13,12 +27,25 @@
1327
import org.eclipse.paho.client.mqttv3.MqttException;
1428
import org.eclipse.paho.client.mqttv3.MqttMessage;
1529
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
30+
import org.eclipse.paho.client.mqttv3.test.ManualTest;
1631
import org.junit.Assert;
1732
import org.junit.Test;
33+
import org.junit.experimental.categories.Category;
1834

19-
public class ConnectionLossTest implements MqttCallback
35+
/**
36+
* These tests verify whether paho can successfully detect a loss of connection with a broker.
37+
*
38+
* >> The tests MUST BE run manually and they WILL FAIL in an automated test environment. <<
39+
* The pom.xml of the test project, all tests categorized as ManualTests are excluded from the execution.
40+
*
41+
* The tests will print a messages in the console notifying the operator when to "unplug" the internet connection of the test machine.
42+
*
43+
* @author mcarrer
44+
*/
45+
@Category(ManualTest.class)
46+
public class ConnectionLossManualTest implements MqttCallback
2047
{
21-
static final Class<?> cclass = ConnectionLossTest.class;
48+
static final Class<?> cclass = ConnectionLossManualTest.class;
2249
private static final String className = cclass.getName();
2350
private static final Logger log = Logger.getLogger(className);
2451

@@ -28,7 +55,11 @@ public class ConnectionLossTest implements MqttCallback
2855
private char[] password = "password".toCharArray();
2956
private String clientId = "device-client-id";
3057
private String message = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
31-
58+
59+
/**
60+
* Tests whether paho can detect a connection loss with the server even if it has outbound activity by publishing messages with QoS 0.
61+
* @throws Exception
62+
*/
3263
@Test
3364
public void testConnectionLossWhilePublishingQos0()
3465
throws Exception
@@ -79,6 +110,10 @@ public void run() {
79110
}
80111

81112

113+
/**
114+
* Tests whether paho can detect a connection loss with the server even if it has outbound activity by publishing messages with QoS 1.
115+
* @throws Exception
116+
*/
82117
@Test
83118
public void testConnectionLossWhilePublishingQos1()
84119
throws Exception
@@ -130,6 +165,10 @@ public void run() {
130165
}
131166

132167

168+
/**
169+
* Tests whether paho can detect a connection loss with the server even if it has outbound activity by publishing messages with QoS 2.
170+
* @throws Exception
171+
*/
133172
@Test
134173
public void testConnectionLossWhilePublishingQos2()
135174
throws Exception
@@ -180,6 +219,10 @@ public void run() {
180219
}
181220

182221

222+
/**
223+
* Tests whether async paho can detect a connection loss with the server even if it has outbound activity by publishing messages with QoS 1.
224+
* @throws Exception
225+
*/
183226
@Test
184227
public void testConnectionLossWhilePublishingQos1Async()
185228
throws Exception
@@ -239,6 +282,10 @@ public void run() {
239282
}
240283

241284

285+
/**
286+
* Tests whether paho keeps the connection alive for 10 keep alive intervals while publishing messages with QoS 0.
287+
* @throws Exception
288+
*/
242289
@Test
243290
public void testKeepConnectionOpenWhilePublishingQos0()
244291
throws Exception
@@ -279,6 +326,10 @@ public void run() {
279326
}
280327

281328

329+
/**
330+
* Tests whether paho keeps the connection alive for 10 keep alive in idle state.
331+
* @throws Exception
332+
*/
282333
@Test
283334
public void testKeepConnectionOpenIdle()
284335
throws Exception

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ public class MqttException extends Exception {
5454
*/
5555
public static final short REASON_CODE_CLIENT_TIMEOUT = 32000;
5656

57-
/**
58-
* Client timed out while waiting to write messages to the server.
59-
*/
60-
public static final short REASON_CODE_WRITE_TIMEOUT = 32002;
61-
6257
/**
6358
* Internal error, caused by no new message IDs being available.
6459
*/
6560
public static final short REASON_CODE_NO_MESSAGE_IDS_AVAILABLE = 32001;
6661

62+
/**
63+
* Client timed out while waiting to write messages to the server.
64+
*/
65+
public static final short REASON_CODE_WRITE_TIMEOUT = 32002;
6766

6867
/**
6968
* The client is already connected.
7069
*/
71-
public static final short REASON_CODE_CLIENT_CONNECTED = 32100;
70+
public static final short REASON_CODE_CLIENT_CONNECTED = 32100;
71+
7272
/**
7373
* The client is already disconnected.
7474
*/

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/ClientState.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ public void notifySentBytes(int sentBytesCount) {
742742
}
743743
// @TRACE 631=sent bytes count={0}
744744
log.fine(CLASS_NAME, methodName, "631", new Object[] {
745-
Integer.valueOf(sentBytesCount) });
745+
new Integer(sentBytesCount) });
746746
}
747747

748748

@@ -767,7 +767,7 @@ protected void notifySent(MqttWireMessage message) {
767767
pingOutstanding++;
768768
}
769769
//@TRACE 635=ping sent. pingOutstanding: {0}
770-
log.fine(CLASS_NAME,methodName,"635",new Object[]{Integer.valueOf(pingOutstanding)});
770+
log.fine(CLASS_NAME,methodName,"635",new Object[]{ new Integer(pingOutstanding)});
771771
}
772772
}
773773
else if (message instanceof MqttPublish) {
@@ -819,7 +819,7 @@ public void notifyReceivedBytes(int receivedBytesCount) {
819819
}
820820
// @TRACE 630=received bytes count={0}
821821
log.fine(CLASS_NAME, methodName, "630", new Object[] {
822-
Integer.valueOf(receivedBytesCount) });
822+
new Integer(receivedBytesCount) });
823823
}
824824

825825
/**
@@ -861,7 +861,7 @@ protected void notifyReceivedAck(MqttAck ack) throws MqttException {
861861
}
862862
}
863863
//@TRACE 636=ping response received. pingOutstanding: {0}
864-
log.fine(CLASS_NAME,methodName,"636",new Object[]{Integer.valueOf(pingOutstanding)});
864+
log.fine(CLASS_NAME,methodName,"636",new Object[]{ new Integer(pingOutstanding)});
865865
} else if (ack instanceof MqttConnack) {
866866
int rc = ((MqttConnack) ack).getReturnCode();
867867
if (rc == 0) {
@@ -1252,7 +1252,7 @@ public Properties getDebug() {
12521252
props.put("actualInFlight", new Integer(actualInFlight));
12531253
props.put("inFlightPubRels", new Integer(inFlightPubRels));
12541254
props.put("quiescing", Boolean.valueOf(quiescing));
1255-
props.put("pingoutstanding", Integer.valueOf(pingOutstanding));
1255+
props.put("pingoutstanding", new Integer(pingOutstanding));
12561256
props.put("lastOutboundActivity", new Long(lastOutboundActivity));
12571257
props.put("lastInboundActivity", new Long(lastInboundActivity));
12581258
props.put("outboundQoS2", outboundQoS2);

0 commit comments

Comments
 (0)