Added main client test
This commit is contained in:
@@ -101,22 +101,22 @@ public final class Client {
|
|||||||
int retries = 0;
|
int retries = 0;
|
||||||
|
|
||||||
//TODO perhaps by proto deinifinition should be an implicit retry policy
|
//TODO perhaps by proto deinifinition should be an implicit retry policy
|
||||||
for (; retries < m_connectRetries; retries++) {
|
// for (; retries < m_connectRetries; retries++) {
|
||||||
try {
|
try {
|
||||||
ConnectFuture future = m_connector.connect(new InetSocketAddress(m_hostname, m_port));
|
ConnectFuture future = m_connector.connect(new InetSocketAddress(m_hostname, m_port));
|
||||||
LOG.fine("Client waiting to connect to server");
|
LOG.fine("Client waiting to connect to server");
|
||||||
future.awaitUninterruptibly();
|
future.awaitUninterruptibly();
|
||||||
m_session = future.getSession();
|
m_session = future.getSession();
|
||||||
break;
|
// break;
|
||||||
} catch (RuntimeIoException e) {
|
} catch (RuntimeIoException e) {
|
||||||
LOG.log(Level.FINE, "Failed to connect, retry " + retries + " of ("+m_connectRetries+")", e);
|
LOG.log(Level.FINE, "Failed to connect, retry " + retries + " of ("+m_connectRetries+")", e);
|
||||||
}
|
}
|
||||||
try {
|
// try {
|
||||||
Thread.sleep(1000);
|
// Thread.sleep(1000);
|
||||||
} catch (InterruptedException ex) {
|
// } catch (InterruptedException ex) {
|
||||||
LOG.log(Level.SEVERE, "Error while sleeping for retry", ex);
|
// LOG.log(Level.SEVERE, "Error while sleeping for retry", ex);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (retries == m_connectRetries) {
|
if (retries == m_connectRetries) {
|
||||||
throw new MQTTException("Can't connect to the server after " + retries + "retries");
|
throw new MQTTException("Can't connect to the server after " + retries + "retries");
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.dna.mqtt.moquette.client;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.dna.mqtt.moquette.server.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author andrea
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
private static final Logger LOG = Logger.getLogger(Main.class.getName());
|
||||||
|
|
||||||
|
static boolean received;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
Client client = new Client("localhost", Server.PORT);
|
||||||
|
client.connect();
|
||||||
|
|
||||||
|
|
||||||
|
client.subscribe("/topic", new IPublishCallback() {
|
||||||
|
|
||||||
|
public void published(String topic, byte[] message) {
|
||||||
|
LOG.info("Received publush notification");
|
||||||
|
received = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
client.publish("/topic", "Test my payload".getBytes());
|
||||||
|
client.close();
|
||||||
|
|
||||||
|
|
||||||
|
assert received;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,7 +15,6 @@ import org.junit.Before;
|
|||||||
*/
|
*/
|
||||||
public class ServerIntegrationTest {
|
public class ServerIntegrationTest {
|
||||||
|
|
||||||
IoConnector connector;
|
|
||||||
boolean received;
|
boolean received;
|
||||||
Server server;
|
Server server;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user