Ejemplo n.º 1
0
  @Test
  public void testPoll3() throws InterruptedException {
    // 插入1条消息
    String myType = TYPE + "_";
    SwallowMessage myTypeMsg = createMessage();
    myTypeMsg.setType(myType);
    messageDAO.saveMessage(TOPIC_NAME, myTypeMsg);

    Set<String> messageTypeSet = new HashSet<String>();
    messageTypeSet.add(myType);
    ConsumerInfo consumerInfo =
        new ConsumerInfo(
            "consumerId", Destination.topic(TOPIC_NAME), ConsumerType.DURABLE_AT_LEAST_ONCE);
    BlockingQueue<SwallowMessage> queue =
        swallowBuffer.createMessageQueue(
            consumerInfo,
            tailMessageId,
            tailMessageId,
            MessageFilter.createInSetMessageFilter(messageTypeSet));

    SwallowMessage m = queue.poll(500, TimeUnit.MILLISECONDS);
    while (m == null) {
      m = queue.poll(50, TimeUnit.MILLISECONDS);
    }
    Assert.assertEquals(myType, m.getType());
  }
Ejemplo n.º 2
0
 @Before
 public void setUp() throws Exception {
   mongoClient.getMessageCollection(TOPIC_NAME).drop();
   // 插入1条消息
   SwallowMessage firstMsg = createMessage();
   firstMsg.setContent("content1");
   messageDAO.saveMessage(TOPIC_NAME, firstMsg);
   // 初始化tailMessageId
   tailMessageId = messageDAO.getMaxMessageId(TOPIC_NAME);
   // 添加9条Message
   int i = 2;
   while (i <= 10) {
     // 插入消息
     SwallowMessage msg = createMessage();
     msg.setContent("content" + i++);
     messageDAO.saveMessage(TOPIC_NAME, msg);
   }
 }