// Path: src/main/java/net/eusashead/iot/mqtt/ObservableMqttClient.java
// public interface ObservableMqttClient {
// 
//     /**
//      * Get the MQTT broker URI
//      *
//      * @return the MQTT broker URI string
//      */
//     String getBrokerUri();
// 
//     /**
//      * Get the MQTT client id from the underlying MQTT client
//      *
//      * @return {@link String} client identifier
//      */
//     String getClientId();
// 
//     /**
//      * Whether the MQTT client is connected to the broker
//      *
//      * @return <code>true</code> if connected, <code>false</code> otherwise
//      */
//     boolean isConnected();
// 
//     /**
//      * Close the MQTT client
//      *
//      * @return {@link Completable} that will complete on successful closure
//      */
//     Completable close();
// 
//     /**
//      * Connect the MQTT client
//      *
//      * @return {@link Completable} that will complete on successful connection
//      */
//     Completable connect();
// 
//     /**
//      * Disconnect the MQTT client
//      *
//      * @return {@link Completable} that will complete on successful
//      *         disconnection
//      */
//     Completable disconnect();
// 
//     /**
//      * Publish an {@link PublishMessage} to a {@link String} topic.
//      *
//      * @param topic {@link String} topic name
//      * @param msg {@link PublishMessage} message to publish
//      *
//      * @return {@link Single} that will complete on successful publication with
//      *         a {@link PublishToken}
//      */
//     Single<PublishToken> publish(String topic, PublishMessage msg);
// 
//     /**
//      * Subscribe to multiple {@link String} topics to receive multiple
//      * {@link SubscribeMessage} at the given QOS levels
//      *
//      * @param topics {@link String} topic names
//      * @param qos QOS level to use for subscription
//      *
//      * @return {@link Flowable} that will receive multiple
//      *         {@link SubscribeMessage}
//      */
//     Flowable<SubscribeMessage> subscribe(String[] topics, int[] qos);
// 
//     /**
//      * Subscribe to a {@link String} topic to receive multiple
//      * {@link SubscribeMessage} at the supplied QOS level
//      *
//      * @param topic {@link String} topic name
//      * @param qos QOS level to use for subscription
//      *
//      * @return {@link Flowable} that will receive multiple
//      *         {@link SubscribeMessage}
//      */
//     Flowable<SubscribeMessage> subscribe(String topic, int qos);
// 
//     /**
//      * Unsubscribe from the given topics {@link String} array
//      *
//      * @param topics {@link String} topic names
//      *
//      * @return {@link Completable} that will complete on successful unsubscribe
//      */
//     Completable unsubscribe(String[] topics);
// 
//     /**
//      * Unsubscribe from the given topic {@link String}
//      *
//      * @param topic {@link String} topic name
//      *
//      * @return {@link Completable} that will complete on successful unsubscribe
//      */
//     Completable unsubscribe(String topic);
// 
// }


