Search in sources :

Example 1 with SessionStateManager

use of com.zx.sms.session.cmpp.SessionStateManager in project SMSGate by Lihuanghe.

the class TestSpeedError method test.

@Test
public void test() throws InterruptedException {
    SessionStateManager sessionhandler = (SessionStateManager) ch.pipeline().get("session");
    // 测试超速错误的重发机制
    CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
    msg.setDestterminalId(new String[] { "13800138000" });
    msg.setLinkID("0000");
    msg.setMsgContent("123");
    msg.setServiceId("10086");
    msg.setSrcId("10086");
    ch.writeOutbound(msg);
    // 等待重发
    Thread.sleep((reSendTime + 1) * 1000);
    // 一共发送了2条MT消息
    Assert.assertEquals(2, sessionhandler.getWriteCount());
    // 有一条等待发送的消息
    Assert.assertEquals(1, sessionhandler.getWaittingResp());
    ByteBuf recvMsg = ch.readOutbound();
    Assert.assertNotNull(recvMsg);
    // 新为上面等待超时,会重发一次,所以这里会收到两条
    recvMsg = ch.readOutbound();
    Assert.assertNotNull(recvMsg);
    // 回复一条超速错误
    CmppSubmitResponseMessage resp = new CmppSubmitResponseMessage(msg.getHeader().getSequenceId());
    resp.setResult(8L);
    // 把resp转化为ByteBuf
    ch.writeOutbound(resp);
    ch.writeInbound(ch.readOutbound());
    Thread.sleep((reSendTime + 2) * 1000);
    // 一共发送了3条MT消息
    Assert.assertEquals(3, sessionhandler.getWriteCount());
    // 收到超速错,会再次重发一次
    recvMsg = ch.readOutbound();
    Assert.assertNotNull(recvMsg);
    // 回复一条正确接收
    resp = new CmppSubmitResponseMessage(msg.getHeader().getSequenceId());
    resp.setResult(0L);
    // 把resp转化为ByteBuf
    ch.writeOutbound(resp);
    ch.writeInbound(ch.readOutbound());
    CmppSubmitResponseMessage respret = ch.readInbound();
    // System.out.println(respret.getRequest());
    Assert.assertSame(msg, respret.getRequest());
    Assert.assertNotEquals(respret.getMsgId(), msg.getMsgid());
    // 没有等待发送的消息
    Assert.assertEquals(0, sessionhandler.getWaittingResp());
    // 等待重发超时
    Thread.sleep((reSendTime + 1) * 1000);
    // 因为已收到response,发送成功了,不会再重发了,因此这次接收的是Null
    recvMsg = ch.readOutbound();
    Assert.assertNull(recvMsg);
}
Also used : CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) SessionStateManager(com.zx.sms.session.cmpp.SessionStateManager) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage) Test(org.junit.Test)

Example 2 with SessionStateManager

use of com.zx.sms.session.cmpp.SessionStateManager in project SMSGate by Lihuanghe.

the class ConnState method printOne.

private String printOne(EndpointEntity e) {
    StringBuilder sb = new StringBuilder();
    EndpointConnector econn = e.getSingletonConnector();
    if (econn == null)
        return "";
    Channel[] carr = econn.getallChannel();
    if (carr != null && carr.length > 0) {
        for (int i = 0; i < carr.length; i++) {
            Channel ch = carr[i];
            SessionStateManager ssm = (SessionStateManager) ch.pipeline().get("sessionStateManager");
            sb.append("\tch[");
            sb.append(ch.localAddress().toString());
            if (e instanceof ServerEndpoint) {
                sb.append("<-");
            } else {
                sb.append("->");
            }
            sb.append(ch.remoteAddress().toString() + "]");
            sb.append("\tWaitting-resp=").append(ssm.getWaittingResp());
            sb.append("\tWriteCount=").append(ssm.getWriteCount());
            sb.append("\tReadCount=").append(ssm.getReadCount());
            sb.append("\n");
        }
    }
    return sb.toString();
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) Channel(io.netty.channel.Channel) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint) SessionStateManager(com.zx.sms.session.cmpp.SessionStateManager) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint)

Aggregations

SessionStateManager (com.zx.sms.session.cmpp.SessionStateManager)2 CmppSubmitRequestMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage)1 CmppSubmitResponseMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)1 EndpointConnector (com.zx.sms.connect.manager.EndpointConnector)1 ServerEndpoint (com.zx.sms.connect.manager.ServerEndpoint)1 ByteBuf (io.netty.buffer.ByteBuf)1 Channel (io.netty.channel.Channel)1 Test (org.junit.Test)1