/** * Set a handler that will be called when the connection with server is closed * @param closeHandler handler to call * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient closeHandler(Handler<Void> closeHandler) { delegate.closeHandler(closeHandler); return this; }
/** * Set a handler that will be called when the connection with server is closed * @param closeHandler handler to call * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient closeHandler(Handler<Void> closeHandler) { delegate.closeHandler(closeHandler); return this; }
@Test public void closeHandler(TestContext context) throws InterruptedException { Async async = context.async(); MqttClient client = MqttClient.create(Vertx.vertx(), new MqttClientOptions() .setKeepAliveTimeSeconds(5) .setAutoKeepAlive(false) ); client.closeHandler((v) -> { async.countDown(); }); client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, c -> { assertTrue(c.succeeded()); }); async.await(); }
@Test public void closeHandler(TestContext context) throws InterruptedException { Async async = context.async(); MqttClient client = MqttClient.create(Vertx.vertx(), new MqttClientOptions() .setKeepAliveTimeSeconds(5) .setAutoKeepAlive(false) ); client.closeHandler((v) -> { async.countDown(); }); client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, c -> { assertTrue(c.succeeded()); }); async.await(); }
@Test public void tcpConnectionFails(TestContext context) { Async async = context.async(); MqttClient client = MqttClient.create(Vertx.vertx()); client.closeHandler(v -> { // when TCP connection fails, this handler should not be called, connection not established context.fail(); }); client.connect(MqttClientOptions.DEFAULT_PORT, MqttClientOptions.DEFAULT_HOST, c -> { // connection assertTrue(c.failed()); assertFalse(client.isConnected()); async.complete(); }); async.await(); }
@Test public void tcpConnectionFails(TestContext context) { Async async = context.async(); MqttClient client = MqttClient.create(Vertx.vertx()); client.closeHandler(v -> { // when TCP connection fails, this handler should not be called, connection not established context.fail(); }); client.connect(MqttClientOptions.DEFAULT_PORT, MqttClientOptions.DEFAULT_HOST, c -> { // connection assertTrue(c.failed()); assertFalse(client.isConnected()); async.complete(); }); async.await(); }
client.closeHandler(v -> {
client.closeHandler(v -> {