Skip to content

Commit 3fc5795

Browse files
author
Ranjan Dasgupta
authored
Merge pull request #762 from rdasgupt/test644
Merging this PR will close #644. If details provided in #644 is not clear and you need more information, please open a new issue with your use case and test case with paho logs.
2 parents 5787d6e + 4cbff00 commit 3fc5795

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

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

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

0 commit comments

Comments
 (0)