【迁移2015-09-23 19:46】HTTPSQS(二)

Test


  1. 新建工程,添加jar包httpsq4j.jar

  2. 新建JUnit测试

import com.daguu.lib.httpsqs4j.Httpsqs4j;
import com.daguu.lib.httpsqs4j.HttpsqsClient;
import com.daguu.lib.httpsqs4j.HttpsqsException;
import com.daguu.lib.httpsqs4j.HttpsqsStatus;
import org.junit.Before;
import org.junit.Test;
import org.springframework.util.StopWatch;
import static junit.framework.Assert.fail;

/**
 * Created by congye on 9/23/2015.
 */
public class HttpsqsTest {

    private final static String QUEUE_NAME = "KQ";
    private static final int COUNT = 5000;
    HttpsqsClient client;

    /**
     * @throws Exception
     */
    @Before
    public void before() throws Exception {
        Httpsqs4j.setConnectionInfo("192.168.56.101", 1218, "UTF-8");
        client = Httpsqs4j.createNewClient();
        HttpsqsStatus status = client.getStatus(QUEUE_NAME);
        System.out.println(status.version);
        System.out.println(status.queueName);
        System.out.println(status.maxNumber);
        System.out.println(status.getLap);
        System.out.println(status.getPosition);
        System.out.println(status.putLap);
        System.out.println(status.putPosition);
        System.out.println(status.unreadNumber);
    }

    /**
     *发包测试
     */
    @Test
    public void send() {
        StopWatch stopWatch = new StopWatch("send");
        stopWatch.start("set");
        for (int i = 0; i < COUNT; i++) {
            try {
                client.putString(QUEUE_NAME, "http://" + i + "_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo_twentwo");
            } catch (Exception e) {
                fail(e.getMessage());
                e.printStackTrace();
            }
        }
        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());

    }

    /**
     * 收包测试
     */
    @Test
    public void receive() {
        String value = "";
        StopWatch stopWatch = new StopWatch("receive");
        stopWatch.start("get");
        try {
            while (true) {
                value = client.getString(QUEUE_NAME);
                //System.out.println(value);
            }
        } catch (HttpsqsException e) {
            System.out.println(e.getMessage());
            //e.printStackTrace();
        } finally {
            stopWatch.stop();
            System.out.println(stopWatch.prettyPrint());
        }
    }

}
  1. 测试环境(和之前Kestrel环境相同)
- kestrel server服务环境,本地虚拟机,centOS6.6,只分配了650M内存,1核CPU
- jdk7,单线程,单client
- 消息个数5000,消息长度约256
  1. 发送测试结果
StopWatch 'send': running time (millis) = 3730
-----------------------------------------
ms     %     Task name
-----------------------------------------
03730  100%  set
  1. 接收测试结果
There's no data in queue [KQ].
StopWatch 'receive': running time (millis) = 3644
-----------------------------------------
ms     %     Task name
-----------------------------------------
03644  100%  get

转载于:https://my.oschina.net/twen/blog/1925443

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值