You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by GitBox <gi...@apache.org> on 2019/12/03 14:56:31 UTC
[GitHub] [activemq-artemis] clebertsuconic commented on a change in pull
request #2906: ARTEMIS-2560 Duplicate amqp messages over cluster
clebertsuconic commented on a change in pull request #2906: ARTEMIS-2560 Duplicate amqp messages over cluster
URL: https://github.com/apache/activemq-artemis/pull/2906#discussion_r353226152
##########
File path: tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/AMQPMessageRedistributionTest.java
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.cluster.distribution;
+
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory;
+import org.apache.qpid.jms.JmsConnectionFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+public class AMQPMessageRedistributionTest extends ClusterTestBase {
+
+ final String queue = "exampleQueue";
+ final String broker0 = "amqp://localhost:61616";
+ final String broker1 = "amqp://localhost:61617";
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ start();
+ }
+
+ private void start() throws Exception {
+ setupServers();
+
+ setRedistributionDelay(0);
+ }
+
+ protected boolean isNetty() {
+ return true;
+ }
+
+ @Test
+ public void testMessageRedistributionWithoutDupAMQP() throws Exception {
+ setupCluster(MessageLoadBalancingType.ON_DEMAND);
+
+ startServers(0, 1);
+
+ setupSessionFactory(0, isNetty());
+ setupSessionFactory(1, isNetty());
+
+ createQueue(0, queue, queue, null, true, null, null, RoutingType.ANYCAST);
+ createQueue(1, queue, queue, null, true, null, null, RoutingType.ANYCAST);
+
+ waitForBindings(0, queue, 1, 0, true);
+ waitForBindings(1, queue, 1, 0, true);
+
+ waitForBindings(0, queue, 1, 0, false);
+ waitForBindings(1, queue, 1, 0, false);
+
+ final int NUMBER_OF_MESSAGES = 20;
+
+ JmsConnectionFactory factory = new JmsConnectionFactory(broker0);
+ Connection connection = factory.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(session.createQueue(queue));
+
+ for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
+ producer.send(session.createTextMessage("hello " + i));
+ }
+ connection.close();
+
+ receiveOnBothNodes(NUMBER_OF_MESSAGES);
+ }
+
+ private void receiveOnBothNodes(int NUMBER_OF_MESSAGES) throws Exception {
+ receiveBroker(broker1, 1);
+ receiveBroker(broker0, 1);
+ receiveBrokerAll(broker1, NUMBER_OF_MESSAGES - 2);
+ }
+
+ private void receiveBrokerAll(String brokerurl, int num) throws Exception {
+ JmsConnectionFactory factory = new JmsConnectionFactory(brokerurl);
+ Connection connection = factory.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(session.createQueue(queue));
+ connection.start();
+
+ for (int i = 0; i < num; i++) {
+ TextMessage msg = (TextMessage) consumer.receive(5000);
+ assertNotNull(msg);
+ }
+ Message msg = consumer.receive(2000);
Review comment:
Please... do not receive(2 seconds) and assert for null
if you expect it to be null, please receiveNoWait
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services