Fixed checkStyle and ErrorProne warns
This commit is contained in:
@@ -26,7 +26,7 @@ import java.util.concurrent.*;
|
||||
*/
|
||||
public class MessageCollector implements MqttCallback {
|
||||
|
||||
private final class ReceivedMessage {
|
||||
private static final class ReceivedMessage {
|
||||
|
||||
private final MqttMessage message;
|
||||
private final String topic;
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ServerIntegrationFuseTest {
|
||||
@@ -98,6 +100,6 @@ public class ServerIntegrationFuseTest {
|
||||
Message msg = m_subscriber.receive(500, TimeUnit.MILLISECONDS);
|
||||
assertNotNull("We should get notified with 'Will' message", msg);
|
||||
msg.ack();
|
||||
assertEquals(willTestamentMsg, new String(msg.getPayload()));
|
||||
assertEquals(willTestamentMsg, new String(msg.getPayload(), UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -35,6 +35,7 @@ import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static io.moquette.BrokerConstants.*;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ServerIntegrationHazelcastHandlerInterceptorTest {
|
||||
@@ -122,7 +123,7 @@ public class ServerIntegrationHazelcastHandlerInterceptorTest {
|
||||
LOG.info("*** checkPublishPassThroughCluster_Qos0 ***");
|
||||
m_listener.subscribe("/topic", 1);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS0".getBytes(), 0, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS0".getBytes(UTF_8), 0, false);
|
||||
MqttMessage messageQos0 = m_messagesCollector.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS0", messageQos0.toString());
|
||||
assertEquals(0, messageQos0.getQos());
|
||||
@@ -133,7 +134,7 @@ public class ServerIntegrationHazelcastHandlerInterceptorTest {
|
||||
LOG.info("*** checkPublishPassThroughCluster_Qos1 ***");
|
||||
m_listener.subscribe("/topic", 1);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS1".getBytes(), 1, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS1".getBytes(UTF_8), 1, false);
|
||||
MqttMessage messageQos1 = m_messagesCollector.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS1", messageQos1.toString());
|
||||
assertEquals(1, messageQos1.getQos());
|
||||
@@ -144,7 +145,7 @@ public class ServerIntegrationHazelcastHandlerInterceptorTest {
|
||||
LOG.info("*** checkPublishPassThroughCluster_Qos2 ***");
|
||||
m_listener.subscribe("/topic", 2);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(), 2, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(UTF_8), 2, false);
|
||||
MqttMessage messageQos2 = m_messagesCollector.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS2", messageQos2.toString());
|
||||
assertEquals(2, messageQos2.getQos());
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ServerIntegrationPahoTest {
|
||||
@@ -83,7 +85,6 @@ public class ServerIntegrationPahoTest {
|
||||
m_server.stopServer();
|
||||
}
|
||||
|
||||
|
||||
@Ignore("This test hasn't any meaning using in memory storage service")
|
||||
@Test
|
||||
public void testCleanSession_maintainClientSubscriptions_withServerRestart() throws Exception {
|
||||
@@ -100,12 +101,11 @@ public class ServerIntegrationPahoTest {
|
||||
|
||||
// reconnect and publish
|
||||
m_client.connect(options);
|
||||
m_client.publish("/topic", "Test my payload".getBytes(), 0, false);
|
||||
m_client.publish("/topic", "Test my payload".getBytes(UTF_8), 0, false);
|
||||
|
||||
assertEquals("/topic", m_messagesCollector.getTopic());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* subscriber A connect and subscribe on "a/b" QoS 1 subscriber B connect and subscribe on "a/+"
|
||||
* BUT with QoS 2 publisher connects and send a message "hello" on "a/b" subscriber A must
|
||||
@@ -133,15 +133,15 @@ public class ServerIntegrationPahoTest {
|
||||
subscriberB.subscribe("a/+", 2);
|
||||
|
||||
m_client.connect();
|
||||
m_client.publish("a/b", "Hello world MQTT!!".getBytes(), 2, false);
|
||||
m_client.publish("a/b", "Hello world MQTT!!".getBytes(UTF_8), 2, false);
|
||||
|
||||
MqttMessage messageOnA = cbSubscriberA.waitMessage(1);
|
||||
assertEquals("Hello world MQTT!!", new String(messageOnA.getPayload()));
|
||||
assertEquals("Hello world MQTT!!", new String(messageOnA.getPayload(), UTF_8));
|
||||
assertEquals(1, messageOnA.getQos());
|
||||
subscriberA.disconnect();
|
||||
|
||||
MqttMessage messageOnB = cbSubscriberB.waitMessage(1);
|
||||
assertEquals("Hello world MQTT!!", new String(messageOnB.getPayload()));
|
||||
assertEquals("Hello world MQTT!!", new String(messageOnB.getPayload(), UTF_8));
|
||||
assertEquals(2, messageOnB.getQos());
|
||||
subscriberB.disconnect();
|
||||
}
|
||||
@@ -180,15 +180,15 @@ public class ServerIntegrationPahoTest {
|
||||
tmpDir + File.separator + "clientForPublish");
|
||||
MqttClient clientForPublish = new MqttClient("tcp://localhost:1883", "clientForPublish", dsSubscriberPUB);
|
||||
clientForPublish.connect();
|
||||
clientForPublish.publish("topic", "Hello".getBytes(), 2, true);
|
||||
clientForPublish.publish("topic", "Hello".getBytes(UTF_8), 2, true);
|
||||
|
||||
// verify clientForSubscribe1 doesn't receive a notification but clientForSubscribe2 yes
|
||||
LOG.info("Before waiting to receive 1 sec from " + clientForSubscribe1.getClientId());
|
||||
LOG.info("Before waiting to receive 1 sec from {}", clientForSubscribe1.getClientId());
|
||||
assertFalse(clientForSubscribe1.isConnected());
|
||||
assertTrue(clientForSubscribe2.isConnected());
|
||||
LOG.info("Waiting to receive 1 sec from " + clientForSubscribe2.getClientId());
|
||||
LOG.info("Waiting to receive 1 sec from {}", clientForSubscribe2.getClientId());
|
||||
MqttMessage messageOnB = cbSubscriber2.waitMessage(1);
|
||||
assertEquals("Hello", new String(messageOnB.getPayload()));
|
||||
assertEquals("Hello", new String(messageOnB.getPayload(), UTF_8));
|
||||
}
|
||||
|
||||
// @Test
|
||||
|
||||
@@ -32,6 +32,8 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ServerIntegrationQoSValidationTest {
|
||||
@@ -92,7 +94,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS0ReceiveQoS0publishes ***");
|
||||
m_subscriber.subscribe("/topic", 0);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS0".getBytes(), 0, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS0".getBytes(UTF_8), 0, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS0", message.toString());
|
||||
assertEquals(0, message.getQos());
|
||||
@@ -103,7 +105,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS0ReceiveQoS1publishes_downgrade ***");
|
||||
m_subscriber.subscribe("/topic", 0);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS1".getBytes(), 1, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS1".getBytes(UTF_8), 1, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS1", message.toString());
|
||||
assertEquals(0, message.getQos());
|
||||
@@ -114,7 +116,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS0ReceiveQoS2publishes_downgrade ***");
|
||||
m_subscriber.subscribe("/topic", 0);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(), 2, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(UTF_8), 2, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS2", message.toString());
|
||||
assertEquals(0, message.getQos());
|
||||
@@ -125,7 +127,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS1ReceiveQoS0publishes ***");
|
||||
m_subscriber.subscribe("/topic", 1);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS0".getBytes(), 0, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS0".getBytes(UTF_8), 0, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS0", message.toString());
|
||||
assertEquals(0, message.getQos());
|
||||
@@ -136,7 +138,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS1ReceiveQoS1publishes ***");
|
||||
m_subscriber.subscribe("/topic", 1);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS1".getBytes(), 1, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS1".getBytes(UTF_8), 1, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS1", message.toString());
|
||||
assertEquals(1, message.getQos());
|
||||
@@ -147,7 +149,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS1ReceiveQoS2publishes_downgrade ***");
|
||||
m_subscriber.subscribe("/topic", 1);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(), 2, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(UTF_8), 2, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS2", message.toString());
|
||||
assertEquals(1, message.getQos());
|
||||
@@ -158,7 +160,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS2ReceiveQoS0publishes ***");
|
||||
m_subscriber.subscribe("/topic", 2);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(), 0, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(UTF_8), 0, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS2", message.toString());
|
||||
assertEquals(0, message.getQos());
|
||||
@@ -169,7 +171,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS2ReceiveQoS1publishes ***");
|
||||
m_subscriber.subscribe("/topic", 2);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(), 1, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(UTF_8), 1, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS2", message.toString());
|
||||
assertEquals(1, message.getQos());
|
||||
@@ -180,7 +182,7 @@ public class ServerIntegrationQoSValidationTest {
|
||||
LOG.info("*** checkSubscriberQoS2ReceiveQoS2publishes ***");
|
||||
m_subscriber.subscribe("/topic", 2);
|
||||
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(), 2, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT QoS2".getBytes(UTF_8), 2, false);
|
||||
MqttMessage message = m_callback.waitMessage(1);
|
||||
assertEquals("Hello world MQTT QoS2", message.toString());
|
||||
assertEquals(2, message.getQos());
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.junit.Test;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@@ -100,11 +102,11 @@ public class ServerIntegrationRestartTest {
|
||||
|
||||
// should be just one registration so a publisher receive one notification
|
||||
m_publisher.connect(CLEAN_SESSION_OPT);
|
||||
m_publisher.publish("/topic", "Hello world MQTT!!".getBytes(), 1, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT!!".getBytes(UTF_8), 1, false);
|
||||
|
||||
// read the messages
|
||||
MqttMessage msg = m_messageCollector.waitMessage(1);
|
||||
assertEquals("Hello world MQTT!!", new String(msg.getPayload()));
|
||||
assertEquals("Hello world MQTT!!", new String(msg.getPayload(), UTF_8));
|
||||
// no more messages on the same topic will be received
|
||||
assertNull(m_messageCollector.waitMessage(1));
|
||||
}
|
||||
@@ -121,7 +123,7 @@ public class ServerIntegrationRestartTest {
|
||||
m_server.startServer(IntegrationUtils.prepareTestProperties());
|
||||
|
||||
m_publisher.connect();
|
||||
m_publisher.publish("/topic", "Hello world MQTT!!".getBytes(), 0, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT!!".getBytes(UTF_8), 0, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,7 +149,7 @@ public class ServerIntegrationRestartTest {
|
||||
// publisher publishes on /topic
|
||||
m_publisher = new MqttClient("tcp://localhost:1883", "Publisher", s_pubDataStore);
|
||||
m_publisher.connect();
|
||||
m_publisher.publish("/topic", "Hello world MQTT!!".getBytes(), 1, false);
|
||||
m_publisher.publish("/topic", "Hello world MQTT!!".getBytes(UTF_8), 1, false);
|
||||
|
||||
// Expected
|
||||
// the subscriber doesn't get notified (it's fully unsubscribed)
|
||||
@@ -163,9 +165,9 @@ public class ServerIntegrationRestartTest {
|
||||
client.setCallback(collector);
|
||||
client.connect();
|
||||
client.subscribe(topic, 1);
|
||||
client.publish(topic, "Hello world MQTT!!".getBytes(), 0, false);
|
||||
client.publish(topic, "Hello world MQTT!!".getBytes(UTF_8), 0, false);
|
||||
MqttMessage msg = collector.waitMessage(1);
|
||||
assertEquals("Hello world MQTT!!", new String(msg.getPayload()));
|
||||
assertEquals("Hello world MQTT!!", new String(msg.getPayload(), UTF_8));
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.moquette.server;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -150,7 +151,7 @@ public class ServerIntegrationSSLTest {
|
||||
MqttConnectOptions secondClientOptions = new MqttConnectOptions();
|
||||
secondClientOptions.setSocketFactory(ssf);
|
||||
secondClient.connect(secondClientOptions);
|
||||
secondClient.publish("/topic", new MqttMessage("message".getBytes()));
|
||||
secondClient.publish("/topic", new MqttMessage("message".getBytes(UTF_8)));
|
||||
secondClient.disconnect();
|
||||
|
||||
m_client.disconnect();
|
||||
|
||||
@@ -65,6 +65,7 @@ public class ServerIntegrationWebSocketTest {
|
||||
m_server.stopServer();
|
||||
}
|
||||
|
||||
@SuppressWarnings("FutureReturnValueIgnored")
|
||||
@Test
|
||||
public void checkPlainConnect() throws Exception {
|
||||
LOG.info("*** checkPlainConnect ***");
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ServerLowlevelMessagesIntegrationTests {
|
||||
@@ -121,7 +122,7 @@ public class ServerLowlevelMessagesIntegrationTests {
|
||||
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
|
||||
assertTrue(System.currentTimeMillis() - connectTime > 3000);
|
||||
assertEquals(willTestamentMsg, new String(msg.getPayload(), StandardCharsets.UTF_8));
|
||||
assertEquals(willTestamentMsg, new String(msg.getPayload(), UTF_8));
|
||||
});
|
||||
|
||||
m_willSubscriber.disconnect();
|
||||
@@ -153,7 +154,7 @@ public class ServerLowlevelMessagesIntegrationTests {
|
||||
|
||||
// Verify will testament is published
|
||||
org.eclipse.paho.client.mqttv3.MqttMessage receivedTestament = m_messageCollector.waitMessage(1);
|
||||
assertEquals(willTestamentMsg, new String(receivedTestament.getPayload()));
|
||||
assertEquals(willTestamentMsg, new String(receivedTestament.getPayload(), UTF_8));
|
||||
m_willSubscriber.disconnect();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user