Separated all mina related stuff in classes to avoid main protocol loop to depend on mina related stuff
This commit is contained in:
+11
-5
@@ -21,6 +21,8 @@ import org.dna.mqtt.moquette.proto.messages.PublishMessage;
|
||||
import org.dna.mqtt.moquette.proto.messages.SubAckMessage;
|
||||
import org.dna.mqtt.moquette.proto.messages.SubscribeMessage;
|
||||
import org.dna.mqtt.moquette.server.ConnectionDescriptor;
|
||||
import org.dna.mqtt.moquette.server.ServerChannel;
|
||||
import org.dna.mqtt.moquette.server.mina.MinaChannel;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -35,7 +37,7 @@ public class ProtocolProcessorTest {
|
||||
final static String FAKE_CLIENT_ID = "FAKE_123";
|
||||
final static String FAKE_TOPIC = "/news";
|
||||
|
||||
IoSession m_session;
|
||||
ServerChannel m_session;
|
||||
byte m_returnCode;
|
||||
ConnectMessage connMsg;
|
||||
ProtocolProcessor m_processor;
|
||||
@@ -44,15 +46,19 @@ public class ProtocolProcessorTest {
|
||||
SubscriptionsStore subscriptions;
|
||||
AbstractMessage m_receivedMessage;
|
||||
|
||||
IoSession m_minaSession;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws InterruptedException {
|
||||
connMsg = new ConnectMessage();
|
||||
connMsg.setProcotolVersion((byte) 0x03);
|
||||
|
||||
m_session = new DummySession();
|
||||
m_minaSession = new DummySession();
|
||||
|
||||
m_session = new MinaChannel(m_minaSession);
|
||||
|
||||
m_session.getFilterChain().addFirst("MessageCatcher", new IoFilterAdapter() {
|
||||
m_minaSession.getFilterChain().addFirst("MessageCatcher", new IoFilterAdapter() {
|
||||
|
||||
@Override
|
||||
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session,
|
||||
@@ -190,8 +196,8 @@ public class ProtocolProcessorTest {
|
||||
|
||||
@Test
|
||||
public void testPublishOfRetainedMessage_afterNewSubscription() throws Exception {
|
||||
m_session.getFilterChain().remove("MessageCatcher");
|
||||
m_session.getFilterChain().addFirst("MessageCatcher", new IoFilterAdapter() {
|
||||
m_minaSession.getFilterChain().remove("MessageCatcher");
|
||||
m_minaSession.getFilterChain().addFirst("MessageCatcher", new IoFilterAdapter() {
|
||||
|
||||
@Override
|
||||
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session,
|
||||
|
||||
@@ -51,6 +51,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testSubscribe() throws Exception {
|
||||
System.out.println("*** testSubscribe ***");
|
||||
m_connection = m_mqtt.blockingConnection();
|
||||
m_connection.connect();
|
||||
|
||||
@@ -66,6 +67,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testCleanSession_maintainClientSubscriptions() throws Exception {
|
||||
System.out.println("*** testCleanSession_maintainClientSubscriptions ***");
|
||||
MQTT localMqtt = new MQTT(m_mqtt);
|
||||
localMqtt.setCleanSession(false);
|
||||
BlockingConnection connection = localMqtt.blockingConnection();
|
||||
@@ -87,6 +89,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testCleanSession_maintainClientSubscriptions_againstClientDestruction() throws Exception {
|
||||
System.out.println("*** testCleanSession_maintainClientSubscriptions_againstClientDestruction ***");
|
||||
MQTT localMqtt = new MQTT(m_mqtt);
|
||||
localMqtt.setCleanSession(false);
|
||||
BlockingConnection connection = localMqtt.blockingConnection();
|
||||
@@ -114,6 +117,7 @@ public class ServerIntegrationFuseTest {
|
||||
*/
|
||||
@Test
|
||||
public void testCleanSession_correctlyClientSubscriptions() throws Exception {
|
||||
System.out.println("*** testCleanSession_correctlyClientSubscriptions ***");
|
||||
MQTT localMqtt = new MQTT(m_mqtt);
|
||||
localMqtt.setCleanSession(false);
|
||||
BlockingConnection connection = localMqtt.blockingConnection();
|
||||
@@ -134,6 +138,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testCleanSession_maintainClientSubscriptions_withServerRestart() throws Exception {
|
||||
System.out.println("*** testCleanSession_maintainClientSubscriptions_withServerRestart ***");
|
||||
MQTT localMqtt = new MQTT(m_mqtt);
|
||||
localMqtt.setCleanSession(false);
|
||||
BlockingConnection connection = localMqtt.blockingConnection();
|
||||
@@ -160,6 +165,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testRetain_maintainMessage_againstClientDestruction() throws Exception {
|
||||
System.out.println("*** testRetain_maintainMessage_againstClientDestruction ***");
|
||||
m_connection = m_mqtt.blockingConnection();
|
||||
m_connection.connect();
|
||||
m_connection.publish("/topic", "Test my payload".getBytes(), QoS.AT_MOST_ONCE, true);
|
||||
@@ -176,6 +182,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testUnsubscribe_do_not_notify_anymore_same_session() throws Exception {
|
||||
System.out.println("*** testUnsubscribe_do_not_notify_anymore_same_session ***");
|
||||
m_connection = m_mqtt.blockingConnection();
|
||||
m_connection.connect();
|
||||
m_connection.subscribe(new Topic[] {new Topic("/topic", QoS.AT_MOST_ONCE)});
|
||||
@@ -195,6 +202,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testUnsubscribe_do_not_notify_anymore_new_session() throws Exception {
|
||||
System.out.println("*** testUnsubscribe_do_not_notify_anymore_new_session ***");
|
||||
m_connection = m_mqtt.blockingConnection();
|
||||
m_connection.connect();
|
||||
m_connection.subscribe(new Topic[] {new Topic("/topic", QoS.AT_MOST_ONCE)});
|
||||
@@ -217,6 +225,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testPublishWithQoS1() throws Exception {
|
||||
System.out.println("*** testPublishWithQoS1 ***");
|
||||
m_connection = m_mqtt.blockingConnection();
|
||||
m_connection.connect();
|
||||
|
||||
@@ -236,6 +245,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testPublishWithQoS1_notCleanSession() throws Exception {
|
||||
System.out.println("*** testPublishWithQoS1_notCleanSession ***");
|
||||
MQTT mqtt = new MQTT(m_mqtt);
|
||||
mqtt.setCleanSession(false);
|
||||
m_connection = mqtt.blockingConnection();
|
||||
@@ -275,6 +285,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testPublishWithQoS2() throws Exception {
|
||||
System.out.println("*** testPublishWithQoS2 ***");
|
||||
m_mqtt.setClientId("TestClient");
|
||||
m_connection = m_mqtt.blockingConnection();
|
||||
m_connection.connect();
|
||||
@@ -295,6 +306,7 @@ public class ServerIntegrationFuseTest {
|
||||
|
||||
@Test
|
||||
public void testPublishReceiveWithQoS2() throws Exception {
|
||||
System.out.println("*** testPublishReceiveWithQoS2 ***");
|
||||
m_mqtt.setCleanSession(false);
|
||||
m_connection = m_mqtt.blockingConnection();
|
||||
m_connection.connect();
|
||||
|
||||
Reference in New Issue
Block a user