broker/ServerLowlevelMessagesIntegrationTests: code formatter used

This commit is contained in:
Andreas Mager
2017-02-01 17:13:42 +01:00
parent 6f2796f851
commit 6d4f076969
@@ -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 io.moquette.server.config.IConfig; import io.moquette.server.config.IConfig;
@@ -26,7 +27,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*; import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*;
@@ -37,6 +37,7 @@ import static org.junit.Assert.*;
* @author andrea * @author andrea
*/ */
public class ServerLowlevelMessagesIntegrationTests { public class ServerLowlevelMessagesIntegrationTests {
private static final Logger LOG = LoggerFactory.getLogger(ServerLowlevelMessagesIntegrationTests.class); private static final Logger LOG = LoggerFactory.getLogger(ServerLowlevelMessagesIntegrationTests.class);
static MqttClientPersistence s_dataStore; static MqttClientPersistence s_dataStore;
Server m_server; Server m_server;
@@ -66,7 +67,7 @@ public class ServerLowlevelMessagesIntegrationTests {
public void tearDown() throws Exception { public void tearDown() throws Exception {
m_client.close(); m_client.close();
LOG.debug("After raw client close"); LOG.debug("After raw client close");
Thread.sleep(300); //to let the close event pass before server stop event Thread.sleep(300); // to let the close event pass before server stop event
m_server.stopServer(); m_server.stopServer();
LOG.debug("After asked server to stop"); LOG.debug("After asked server to stop");
IntegrationUtils.cleanPersistenceFile(m_config); IntegrationUtils.cleanPersistenceFile(m_config);
@@ -74,26 +75,31 @@ public class ServerLowlevelMessagesIntegrationTests {
@Test @Test
public void elapseKeepAliveTime() throws InterruptedException { public void elapseKeepAliveTime() throws InterruptedException {
int keepAlive = 2; //secs int keepAlive = 2; // secs
MqttConnectMessage connectMessage = createConnectMessage("FAKECLNT", keepAlive); MqttConnectMessage connectMessage = createConnectMessage("FAKECLNT", keepAlive);
/*ConnectMessage connectMessage = new ConnectMessage(); /*
connectMessage.setProtocolVersion((byte) 3); * ConnectMessage connectMessage = new ConnectMessage();
connectMessage.setClientID("FAKECLNT"); * connectMessage.setProtocolVersion((byte) 3); connectMessage.setClientID("FAKECLNT");
connectMessage.setKeepAlive(keepAlive);*/ * connectMessage.setKeepAlive(keepAlive);
*/
m_client.sendMessage(connectMessage); m_client.sendMessage(connectMessage);
//wait 2 times the keepAlive // wait 2 times the keepAlive
Thread.sleep(keepAlive * 2 * 1000); Thread.sleep(keepAlive * 2 * 1000);
assertTrue(m_client.isConnectionLost()); assertTrue(m_client.isConnectionLost());
} }
private static MqttConnectMessage createConnectMessage(String clientID, int keepAlive) { private static MqttConnectMessage createConnectMessage(String clientID, int keepAlive) {
MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0); MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(
MqttConnectVariableHeader mqttConnectVariableHeader = MqttMessageType.CONNECT,
new MqttConnectVariableHeader( false,
MqttQoS.AT_MOST_ONCE,
false,
0);
MqttConnectVariableHeader mqttConnectVariableHeader = new MqttConnectVariableHeader(
MqttVersion.MQTT_3_1.protocolName(), MqttVersion.MQTT_3_1.protocolName(),
MqttVersion.MQTT_3_1.protocolLevel(), MqttVersion.MQTT_3_1.protocolLevel(),
false, false,
@@ -119,11 +125,11 @@ public class ServerLowlevelMessagesIntegrationTests {
m_client.clientId("FAKECLNT").connect(willTestamentTopic, willTestamentMsg); m_client.clientId("FAKECLNT").connect(willTestamentTopic, willTestamentMsg);
long connectTime = System.currentTimeMillis(); long connectTime = System.currentTimeMillis();
//but after the 2 KEEP ALIVE timeout expires it gets fired, // but after the 2 KEEP ALIVE timeout expires it gets fired,
//NB it's 1,5 * KEEP_ALIVE so 3 secs and some millis to propagate the message // NB it's 1,5 * KEEP_ALIVE so 3 secs and some millis to propagate the message
org.eclipse.paho.client.mqttv3.MqttMessage msg = m_messageCollector.waitMessage(5); org.eclipse.paho.client.mqttv3.MqttMessage msg = m_messageCollector.waitMessage(5);
assertNotNull("the will message should be fired after keep alive!", msg); assertNotNull("the will message should be fired after keep alive!", msg);
//the will message hasn't to be received before the elapsing of Keep Alive timeout // the will message hasn't to be received before the elapsing of Keep Alive timeout
assertTrue(System.currentTimeMillis() - connectTime > 3000); assertTrue(System.currentTimeMillis() - connectTime > 3000);
assertEquals(willTestamentMsg, new String(msg.getPayload())); assertEquals(willTestamentMsg, new String(msg.getPayload()));
@@ -151,10 +157,10 @@ public class ServerLowlevelMessagesIntegrationTests {
m_willSubscriber.subscribe(willTestamentTopic, 0); m_willSubscriber.subscribe(willTestamentTopic, 0);
m_client.clientId("FAKECLNT").connect(willTestamentTopic, willTestamentMsg); m_client.clientId("FAKECLNT").connect(willTestamentTopic, willTestamentMsg);
//kill will publisher // kill will publisher
m_client.close(); m_client.close();
//Verify will testament is published // Verify will testament is published
org.eclipse.paho.client.mqttv3.MqttMessage receivedTestament = m_messageCollector.waitMessage(1); org.eclipse.paho.client.mqttv3.MqttMessage receivedTestament = m_messageCollector.waitMessage(1);
assertEquals(willTestamentMsg, new String(receivedTestament.getPayload())); assertEquals(willTestamentMsg, new String(receivedTestament.getPayload()));
m_willSubscriber.disconnect(); m_willSubscriber.disconnect();