@Test(expected = java.lang.NullPointerException.class) public void testSendMQNull() throws Exception { Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes()); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); MessageQueue messageQueue = null; producer.sendOneway(msg, messageQueue); }
private static String getString(int n, int arg[]) { StringBuilder res = new StringBuilder(); for (int i = 0; i < n; i++) { res.append(getChar(arg)); } return res.toString(); }
public static String getCheseWord(int len) { StringBuilder res = new StringBuilder(); for (int i = 0; i < len; ++i) { char str = getCheseChar(); res.append(str); } return res.toString(); }
/** * @since version3.4.6 */ @Test(expected = org.apache.rocketmq.client.exception.MQBrokerException.class) public void testSend20kChinaPropMsg() throws Exception { Message msg = MessageFactory.getRandomMessage(topic); msg.putUserProperty("key", RandomUtils.getCheseWord(32 * 1024 + 1)); producer.send(msg); }
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class) public void testSend128kMsg() throws Exception { Message msg = new Message(topic, RandomUtils.getStringWithNumber(1024 * 1024 * 4 + 1).getBytes()); producer.send(msg); }
public static String getStringWithCharacter(int n) { int arg[] = new int[] {'a', 'z' + 1, 'A', 'Z' + 1}; return getString(n, arg); }
private static char getChar(int arg[]) { int size = arg.length; int c = rd.nextInt(size / 2); c = c * 2; return (char) (getIntegerBetween(arg[c], arg[c + 1])); }
public static int getIntegerBetween(int n, int m) { if (m == n) { return n; } int res = getIntegerMoreThanZero(); return n + res % (m - n); }
@Test public void testSendMsgWithUserProperty() { Message msg = MessageFactory.getRandomMessage(topic); msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024)); SendResult sendResult = null; try { sendResult = producer.send(msg); } catch (Exception e) { } assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); } }
@Test public void testSendLess128kMsg() { Message msg = new Message(topic, RandomUtils.getStringWithNumber(128 * 1024).getBytes()); SendResult sendResult = null; try { sendResult = producer.send(msg); } catch (Exception e) { } assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); }
public static String getStringWithNumber(int n) { int arg[] = new int[] {'0', '9' + 1}; return getString(n, arg); }
private static char getChar(int arg[]) { int size = arg.length; int c = rd.nextInt(size / 2); c = c * 2; return (char) (getIntegerBetween(arg[c], arg[c + 1])); }
public static int getIntegerBetween(int n, int m) { if (m == n) { return n; } int res = getIntegerMoreThanZero(); return n + res % (m - n); }
@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.sendOneway(msg, selector, 100); }
/** * @since version3.4.6 */ @Test public void testSend10kChinaPropMsg() { Message msg = MessageFactory.getRandomMessage(topic); msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024)); SendResult sendResult = null; try { sendResult = producer.send(msg); } catch (Exception e) { } assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); } }
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class) public void testSend128kMsg() throws Exception { Message msg = new Message(topic, RandomUtils.getStringWithNumber(1024 * 1024 * 4 + 1).getBytes()); producer.send(msg); }
public static String getStringWithCharacter(int n) { int arg[] = new int[] {'a', 'z' + 1, 'A', 'Z' + 1}; return getString(n, arg); }
public static String getCheseWord(int len) { StringBuilder res = new StringBuilder(); for (int i = 0; i < len; ++i) { char str = getCheseChar(); res.append(str); } return res.toString(); }
private static String getString(int n, int arg[]) { StringBuilder res = new StringBuilder(); for (int i = 0; i < n; i++) { res.append(getChar(arg)); } return res.toString(); }
@Test public void testSendCallBackNull() throws Exception { Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes()); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); SendCallback sendCallback = null; producer.send(msg, sendCallback); }