@Test public void testSubTagWithKindsOfMessage() { String tag1 = null; String tag2 = "jueyin"; String subExpress = tag2; int msgSize = 10; RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress, new RMQNormalListener()); List<Object> tag1Msgs = MQMessageFactory.getRMQMessage(tag1, topic, msgSize); List<Object> tag2Msgs = MQMessageFactory.getRMQMessage(tag2, topic, msgSize); producer.send(tag1Msgs); producer.send(tag2Msgs); producer.send(10); Assert.assertEquals("Not all are sent", msgSize * 3, producer.getAllUndupMsgBody().size()); consumer.getListener().waitForMessageConsume(MQMessageFactory.getMessageBody(tag2Msgs), consumeTime); assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())) .containsExactlyElementsIn(MQMessageFactory.getMessageBody(tag2Msgs)); } }
public static List<Object> getMsg(String topic, int msgSize) { return getMsg(topic, msgSize, null); }
@Test public void testDelayLevel2() { int delayLevel = 2; List<Object> delayMsgs = MQMessageFactory.getDelayMsg(topic, delayLevel, msgSize); producer.send(delayMsgs); Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size()); consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), DELAY_LEVEL[delayLevel - 1] * 1000 * 2); Assert.assertEquals("Not all are consumed", 0, VerifyUtils.verify(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())); Assert.assertEquals("Timer is not correct", true, VerifyUtils.verifyDelay(DELAY_LEVEL[delayLevel - 1] * 1000, ((RMQDelayListner) consumer.getListener()).getMsgDelayTimes())); }
public List<Object> getMessageBodyByTag(String tag) { if (tags.contains(tag)) { return MQMessageFactory.getMessageBody(rmqMsgs.get(tag)); } else { return new ArrayList<Object>(); } }
@Test public void testSubNullWithKindsOfMessage() { String tag1 = null; String tag2 = "jueyin"; String subExpress = null; int msgSize = 10; RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress, new RMQNormalListener()); List<Object> tag1Msgs = MQMessageFactory.getRMQMessage(tag1, topic, msgSize); List<Object> tag2Msgs = MQMessageFactory.getRMQMessage(tag2, topic, msgSize); producer.send(tag1Msgs); producer.send(tag2Msgs); Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size()); consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime); assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())) .containsExactlyElementsIn(producer.getAllMsgBody()); }
public static Map<MessageQueue, List<Object>> getMsgByMQ(List<MessageQueue> mqs, int msgSize) { return getMsgByMQ(mqs, msgSize, null); }
@Test public void testSendRandomQueues() { int msgSize = 10; List<MessageQueue> mqs = producer.getMessageQueue(); MessageQueueMsg mqMsgs = new MessageQueueMsg( MQMessageFactory.getMessageQueues(mqs.get(0), mqs.get(1), mqs.get(mqs.size() - 1)), msgSize); producer.send(mqMsgs.getMsgsWithMQ()); consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime); assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())) .containsExactlyElementsIn(mqMsgs.getMsgBodys()); assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer.getListener()).getMsgs())) .isEqualTo(true); } }
@Test public void testQueryMsg() { int msgSize = 20; String key = "jueyin"; long begin = System.currentTimeMillis(); List<Object> msgs = MQMessageFactory.getKeyMsg(topic, key, msgSize); producer.send(msgs); Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size()); List<MessageExt> queryMsgs = null; try { TestUtils.waitForMoment(500 * 3); queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 5000, System.currentTimeMillis() + 5000).getMessageList(); } catch (Exception e) { } assertThat(queryMsgs).isNotNull(); assertThat(queryMsgs.size()).isEqualTo(msgSize); }
consumeTime); consumerSubAll.getListener().waitForMessageConsume( MQMessageFactory.getMessage(msgsWithNoTag, tagMessage.getAllTagMessageBody()), consumeTime); assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerSubAll.getListener().getAllMsgBody())) .containsExactlyElementsIn(MQMessageFactory.getMessage(msgsWithNoTag, tagMessage.getAllTagMessageBody()));
public List<Object> getAllTagMessageBody() { List<Object> msgs = new ArrayList<Object>(); for (String tag : tags) { msgs.addAll(MQMessageFactory.getMessageBody(rmqMsgs.get(tag))); } return msgs; }
@Test public void testSubAllWithKindsOfMessage() { String tag1 = null; String tag2 = "jueyin"; String subExpress = "*"; int msgSize = 10; RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress, new RMQNormalListener()); List<Object> tag1Msgs = MQMessageFactory.getRMQMessage(tag1, topic, msgSize); List<Object> tag2Msgs = MQMessageFactory.getRMQMessage(tag2, topic, msgSize); producer.send(tag1Msgs); producer.send(tag2Msgs); producer.send(10); Assert.assertEquals("Not all are sent", msgSize * 3, producer.getAllUndupMsgBody().size()); consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime); assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())) .containsExactlyElementsIn(producer.getAllMsgBody()); }
public static Map<MessageQueue, List<Object>> getMsgByMQ(MessageQueue mq, int msgSize) { List<MessageQueue> mqs = new ArrayList<MessageQueue>(); mqs.add(mq); return getMsgByMQ(mqs, msgSize); }
@Test public void testSendOneQueue() { int msgSize = 20; List<MessageQueue> mqs = producer.getMessageQueue(); MessageQueueMsg mqMsgs = new MessageQueueMsg(MQMessageFactory.getMessageQueues(mqs.get(0)), msgSize); producer.send(mqMsgs.getMsgsWithMQ()); consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime); assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())) .containsExactlyElementsIn(mqMsgs.getMsgBodys()); assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer.getListener()).getMsgs())) .isEqualTo(true); }
String key = "jueyin"; long begin = System.currentTimeMillis(); List<Object> msgs = MQMessageFactory.getKeyMsg(topic, key, msgSize); producer.send(msgs); Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
consumeTime); consumerSubAll.getListener().waitForMessageConsume( MQMessageFactory.getMessage(msgsWithNoTag, tagMessage.getAllTagMessageBody()), consumeTime); assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerSubAll.getListener().getAllMsgBody())) .containsExactlyElementsIn(MQMessageFactory.getMessage(msgsWithNoTag, tagMessage.getAllTagMessageBody()));
@Test public void testSubTwoTabAndMatchOne() { String tag1 = "jueyin1"; String tag2 = "jueyin2"; String subExpress = String.format("%s||noExistTag", tag2); int msgSize = 10; RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress, new RMQNormalListener()); producer.send(tag1, msgSize); Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size()); List<Object> tag2Msgs = MQMessageFactory.getRMQMessage(tag2, topic, msgSize); producer.send(tag2Msgs); Assert.assertEquals("Not all sent succeeded", msgSize * 2, producer.getAllUndupMsgBody().size()); consumer.getListener().waitForMessageConsume(MQMessageFactory.getMessageBody(tag2Msgs), consumeTime); assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())) .containsExactlyElementsIn(MQMessageFactory.getMessageBody(tag2Msgs)); }
@Test public void testConsumeWithDiffTagAndFilter() { int msgSize = 10; String topic1 = initTopic(); String topic2 = initTopic(); String tag1 = "jueyin_tag_1"; String tag2 = "jueyin_tag_2"; RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic1, "*", new RMQNormalListener()); consumer1.subscribe(topic2, tag1); RMQNormalConsumer consumer2 = getConsumer(nsAddr, topic1, "*", new RMQNormalListener()); consumer2.subscribe(topic2, tag1); producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag2)); producer.clearMsg(); producer.send(MQMessageFactory.getMsg(topic1, msgSize)); producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag1)); boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListener(), consumer2.getListener()); assertThat(recvAll).isEqualTo(true); } }
public List<Object> getMessageBodyByTag(List<String> tags) { List<Object> msgBodys = new ArrayList<Object>(); for (String tag : tags) { msgBodys.addAll(MQMessageFactory.getMessageBody(rmqMsgs.get(tag))); } return msgBodys; }
private void init() { for (String tag : tags) { List<Object> tagMsgs = MQMessageFactory.getRMQMessage(tag, topic, msgSize); rmqMsgs.put(tag, tagMsgs); } }
@Test public void testDelayLevell() { int delayLevel = 1; List<Object> delayMsgs = MQMessageFactory.getDelayMsg(topic, delayLevel, msgSize); producer.send(delayMsgs); Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size()); consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime); Assert.assertEquals("Not all are consumed", 0, VerifyUtils.verify(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())); Assert.assertEquals("Timer is not correct", true, VerifyUtils.verifyDelay(DELAY_LEVEL[delayLevel - 1] * 1000, ((RMQDelayListner) consumer.getListener()).getMsgDelayTimes())); }