org.apache.rocketmq.test.base.BaseConf Java Examples
The following examples show how to use
org.apache.rocketmq.test.base.BaseConf.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DLedgerProduceAndConsumeIT.java From rocketmq with Apache License 2.0 | 5 votes |
public BrokerConfig buildBrokerConfig(String cluster, String brokerName) { BrokerConfig brokerConfig = new BrokerConfig(); brokerConfig.setBrokerClusterName(cluster); brokerConfig.setBrokerName(brokerName); brokerConfig.setBrokerIP1("127.0.0.1"); brokerConfig.setNamesrvAddr(BaseConf.nsAddr); return brokerConfig; }
Example #2
Source File: DLedgerProduceAndConsumeIT.java From rocketmq with Apache License 2.0 | 4 votes |
@Test public void testProduceAndConsume() throws Exception { String cluster = UUID.randomUUID().toString(); String brokerName = UUID.randomUUID().toString(); String selfId = "n0"; String peers = String.format("n0-localhost:%d", nextPort()); BrokerConfig brokerConfig = buildBrokerConfig(cluster, brokerName); MessageStoreConfig storeConfig = buildStoreConfig(brokerName, peers, selfId); BrokerController brokerController = IntegrationTestBase.createAndStartBroker(storeConfig, brokerConfig); Thread.sleep(3000); Assert.assertEquals(BrokerRole.SYNC_MASTER, storeConfig.getBrokerRole()); String topic = UUID.randomUUID().toString(); String consumerGroup = UUID.randomUUID().toString(); IntegrationTestBase.initTopic(topic, BaseConf.nsAddr, cluster, 1); DefaultMQProducer producer = ProducerFactory.getRMQProducer(BaseConf.nsAddr); DefaultMQPullConsumer consumer = ConsumerFactory.getRMQPullConsumer(BaseConf.nsAddr, consumerGroup); for (int i = 0; i < 10; i++) { Message message = new Message(); message.setTopic(topic); message.setBody(("Hello" + i).getBytes()); SendResult sendResult = producer.send(message); Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus()); Assert.assertEquals(0, sendResult.getMessageQueue().getQueueId()); Assert.assertEquals(brokerName, sendResult.getMessageQueue().getBrokerName()); Assert.assertEquals(i, sendResult.getQueueOffset()); Assert.assertNotNull(sendResult.getMsgId()); Assert.assertNotNull(sendResult.getOffsetMsgId()); } Thread.sleep(500); Assert.assertEquals(0, brokerController.getMessageStore().getMinOffsetInQueue(topic, 0)); Assert.assertEquals(10, brokerController.getMessageStore().getMaxOffsetInQueue(topic, 0)); MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0); PullResult pullResult= consumer.pull(messageQueue, "*", 0, 32); Assert.assertEquals(PullStatus.FOUND, pullResult.getPullStatus()); Assert.assertEquals(10, pullResult.getMsgFoundList().size()); for (int i = 0; i < 10; i++) { MessageExt messageExt = pullResult.getMsgFoundList().get(i); Assert.assertEquals(i, messageExt.getQueueOffset()); Assert.assertArrayEquals(("Hello" + i).getBytes(), messageExt.getBody()); } producer.shutdown(); consumer.shutdown(); brokerController.shutdown(); }