broker/test/MQTTWebSocket: code formatter used
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
*
|
*
|
||||||
* You may elect to redistribute this code under either of these licenses.
|
* You may elect to redistribute this code under either of these licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.moquette.server;
|
package io.moquette.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -35,62 +36,61 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
@WebSocket
|
@WebSocket
|
||||||
public class MQTTWebSocket {
|
public class MQTTWebSocket {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MQTTWebSocket.class);
|
private static final Logger LOG = LoggerFactory.getLogger(MQTTWebSocket.class);
|
||||||
|
|
||||||
private Session session;
|
private Session session;
|
||||||
|
|
||||||
private final CountDownLatch connectSentLatch;
|
private final CountDownLatch connectSentLatch;
|
||||||
|
|
||||||
public MQTTWebSocket() {
|
public MQTTWebSocket() {
|
||||||
this.connectSentLatch = new CountDownLatch(1);
|
this.connectSentLatch = new CountDownLatch(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnWebSocketClose
|
@OnWebSocketClose
|
||||||
public void onClose(int statusCode, String reason) {
|
public void onClose(int statusCode, String reason) {
|
||||||
System.out.printf("Connection closed: %d - %s%n", statusCode, reason);
|
System.out.printf("Connection closed: %d - %s%n", statusCode, reason);
|
||||||
this.session = null;
|
this.session = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnWebSocketConnect
|
@OnWebSocketConnect
|
||||||
public void onConnect(Session session) throws IOException {
|
public void onConnect(Session session) throws IOException {
|
||||||
System.out.printf("Got connect: %s%n", session);
|
System.out.printf("Got connect: %s%n", session);
|
||||||
LOG.info("Got connect: %s%n", session);
|
LOG.info("Got connect: %s%n", session);
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
|
||||||
//Trivial MQTT Connect message
|
// Trivial MQTT Connect message
|
||||||
// assertEquals(12, out.readByte()); //remaining length
|
// assertEquals(12, out.readByte()); //remaining length
|
||||||
// verifyString("MQIsdp", out);
|
// verifyString("MQIsdp", out);
|
||||||
// assertEquals(0x03, out.readByte()); //protocol version
|
// assertEquals(0x03, out.readByte()); //protocol version
|
||||||
// assertEquals(0x32, out.readByte()); //flags
|
// assertEquals(0x32, out.readByte()); //flags
|
||||||
// assertEquals(2, out.readByte()); //keepAliveTimer msb
|
// assertEquals(2, out.readByte()); //keepAliveTimer msb
|
||||||
// assertEquals(0, out.readByte()); //keepAliveTimer lsb
|
// assertEquals(0, out.readByte()); //keepAliveTimer lsb
|
||||||
|
|
||||||
ByteBuffer msg = ByteBuffer.wrap(new byte[] { 0x10, //message type
|
ByteBuffer msg = ByteBuffer.wrap(new byte[]{0x10, // message type
|
||||||
0x0C, //remaining lenght 12 bytes
|
0x0C, // remaining lenght 12 bytes
|
||||||
'M', 'Q','I','s','d','p',
|
'M', 'Q', 'I', 's', 'd', 'p', 0x03, // protocol version
|
||||||
0x03, //protocol version
|
0x32, // flags
|
||||||
0x32, //flags
|
0x02, 0x00// keepAlive Timer, 2 seconds
|
||||||
0x02, 0x00// keepAlive Timer, 2 seconds
|
|
||||||
});
|
});
|
||||||
// try {
|
// try {
|
||||||
session.getRemote().sendBytes(msg);
|
session.getRemote().sendBytes(msg);
|
||||||
this.connectSentLatch.countDown();
|
this.connectSentLatch.countDown();
|
||||||
session.close(StatusCode.NORMAL, "I'm done");
|
session.close(StatusCode.NORMAL, "I'm done");
|
||||||
// } catch (IOException t) {
|
// } catch (IOException t) {
|
||||||
// LOG.error(null, t);
|
// LOG.error(null, t);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean awaitConnected(int duration, TimeUnit unit) throws InterruptedException {
|
public boolean awaitConnected(int duration, TimeUnit unit) throws InterruptedException {
|
||||||
return this.connectSentLatch.await(duration, unit);
|
return this.connectSentLatch.await(duration, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnWebSocketMessage
|
@OnWebSocketMessage
|
||||||
public void onMessage(Session session, byte[] buf, int offset, int length) {
|
public void onMessage(Session session, byte[] buf, int offset, int length) {
|
||||||
System.out.printf("Got msg: %s%n", buf);
|
System.out.printf("Got msg: %s%n", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnWebSocketError
|
@OnWebSocketError
|
||||||
public void onError(Session session, Throwable cause) {
|
public void onError(Session session, Throwable cause) {
|
||||||
System.out.printf("Got exception: %s%n", cause);
|
System.out.printf("Got exception: %s%n", cause);
|
||||||
|
|||||||
Reference in New Issue
Block a user