Added main client test

This commit is contained in:
selva.andre
2012-07-30 23:27:58 +02:00
parent 3169ac165a
commit 80466f6c5f
3 changed files with 44 additions and 9 deletions
@@ -101,22 +101,22 @@ public final class Client {
int retries = 0;
//TODO perhaps by proto deinifinition should be an implicit retry policy
for (; retries < m_connectRetries; retries++) {
// for (; retries < m_connectRetries; retries++) {
try {
ConnectFuture future = m_connector.connect(new InetSocketAddress(m_hostname, m_port));
LOG.fine("Client waiting to connect to server");
future.awaitUninterruptibly();
m_session = future.getSession();
break;
// break;
} catch (RuntimeIoException e) {
LOG.log(Level.FINE, "Failed to connect, retry " + retries + " of ("+m_connectRetries+")", e);
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
LOG.log(Level.SEVERE, "Error while sleeping for retry", ex);
}
}
// try {
// Thread.sleep(1000);
// } catch (InterruptedException ex) {
// LOG.log(Level.SEVERE, "Error while sleeping for retry", ex);
// }
// }
if (retries == m_connectRetries) {
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 {
IoConnector connector;
boolean received;
Server server;