First clean of Moquette's channel abstraction to user Netty's one

This commit is contained in:
andsel
2016-01-24 19:21:24 +01:00
parent c7e82497dd
commit beb556c73c
6 changed files with 60 additions and 50 deletions
@@ -15,7 +15,7 @@
*/
package io.moquette.spi.impl;
import io.moquette.server.ServerChannel;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.AttributeKey;
import io.moquette.proto.messages.AbstractMessage;
import io.moquette.proto.messages.ConnAckMessage;
@@ -27,7 +27,7 @@ import java.util.Map;
*
* @author andrea
*/
public class DummyChannel implements ServerChannel {
public class DummyChannel extends EmbeddedChannel {
AbstractMessage m_receivedMessage;
@@ -56,17 +56,17 @@ public class DummyChannel implements ServerChannel {
return this.m_channelClosed;
}
public void write(Object value) {
try {
m_receivedMessage = (AbstractMessage) value;
if (m_receivedMessage instanceof ConnAckMessage) {
ConnAckMessage buf = (ConnAckMessage) m_receivedMessage;
m_returnCode = buf.getReturnCode();
}
} catch (Exception ex) {
throw new AssertionError("Wrong return code");
}
}
// public void write(Object value) {
// try {
// m_receivedMessage = (AbstractMessage) value;
// if (m_receivedMessage instanceof ConnAckMessage) {
// ConnAckMessage buf = (ConnAckMessage) m_receivedMessage;
// m_returnCode = buf.getReturnCode();
// }
// } catch (Exception ex) {
// throw new AssertionError("Wrong return code");
// }
// }
public byte getReturnCode() {
return m_returnCode;
@@ -28,6 +28,7 @@ import io.moquette.spi.ISessionsStore;
import io.moquette.spi.impl.security.PermitAllAuthorizator;
import io.moquette.spi.impl.subscriptions.Subscription;
import io.moquette.spi.impl.subscriptions.SubscriptionsStore;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Before;
import org.junit.Test;
@@ -163,8 +164,8 @@ public class ProtocolProcessorTest {
storageService.initStore();
subs.init(storageService.sessionsStore());
m_processor.init(subs, m_messagesStore, m_sessionStore, null, true, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
MockReceiverChannel firstReceiverSession = new MockReceiverChannel();
EmbeddedChannel firstReceiverSession = new EmbeddedChannel();
ConnectMessage connectMessage = new ConnectMessage();
connectMessage.setProtocolVersion((byte) 3);
connectMessage.setClientID(FAKE_CLIENT_ID);
@@ -172,7 +173,7 @@ public class ProtocolProcessorTest {
m_processor.processConnect(firstReceiverSession, connectMessage);
//connect the second fake subscriber
MockReceiverChannel secondReceiverSession = new MockReceiverChannel();
EmbeddedChannel secondReceiverSession = new EmbeddedChannel();
ConnectMessage connectMessage2 = new ConnectMessage();
connectMessage2.setProtocolVersion((byte) 3);
connectMessage2.setClientID(FAKE_CLIENT_ID2);