List of usage examples for org.apache.commons.lang3.tuple ImmutablePair of
public static <L, R> ImmutablePair<L, R> of(final L left, final R right)
Obtains an immutable pair of from two objects inferring the generic types.
This factory allows the pair to be created using inference to obtain the generic types.
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects the first message and then wait for the redelivered * message.//from w w w .j a v a2 s .c o m * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void firstMessageInvalidOnlyQueueMessageListenerTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { long sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "firstMessageInvalidOnlyQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "firstMessageInvalidOnlyQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); publisherConfig.setPrintsPerMessageCount(sendCount / 10L); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); MessageConsumer receiver = andesJMSConsumer.getReceiver(); receiver.setMessageListener(new MessageListener() { private boolean receivedFirstMessage = false; @Override public void onMessage(Message message) { try { TextMessage textMessage = (TextMessage) message; if (!receivedFirstMessage && "#0".equals(textMessage.getText())) { receivedFirstMessage = true; } else { message.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } }); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount; i++) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } validateMessageContentAndDelay(receivedMessages, 0, 10, "#0"); Assert.assertEquals(receivedMessages.size(), sendCount + 1, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects the first message and then wait for the redelivered * message.//from w ww .ja v a2 s . c om * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * Here message receive method is used instead of the message listener to receive messages. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void firstMessageInvalidOnlyQueueMessageReceiverTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { long sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "firstMessageInvalidOnlyReceiverQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "firstMessageInvalidOnlyReceiverQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); publisherConfig.setPrintsPerMessageCount(sendCount / 10L); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); final MessageConsumer receiver = andesJMSConsumer.getReceiver(); Thread messageReceivingThread = new Thread() { private boolean receivedFirstMessage = false; public void run() { while (receiver != null) { try { TextMessage textMessage = (TextMessage) receiver.receive(); if (!receivedFirstMessage && "#0".equals(textMessage.getText())) { receivedFirstMessage = true; } else { textMessage.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } } }; messageReceivingThread.start(); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount; i++) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } validateMessageContentAndDelay(receivedMessages, 0, 10, "#0"); Assert.assertEquals(receivedMessages.size(), sendCount + 1, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects all message and then wait for the redelivered * message./*w w w . j av a 2 s . c o m*/ * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void allUnacknowledgeMessageListenerTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { int sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "multipleUnacknowledgeQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "multipleUnacknowledgeQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); MessageConsumer receiver = andesJMSConsumer.getReceiver(); receiver.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { TextMessage textMessage = (TextMessage) message; if (getMessageList(receivedMessages).contains(textMessage.getText())) { message.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } }); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount * 2; i++) { if (i < sendCount) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } else { validateMessageContentAndDelay(receivedMessages, i - sendCount, i, "#" + Integer.toString(i - sendCount)); } } Assert.assertEquals(receivedMessages.size(), sendCount * 2, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects all message and then wait for the redelivered * message.// w w w. j a v a 2 s . co m * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * Here message receive method is used instead of the message listener to receive messages. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void allUnacknowledgeMessageReceiverTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { int sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "multipleUnacknowledgeReceiverQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "multipleUnacknowledgeReceiverQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); final MessageConsumer receiver = andesJMSConsumer.getReceiver(); Thread messageReceivingThread = new Thread() { public void run() { while (receiver != null) { try { TextMessage textMessage = (TextMessage) receiver.receive(); if (getMessageList(receivedMessages).contains(textMessage.getText())) { textMessage.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } } }; messageReceivingThread.start(); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount * 2; i++) { if (i < sendCount) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } else { validateMessageContentAndDelay(receivedMessages, i - sendCount, i, "#" + Integer.toString(i - sendCount)); } } Assert.assertEquals(receivedMessages.size(), sendCount * 2, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects a message after each 3 received messages and then wait * for the redelivered message./*ww w . j a v a2 s . co m*/ * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void oneByOneUnacknowledgeMessageListenerTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { long sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "oneByOneUnacknowledgeQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "oneByOneUnacknowledgeQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); MessageConsumer receiver = andesJMSConsumer.getReceiver(); receiver.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { TextMessage textMessage = (TextMessage) message; if (Integer.parseInt(textMessage.getText().split("#")[1]) % 3 != 0 || getMessageList(receivedMessages).contains(textMessage.getText())) { message.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } }); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount; i++) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } validateMessageContentAndDelay(receivedMessages, 0, 10, "#0"); validateMessageContentAndDelay(receivedMessages, 1, 11, "#3"); validateMessageContentAndDelay(receivedMessages, 2, 12, "#6"); validateMessageContentAndDelay(receivedMessages, 3, 13, "#9"); Assert.assertEquals(receivedMessages.size(), sendCount + 4, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects a message after each 3 received messages and then wait * for the redelivered message./*w w w. jav a2s . c o m*/ * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * Here message receive method is used instead of the message listener to receive messages. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void oneByOneUnacknowledgeMessageReceiverTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { long sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "oneByOneUnacknowledgeReceiverQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "oneByOneUnacknowledgeReceiverQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); final MessageConsumer receiver = andesJMSConsumer.getReceiver(); Thread messageReceivingThread = new Thread() { public void run() { while (receiver != null) { try { TextMessage textMessage = (TextMessage) receiver.receive(); if (Integer.parseInt(textMessage.getText().split("#")[1]) % 3 != 0 || getMessageList(receivedMessages).contains(textMessage.getText())) { textMessage.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } } }; messageReceivingThread.start(); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount; i++) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } validateMessageContentAndDelay(receivedMessages, 0, 10, "#0"); validateMessageContentAndDelay(receivedMessages, 1, 11, "#3"); validateMessageContentAndDelay(receivedMessages, 2, 12, "#6"); validateMessageContentAndDelay(receivedMessages, 3, 13, "#9"); Assert.assertEquals(receivedMessages.size(), sendCount + 4, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects first 4 messages and then wait for the redelivered * message.//from ww w.ja v a 2 s . c o m * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void firstFewUnacknowledgeMessageListenerTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { long sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "firstFewUnacknowledgeQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "firstFewUnacknowledgeQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); MessageConsumer receiver = andesJMSConsumer.getReceiver(); receiver.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { TextMessage textMessage = (TextMessage) message; if (Integer.parseInt(textMessage.getText().split("#")[1]) >= 4 || getMessageList(receivedMessages).contains(textMessage.getText())) { message.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } }); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount; i++) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } validateMessageContentAndDelay(receivedMessages, 0, 10, "#0"); validateMessageContentAndDelay(receivedMessages, 1, 11, "#1"); validateMessageContentAndDelay(receivedMessages, 2, 12, "#2"); validateMessageContentAndDelay(receivedMessages, 3, 13, "#3"); Assert.assertEquals(receivedMessages.size(), sendCount + 4, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects first 4 messages and then wait for the redelivered * message./*from www . j av a2 s . c om*/ * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * Here message receive method is used instead of the message listener to receive messages. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void firstFewUnacknowledgeMessageReceiverTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { long sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "firstFewUnacknowledgeReceiverQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "firstFewUnacknowledgeReceiverQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); final MessageConsumer receiver = andesJMSConsumer.getReceiver(); Thread messageReceivingThread = new Thread() { public void run() { while (receiver != null) { try { TextMessage textMessage = (TextMessage) receiver.receive(); if (Integer.parseInt(textMessage.getText().split("#")[1]) >= 4 || getMessageList(receivedMessages).contains(textMessage.getText())) { textMessage.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } } }; messageReceivingThread.start(); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount; i++) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } validateMessageContentAndDelay(receivedMessages, 0, 10, "#0"); validateMessageContentAndDelay(receivedMessages, 1, 11, "#1"); validateMessageContentAndDelay(receivedMessages, 2, 12, "#2"); validateMessageContentAndDelay(receivedMessages, 3, 13, "#3"); Assert.assertEquals(receivedMessages.size(), sendCount + 4, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects the 8th message and then wait for the redelivered * message.//from w ww . jav a2 s . c o m * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void unacknowledgeMiddleMessageMessageListenerTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { long sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "unacknowledgeMiddleMessageQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "unacknowledgeMiddleMessageQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); MessageConsumer receiver = andesJMSConsumer.getReceiver(); receiver.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { TextMessage textMessage = (TextMessage) message; if (!textMessage.getText().equals("#7") || getMessageList(receivedMessages).contains(textMessage.getText())) { message.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } }); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount; i++) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } validateMessageContentAndDelay(receivedMessages, 6, 10, "#7"); Assert.assertEquals(receivedMessages.size(), sendCount + 1, "Message receiving failed."); }
From source file:org.wso2.mb.integration.tests.amqp.functional.RedeliveryDelayTestCase.java
/** * This test publishes 10 messages and the subscriber rejects the 8th message and then wait for the redelivered * message.//from w w w . j a va 2s .c o m * <p/> * The redelivered message is tested against the same message content with the original message and the timestamps * are also checked against the original message timestamp to make sure that the message was delayed. * Here message receive method is used instead of the message listener to receive messages. * * @throws AndesClientConfigurationException * @throws XPathExpressionException * @throws IOException * @throws JMSException * @throws AndesClientException * @throws NamingException */ @Test(groups = { "wso2.mb", "queue" }) public void unacknowledgeMiddleMessageMessageReceiverTestCase() throws AndesClientConfigurationException, XPathExpressionException, IOException, JMSException, AndesClientException, NamingException { long sendCount = 10; final List<ImmutablePair<String, Calendar>> receivedMessages = new ArrayList<>(); // Creating a consumer client configuration AndesJMSConsumerClientConfiguration consumerConfig = new AndesJMSConsumerClientConfiguration(getAMQPPort(), ExchangeType.QUEUE, "unacknowledgeMiddleMessageReceiverQueue"); consumerConfig.setAcknowledgeMode(JMSAcknowledgeMode.PER_MESSAGE_ACKNOWLEDGE); consumerConfig.setAsync(false); // Creating a publisher client configuration AndesJMSPublisherClientConfiguration publisherConfig = new AndesJMSPublisherClientConfiguration( getAMQPPort(), ExchangeType.QUEUE, "unacknowledgeMiddleMessageReceiverQueue"); publisherConfig.setNumberOfMessagesToSend(sendCount); // Creating clients AndesClient consumerClient = new AndesClient(consumerConfig, true); final AndesJMSConsumer andesJMSConsumer = consumerClient.getConsumers().get(0); final MessageConsumer receiver = andesJMSConsumer.getReceiver(); Thread messageReceivingThread = new Thread() { public void run() { while (receiver != null) { try { TextMessage textMessage = (TextMessage) receiver.receive(); if (!textMessage.getText().equals("#7") || getMessageList(receivedMessages).contains(textMessage.getText())) { textMessage.acknowledge(); } receivedMessages.add(ImmutablePair.of(textMessage.getText(), Calendar.getInstance())); andesJMSConsumer.getReceivedMessageCount().incrementAndGet(); } catch (JMSException e) { throw new RuntimeException("Exception occurred when receiving messages.", e); } } } }; messageReceivingThread.start(); AndesClient publisherClient = new AndesClient(publisherConfig, true); AndesJMSPublisher andesJMSPublisher = publisherClient.getPublishers().get(0); MessageProducer sender = andesJMSPublisher.getSender(); for (int i = 0; i < sendCount; i++) { TextMessage textMessage = andesJMSPublisher.getSession().createTextMessage("#" + Integer.toString(i)); sender.send(textMessage); } AndesClientUtils.waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME); log.info("Received Messages : " + getMessageList(receivedMessages)); for (int i = 0; i < sendCount; i++) { Assert.assertEquals(receivedMessages.get(i).getLeft(), "#" + Integer.toString(i), "Invalid messages received. #" + Integer.toString(i) + " expected."); } validateMessageContentAndDelay(receivedMessages, 6, 10, "#7"); Assert.assertEquals(receivedMessages.size(), sendCount + 1, "Message receiving failed."); }