use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class AbstractTestCase method mockLoggerAppender.
@Before
public void mockLoggerAppender() throws Exception {
DefaultMQProducer defaultMQProducer = spy(new DefaultMQProducer("loggerAppender"));
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Message message = (Message) invocationOnMock.getArgument(0);
messages.add(message);
return null;
}
}).when(defaultMQProducer).sendOneway(any(Message.class));
ProducerInstance spy = mock(ProducerInstance.class);
Field instance = ProducerInstance.class.getDeclaredField("instance");
instance.setAccessible(true);
instance.set(ProducerInstance.class, spy);
doReturn(defaultMQProducer).when(spy).getInstance(anyString(), anyString());
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class RMQNormalProducer method create.
protected void create(boolean useTLS) {
producer = new DefaultMQProducer();
producer.setProducerGroup(getProducerGroupName());
producer.setInstanceName(getProducerInstanceName());
producer.setUseTLS(useTLS);
if (nsAddr != null) {
producer.setNamesrvAddr(nsAddr);
}
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class AsyncSendExceptionIT method testQueueIdBigThanQueueNum.
@Test
public void testQueueIdBigThanQueueNum() throws Exception {
int queueId = 100;
sendFail = false;
MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
producer.send(msg, mq, new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
}
@Override
public void onException(Throwable throwable) {
sendFail = true;
}
});
int checkNum = 50;
while (!sendFail && checkNum > 0) {
checkNum--;
TestUtils.waitForMoment(100);
}
producer.shutdown();
assertThat(sendFail).isEqualTo(true);
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class AsyncSendExceptionIT method testSendSelectorNull.
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSendSelectorNull() throws Exception {
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
MessageQueueSelector selector = null;
producer.send(msg, selector, 100, SendCallBackFactory.getSendCallBack());
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class AsyncSendExceptionIT method testQueueIdSmallZero.
@Test
public void testQueueIdSmallZero() throws Exception {
int queueId = -100;
sendFail = true;
MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
producer.send(msg, mq, new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
sendFail = false;
}
@Override
public void onException(Throwable throwable) {
sendFail = true;
}
});
int checkNum = 50;
while (sendFail && checkNum > 0) {
checkNum--;
TestUtils.waitForMoment(100);
}
producer.shutdown();
assertThat(sendFail).isEqualTo(false);
}
Aggregations