import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import eu.rekawek.toxiproxy.Proxy;
import eu.rekawek.toxiproxy.ToxiproxyClient;
import net.eusashead.iot.mqtt.ObservableMqttClient;
import java.io.IOException;
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
			}
		});
        this.brokerProxy = proxyClient.createProxy("broker", PROXY_HOST + ":" + PROXY_PORT, BROKER_HOST + ":" + BROKER_PORT);
        this.brokerProxy.enable();
        
    }
    
    @After
    public void after() throws Exception {
        
    	// Remove the proxy
        if (this.brokerProxy != null) {
            this.brokerProxy.delete();
        }
        
    }

    @Ignore
    @Test
    public void whenBrokerIsStoppedThenClientIsDisconnected() throws Throwable {
        
    	// Create client with re-connect and dirty sessions
        MqttConnectOptions options = new MqttConnectOptions();
        options.setAutomaticReconnect(false);
        options.setCleanSession(false);
        options.setKeepAliveInterval(1);
        options.setConnectionTimeout(1);
        
        String proxyUrl = "tcp://" + PROXY_HOST + ":" + PROXY_PORT;
    	MqttAsyncClient asyncClient = new MqttAsyncClient(proxyUrl, "test-client-id", new MemoryPersistence());
// Path: src/main/java/net/eusashead/iot/mqtt/ObservableMqttClient.java
// public interface ObservableMqttClient {
// 
//     /**
//      * Get the MQTT broker URI
//      *
//      * @return the MQTT broker URI string
//      */
//     String getBrokerUri();
// 
//     /**
//      * Get the MQTT client id from the underlying MQTT client
//      *
//      * @return {@link String} client identifier
//      */
//     String getClientId();
// 
//     /**
//      * Whether the MQTT client is connected to the broker
//      *
//      * @return <code>true</code> if connected, <code>false</code> otherwise
//      */
//     boolean isConnected();
// 
//     /**
//      * Close the MQTT client
//      *
//      * @return {@link Completable} that will complete on successful closure
//      */
//     Completable close();
// 
//     /**
//      * Connect the MQTT client
//      *
//      * @return {@link Completable} that will complete on successful connection
//      */
//     Completable connect();
// 
//     /**
//      * Disconnect the MQTT client
//      *
//      * @return {@link Completable} that will complete on successful
//      *         disconnection
//      */
//     Completable disconnect();
// 
//     /**
//      * Publish an {@link PublishMessage} to a {@link String} topic.
//      *
//      * @param topic {@link String} topic name
//      * @param msg {@link PublishMessage} message to publish
//      *
//      * @return {@link Single} that will complete on successful publication with
//      *         a {@link PublishToken}
//      */
//     Single<PublishToken> publish(String topic, PublishMessage msg);
// 
//     /**
//      * Subscribe to multiple {@link String} topics to receive multiple
//      * {@link SubscribeMessage} at the given QOS levels
//      *
//      * @param topics {@link String} topic names
//      * @param qos QOS level to use for subscription
//      *
//      * @return {@link Flowable} that will receive multiple
//      *         {@link SubscribeMessage}
//      */
//     Flowable<SubscribeMessage> subscribe(String[] topics, int[] qos);
// 
//     /**
//      * Subscribe to a {@link String} topic to receive multiple
//      * {@link SubscribeMessage} at the supplied QOS level
//      *
//      * @param topic {@link String} topic name
//      * @param qos QOS level to use for subscription
//      *
//      * @return {@link Flowable} that will receive multiple
//      *         {@link SubscribeMessage}
//      */
//     Flowable<SubscribeMessage> subscribe(String topic, int qos);
// 
//     /**
//      * Unsubscribe from the given topics {@link String} array
//      *
//      * @param topics {@link String} topic names
//      *
//      * @return {@link Completable} that will complete on successful unsubscribe
//      */
//     Completable unsubscribe(String[] topics);
// 
//     /**
//      * Unsubscribe from the given topic {@link String}
//      *
//      * @param topic {@link String} topic name
//      *
//      * @return {@link Completable} that will complete on successful unsubscribe
//      */
//     Completable unsubscribe(String topic);
// 
// }


// Path: src/test/java/net/eusashead/iot/mqtt/paho/ToxiproxyConnectivityITCase.java
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import eu.rekawek.toxiproxy.Proxy;
import eu.rekawek.toxiproxy.ToxiproxyClient;
import net.eusashead.iot.mqtt.ObservableMqttClient;
import java.io.IOException;
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

			}
		});
        this.brokerProxy = proxyClient.createProxy("broker", PROXY_HOST + ":" + PROXY_PORT, BROKER_HOST + ":" + BROKER_PORT);
        this.brokerProxy.enable();
        
    }
    
    @After
    public void after() throws Exception {
        
    	// Remove the proxy
        if (this.brokerProxy != null) {
            this.brokerProxy.delete();
        }
        
    }

    @Ignore
    @Test
    public void whenBrokerIsStoppedThenClientIsDisconnected() throws Throwable {
        
    	// Create client with re-connect and dirty sessions
        MqttConnectOptions options = new MqttConnectOptions();
        options.setAutomaticReconnect(false);
        options.setCleanSession(false);
        options.setKeepAliveInterval(1);
        options.setConnectionTimeout(1);
        
        String proxyUrl = "tcp://" + PROXY_HOST + ":" + PROXY_PORT;
    	MqttAsyncClient asyncClient = new MqttAsyncClient(proxyUrl, "test-client-id", new MemoryPersistence());
        ObservableMqttClient observableClient = observableClient(asyncClient, options);