Introduced interceptors notification into new broker
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
package io.moquette.broker;
|
||||
|
||||
import io.moquette.interception.InterceptHandler;
|
||||
import io.moquette.spi.impl.BrokerInterceptor;
|
||||
import io.moquette.spi.impl.DebugUtils;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import io.netty.handler.codec.mqtt.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.CONNECTION_ACCEPTED;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
class ConnectionTestUtils {
|
||||
|
||||
public static final List<InterceptHandler> EMPTY_OBSERVERS = Collections.emptyList();
|
||||
public static final BrokerInterceptor NO_OBSERVERS_INTERCEPTOR = new BrokerInterceptor(EMPTY_OBSERVERS);
|
||||
|
||||
|
||||
static void assertConnectAccepted(EmbeddedChannel channel) {
|
||||
MqttConnAckMessage connAck = channel.readOutbound();
|
||||
final MqttConnectReturnCode connAckReturnCode = connAck.variableHeader().connectReturnCode();
|
||||
|
||||
@@ -53,8 +53,9 @@ public class MQTTConnectionConnectTest {
|
||||
SessionsRepository sessionsRepository = new SessionsRepository(sessionStore, null);
|
||||
subscriptions.init(sessionsRepository);
|
||||
|
||||
sessionRegistry = new SessionRegistry(subscriptions);
|
||||
postOffice = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), new MemoryRetainedRepository(), sessionRegistry);
|
||||
sessionRegistry = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
postOffice = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), new MemoryRetainedRepository(),
|
||||
sessionRegistry, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
|
||||
sut = createMQTTConnection(CONFIG);
|
||||
channel = (EmbeddedChannel) sut.channel;
|
||||
|
||||
@@ -57,9 +57,10 @@ public class MQTTConnectionPublishTest {
|
||||
SessionsRepository sessionsRepository = new SessionsRepository(sessionStore, null);
|
||||
subscriptions.init(sessionsRepository);
|
||||
|
||||
sessionRegistry = new SessionRegistry(subscriptions);
|
||||
sessionRegistry = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
final PostOffice postOffice = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(),
|
||||
new MemoryRetainedRepository(), sessionRegistry);
|
||||
new MemoryRetainedRepository(), sessionRegistry,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
return new MQTTConnection(channel, config, mockAuthenticator, sessionRegistry, postOffice);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,9 @@ public class PostOfficeInternalPublishTest {
|
||||
subscriptions.init(sessionsRepository);
|
||||
retainedRepository = new MemoryRetainedRepository();
|
||||
|
||||
SessionRegistry sessionRegistry = new SessionRegistry(subscriptions);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), retainedRepository, sessionRegistry);
|
||||
SessionRegistry sessionRegistry = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), retainedRepository, sessionRegistry,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
return sessionRegistry;
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ public class PostOfficeInternalPublishTest {
|
||||
.retained(retained)
|
||||
.qos(qos)
|
||||
.payload(Unpooled.copiedBuffer(PAYLOAD.getBytes(UTF_8))).build();
|
||||
sut.internalPublish(publish, "INTRPUBL");
|
||||
sut.internalPublish(publish);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -81,8 +81,9 @@ public class PostOfficePublishTest {
|
||||
subscriptions.init(sessionsRepository);
|
||||
retainedRepository = new MemoryRetainedRepository();
|
||||
|
||||
SessionRegistry sessionRegistry = new SessionRegistry(subscriptions);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), retainedRepository, sessionRegistry);
|
||||
SessionRegistry sessionRegistry = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), retainedRepository, sessionRegistry,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
return sessionRegistry;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,9 +79,9 @@ public class PostOfficeSubscribeTest {
|
||||
SessionsRepository sessionsRepository = new SessionsRepository(sessionStore, null);
|
||||
subscriptions.init(sessionsRepository);
|
||||
|
||||
sessionRegistry = new SessionRegistry(subscriptions);
|
||||
sessionRegistry = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), new MemoryRetainedRepository(),
|
||||
sessionRegistry);
|
||||
sessionRegistry, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
}
|
||||
|
||||
private MQTTConnection createMQTTConnection(BrokerConfiguration config, Channel channel) {
|
||||
@@ -153,7 +153,8 @@ public class PostOfficeSubscribeTest {
|
||||
when(prohibitReadOnNewsTopic.canRead(eq(new Topic(NEWS_TOPIC)), eq(FAKE_USER_NAME), eq(FAKE_CLIENT_ID)))
|
||||
.thenReturn(false);
|
||||
|
||||
sut = new PostOffice(subscriptions, prohibitReadOnNewsTopic, new MemoryRetainedRepository(), sessionRegistry);
|
||||
sut = new PostOffice(subscriptions, prohibitReadOnNewsTopic, new MemoryRetainedRepository(), sessionRegistry,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
|
||||
connection.processConnect(connectMessage);
|
||||
ConnectionTestUtils.assertConnectAccepted(channel);
|
||||
|
||||
@@ -69,8 +69,9 @@ public class PostOfficeUnsubscribeTest {
|
||||
SessionsRepository sessionsRepository = new SessionsRepository(sessionStore, null);
|
||||
subscriptions.init(sessionsRepository);
|
||||
|
||||
sessionRegistry = new SessionRegistry(subscriptions);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), new MemoryRetainedRepository(), sessionRegistry);
|
||||
sessionRegistry = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
sut = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(), new MemoryRetainedRepository(),
|
||||
sessionRegistry, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
}
|
||||
|
||||
private MQTTConnection createMQTTConnection(BrokerConfiguration config, Channel channel) {
|
||||
|
||||
@@ -69,9 +69,10 @@ public class SessionRegistryTest {
|
||||
SessionsRepository sessionsRepository = new SessionsRepository(sessionStore, null);
|
||||
subscriptions.init(sessionsRepository);
|
||||
|
||||
sut = new SessionRegistry(subscriptions);
|
||||
sut = new SessionRegistry(subscriptions, ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
final PostOffice postOffice = new PostOffice(subscriptions, new PermitAllAuthorizatorPolicy(),
|
||||
new MemoryRetainedRepository(), sut);
|
||||
new MemoryRetainedRepository(), sut,
|
||||
ConnectionTestUtils.NO_OBSERVERS_INTERCEPTOR);
|
||||
return new MQTTConnection(channel, config, mockAuthenticator, sut, postOffice);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user