Skip to content

Commit fb0ab1b

Browse files
author
Ranjan Dasgupta
authored
Merge pull request #758 from rdasgupt/fix727test
Add more tests for connect disconnect tests for Async client
2 parents 27840d2 + fac1549 commit fb0ab1b

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

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

Lines changed: 34 additions & 0 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
*

0 commit comments

Comments
 (0)