Minor, fixed checkstyle and find bugs warns
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2018 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.interception.InterceptHandler;
|
||||
@@ -12,11 +28,13 @@ import java.util.List;
|
||||
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.CONNECTION_ACCEPTED;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ConnectionTestUtils {
|
||||
public final class ConnectionTestUtils {
|
||||
|
||||
public static final List<InterceptHandler> EMPTY_OBSERVERS = Collections.emptyList();
|
||||
public static final BrokerInterceptor NO_OBSERVERS_INTERCEPTOR = new BrokerInterceptor(EMPTY_OBSERVERS);
|
||||
|
||||
private ConnectionTestUtils() {
|
||||
}
|
||||
|
||||
static void assertConnectAccepted(EmbeddedChannel channel) {
|
||||
MqttConnAckMessage connAck = channel.readOutbound();
|
||||
@@ -29,14 +47,16 @@ public class ConnectionTestUtils {
|
||||
assertPublishIsCorrect(expectedTopic, expectedContent, receivedPublish);
|
||||
}
|
||||
|
||||
private static void assertPublishIsCorrect(String expectedTopic, String expectedContent, MqttPublishMessage receivedPublish) {
|
||||
private static void assertPublishIsCorrect(String expectedTopic, String expectedContent,
|
||||
MqttPublishMessage receivedPublish) {
|
||||
assertNotNull("Expecting a PUBLISH message", receivedPublish);
|
||||
final String decodedPayload = DebugUtils.payload2Str(receivedPublish.payload());
|
||||
assertEquals(expectedContent, decodedPayload);
|
||||
assertEquals(expectedTopic, receivedPublish.variableHeader().topicName());
|
||||
}
|
||||
|
||||
static void verifyReceiveRetainedPublish(EmbeddedChannel embeddedChannel, String expectedTopic, String expectedContent) {
|
||||
static void verifyReceiveRetainedPublish(EmbeddedChannel embeddedChannel, String expectedTopic,
|
||||
String expectedContent) {
|
||||
MqttPublishMessage receivedPublish = embeddedChannel.readOutbound();
|
||||
assertPublishIsCorrect(expectedTopic, expectedContent, receivedPublish);
|
||||
assertTrue("MUST be retained publish", receivedPublish.fixedHeader().isRetain());
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2018 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.spi.impl.MockAuthenticator;
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2018 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.spi.impl.MockAuthenticator;
|
||||
@@ -46,7 +61,8 @@ public class MQTTConnectionPublishTest {
|
||||
}
|
||||
|
||||
private MQTTConnection createMQTTConnection(BrokerConfiguration config, Channel channel) {
|
||||
IAuthenticator mockAuthenticator = new MockAuthenticator(singleton(FAKE_CLIENT_ID), singletonMap(TEST_USER, TEST_PWD));
|
||||
IAuthenticator mockAuthenticator = new MockAuthenticator(singleton(FAKE_CLIENT_ID),
|
||||
singletonMap(TEST_USER, TEST_PWD));
|
||||
|
||||
ISubscriptionsDirectory subscriptions = new CTrieSubscriptionDirectory();
|
||||
ISubscriptionsRepository subscriptionsRepository = new MemorySubscriptionsRepository();
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2018 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.spi.impl.MockAuthenticator;
|
||||
@@ -68,7 +83,8 @@ public class PostOfficeInternalPublishTest {
|
||||
subscriptions.init(subscriptionsRepository);
|
||||
retainedRepository = new MemoryRetainedRepository();
|
||||
|
||||
SessionRegistry sessionRegistry = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
SessionRegistry sessionRegistry = new SessionRegistry(subscriptions,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), retainedRepository, sessionRegistry,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
return sessionRegistry;
|
||||
@@ -285,7 +301,6 @@ public class PostOfficeInternalPublishTest {
|
||||
assertEquals(expectedSubscription, onlyMatchedSubscription);
|
||||
}
|
||||
|
||||
|
||||
private void verifyNoPublishIsReceived(EmbeddedChannel channel) {
|
||||
final Object messageReceived = channel.readOutbound();
|
||||
assertNull("Received an out message from processor while not expected", messageReceived);
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2018 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.spi.impl.MockAuthenticator;
|
||||
@@ -75,7 +90,8 @@ public class PostOfficePublishTest {
|
||||
subscriptions.init(subscriptionsRepository);
|
||||
retainedRepository = new MemoryRetainedRepository();
|
||||
|
||||
SessionRegistry sessionRegistry = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
SessionRegistry sessionRegistry = new SessionRegistry(subscriptions,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), retainedRepository, sessionRegistry,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
return sessionRegistry;
|
||||
@@ -235,7 +251,7 @@ public class PostOfficePublishTest {
|
||||
|
||||
// Exercise
|
||||
final ByteBuf anyPayload = Unpooled.copiedBuffer("Any payload", Charset.defaultCharset());
|
||||
sut.receivedPublishQos1(connection, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1,true,
|
||||
sut.receivedPublishQos1(connection, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1, true,
|
||||
MqttMessageBuilders.publish()
|
||||
.payload(Unpooled.copiedBuffer("Any payload", Charset.defaultCharset()))
|
||||
.qos(MqttQoS.AT_LEAST_ONCE)
|
||||
@@ -279,7 +295,7 @@ public class PostOfficePublishTest {
|
||||
ConnectionTestUtils.assertConnectAccepted(pubChannel);
|
||||
|
||||
final ByteBuf anyPayload = Unpooled.copiedBuffer("Any payload", Charset.defaultCharset());
|
||||
sut.receivedPublishQos1(pubConn, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1,true,
|
||||
sut.receivedPublishQos1(pubConn, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1, true,
|
||||
MqttMessageBuilders.publish()
|
||||
.payload(anyPayload.retainedDuplicate())
|
||||
.qos(MqttQoS.AT_LEAST_ONCE)
|
||||
@@ -317,7 +333,7 @@ public class PostOfficePublishTest {
|
||||
ConnectionTestUtils.assertConnectAccepted(pubChannel);
|
||||
|
||||
final ByteBuf anyPayload = Unpooled.copiedBuffer("Any payload", Charset.defaultCharset());
|
||||
sut.receivedPublishQos1(pubConn, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1,true,
|
||||
sut.receivedPublishQos1(pubConn, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1, true,
|
||||
MqttMessageBuilders.publish()
|
||||
.payload(anyPayload.retainedDuplicate())
|
||||
.qos(MqttQoS.AT_LEAST_ONCE)
|
||||
@@ -342,7 +358,7 @@ public class PostOfficePublishTest {
|
||||
ConnectionTestUtils.assertConnectAccepted(pubChannel);
|
||||
|
||||
final ByteBuf anyPayload = Unpooled.copiedBuffer("Any payload", Charset.defaultCharset());
|
||||
sut.receivedPublishQos1(pubConn, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1,true,
|
||||
sut.receivedPublishQos1(pubConn, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1, true,
|
||||
MqttMessageBuilders.publish()
|
||||
.payload(anyPayload)
|
||||
.qos(MqttQoS.AT_LEAST_ONCE)
|
||||
@@ -370,8 +386,8 @@ public class PostOfficePublishTest {
|
||||
.retained(true)
|
||||
.topicName(NEWS_TOPIC)
|
||||
.build();
|
||||
sut.receivedPublishQos1(connection, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1,true,
|
||||
publishMsg);
|
||||
sut.receivedPublishQos1(connection, new Topic(NEWS_TOPIC), TEST_USER, anyPayload, 1, true,
|
||||
publishMsg);
|
||||
|
||||
assertMessageIsRetained(NEWS_TOPIC);
|
||||
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2018 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.server.netty.NettyUtils;
|
||||
@@ -166,7 +181,6 @@ public class PostOfficeSubscribeTest {
|
||||
verifyFailureQos(subAckMsg);
|
||||
}
|
||||
|
||||
|
||||
private void verifyFailureQos(MqttSubAckMessage subAckMsg) {
|
||||
List<Integer> grantedQoSes = subAckMsg.payload().grantedQoSLevels();
|
||||
assertEquals(1, grantedQoSes.size());
|
||||
@@ -179,7 +193,7 @@ public class PostOfficeSubscribeTest {
|
||||
ConnectionTestUtils.assertConnectAccepted(channel);
|
||||
assertEquals("After CONNECT subscription MUST be empty", 0, subscriptions.size());
|
||||
subscribe(channel, NEWS_TOPIC, AT_MOST_ONCE);
|
||||
assertEquals("After /news subscribe, subscription MUST contain it",1, subscriptions.size());
|
||||
assertEquals("After /news subscribe, subscription MUST contain it", 1, subscriptions.size());
|
||||
|
||||
//Exercise & verify
|
||||
subscribe(channel, NEWS_TOPIC, AT_MOST_ONCE);
|
||||
@@ -199,7 +213,7 @@ public class PostOfficeSubscribeTest {
|
||||
this.sut.subscribeClientToTopics(subscribe, FAKE_CLIENT_ID, FAKE_USER_NAME, connection);
|
||||
MqttSubAckMessage subAckMsg = channel.readOutbound();
|
||||
|
||||
assertEquals("Bad topic CAN'T add any subscription",0, subscriptions.size());
|
||||
assertEquals("Bad topic CAN'T add any subscription", 0, subscriptions.size());
|
||||
verifyFailureQos(subAckMsg);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2018 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.spi.impl.MockAuthenticator;
|
||||
@@ -229,7 +244,7 @@ public class PostOfficeUnsubscribeTest {
|
||||
|
||||
// publish from another channel
|
||||
final ByteBuf anyPayload = Unpooled.copiedBuffer(firstPayload, Charset.defaultCharset());
|
||||
sut.receivedPublishQos1(anotherConnection, new Topic(topic), TEST_USER, anyPayload, 1,false,
|
||||
sut.receivedPublishQos1(anotherConnection, new Topic(topic), TEST_USER, anyPayload, 1, false,
|
||||
MqttMessageBuilders.publish()
|
||||
.payload(Unpooled.copiedBuffer(firstPayload, Charset.defaultCharset()))
|
||||
.qos(MqttQoS.AT_LEAST_ONCE)
|
||||
@@ -319,7 +334,7 @@ public class PostOfficeUnsubscribeTest {
|
||||
|
||||
private void publishQos1(MQTTConnection publisher, String topic, String payload, int messageID) {
|
||||
final ByteBuf bytePayload = Unpooled.copiedBuffer(payload, Charset.defaultCharset());
|
||||
sut.receivedPublishQos1(publisher, new Topic(topic), TEST_USER, bytePayload, messageID,false,
|
||||
sut.receivedPublishQos1(publisher, new Topic(topic), TEST_USER, bytePayload, messageID, false,
|
||||
MqttMessageBuilders.publish()
|
||||
.payload(Unpooled.copiedBuffer(payload, Charset.defaultCharset()))
|
||||
.qos(MqttQoS.AT_LEAST_ONCE)
|
||||
|
||||
@@ -1,8 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2018 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.persistence.MemoryStorageService;
|
||||
import io.moquette.server.netty.NettyUtils;
|
||||
import io.moquette.spi.ISessionsStore;
|
||||
import io.moquette.spi.impl.MockAuthenticator;
|
||||
import io.moquette.spi.impl.security.PermitAllAuthorizatorPolicy;
|
||||
import io.moquette.spi.impl.subscriptions.CTrieSubscriptionDirectory;
|
||||
@@ -22,23 +35,12 @@ import static java.util.Collections.singleton;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class SessionRegistryTest {
|
||||
|
||||
static final String FAKE_CLIENT_ID = "FAKE_123";
|
||||
static final String FAKE_CLIENT_ID2 = "FAKE_456";
|
||||
static final String PUBLISHER_ID = "Publisher";
|
||||
private static final String SUBSCRIBER_ID = "Subscriber";
|
||||
static final String NEWS_TOPIC = "/news";
|
||||
static final String BAD_FORMATTED_TOPIC = "#MQTTClient";
|
||||
|
||||
static final String TEST_USER = "fakeuser";
|
||||
static final String TEST_PWD = "fakepwd";
|
||||
static final String EVIL_TEST_USER = "eviluser";
|
||||
static final String EVIL_TEST_PWD = "unsecret";
|
||||
|
||||
private MQTTConnection connection;
|
||||
private EmbeddedChannel channel;
|
||||
@@ -60,7 +62,8 @@ public class SessionRegistryTest {
|
||||
}
|
||||
|
||||
private MQTTConnection createMQTTConnection(BrokerConfiguration config, Channel channel) {
|
||||
IAuthenticator mockAuthenticator = new MockAuthenticator(singleton(FAKE_CLIENT_ID), singletonMap(TEST_USER, TEST_PWD));
|
||||
IAuthenticator mockAuthenticator = new MockAuthenticator(singleton(FAKE_CLIENT_ID),
|
||||
singletonMap(TEST_USER, TEST_PWD));
|
||||
|
||||
ISubscriptionsDirectory subscriptions = new CTrieSubscriptionDirectory();
|
||||
ISubscriptionsRepository subscriptionsRepository = new MemorySubscriptionsRepository();
|
||||
|
||||
+2
-1
@@ -47,7 +47,8 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class ServerIntegrationPahoCanPublishOnReadBlockedTopicTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ServerIntegrationPahoCanPublishOnReadBlockedTopicTest.class);
|
||||
private static final Logger LOG =
|
||||
LoggerFactory.getLogger(ServerIntegrationPahoCanPublishOnReadBlockedTopicTest.class);
|
||||
|
||||
static MqttClientPersistence s_dataStore;
|
||||
static MqttClientPersistence s_pubDataStore;
|
||||
|
||||
@@ -26,6 +26,7 @@ import io.netty.handler.codec.mqtt.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -109,7 +110,7 @@ public class Client {
|
||||
MqttConnectPayload mqttConnectPayload = new MqttConnectPayload(
|
||||
this.clientId,
|
||||
willTestamentTopic,
|
||||
willTestamentMsg.getBytes(),
|
||||
willTestamentMsg.getBytes(Charset.forName("UTF-8")),
|
||||
null,
|
||||
null);
|
||||
MqttConnectMessage connectMessage = new MqttConnectMessage(
|
||||
|
||||
Reference in New Issue
Block a user