[
https://issues.apache.org/jira/browse/ARTEMIS-3243?focusedWorklogId=627139&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-627139
]
ASF GitHub Bot logged work on ARTEMIS-3243:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 23/Jul/21 11:57
Start Date: 23/Jul/21 11:57
Worklog Time Spent: 10m
Work Description: gemmellr commented on a change in pull request #3633:
URL: https://github.com/apache/activemq-artemis/pull/3633#discussion_r675503272
##########
File path:
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/ValidateAMQPErrorsTest.java
##########
@@ -0,0 +1,343 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.amqp.connect;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import io.vertx.core.Vertx;
+import io.vertx.proton.ProtonServerOptions;
+import
org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectConfiguration;
+import
org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectionAddressType;
+import
org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectionElement;
+import
org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPMirrorBrokerConnectionElement;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
+import
org.apache.activemq.artemis.protocol.amqp.broker.ActiveMQProtonRemotingConnection;
+import org.apache.activemq.artemis.protocol.amqp.connect.AMQPBrokerConnection;
+import
org.apache.activemq.artemis.tests.integration.amqp.AmqpClientTestSupport;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.tests.util.Wait;
+import org.apache.qpid.proton.engine.Link;
+import org.apache.qpid.proton.engine.Receiver;
+import org.apache.qpid.proton.engine.impl.ConnectionImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static java.util.EnumSet.of;
+import static org.apache.qpid.proton.engine.EndpointState.ACTIVE;
+
+/**
+ * This test will make sure the Broker connection will react accordingly to a
few misconfigs and possible errors on the network of brokers and eventually
qipd-dispatch.
+ */
+public class ValidateAMQPErrorsTest extends AmqpClientTestSupport {
+
+ protected static final int AMQP_PORT_2 = 5673;
+
+ @Override
+ protected ActiveMQServer createServer() throws Exception {
+ return createServer(AMQP_PORT, false);
+ }
+
+ /**
+ * Connecting to itself should issue an error.
+ * and the max retry should still be counted, not just keep connecting
forever.
+ */
+ @Test
+ public void testConnectItself() throws Exception {
+ try {
+ AssertionLoggerHandler.startCapture();
+ server.setIdentity("Server1");
+
+ AMQPBrokerConnectConfiguration amqpConnection = new
AMQPBrokerConnectConfiguration("test", "tcp://localhost:" +
AMQP_PORT).setReconnectAttempts(10).setRetryInterval(1);
+ amqpConnection.addElement(new AMQPMirrorBrokerConnectionElement());
+ server.getConfiguration().addAMQPConnection(amqpConnection);
+
+ server.start();
+
+ Assert.assertEquals(1, server.getBrokerConnections().size());
+ server.getBrokerConnections().forEach((t) ->
Wait.assertFalse(t::isStarted));
+ Assert.assertTrue(AssertionLoggerHandler.findText("AMQ111001")); //
max retry
+ AssertionLoggerHandler.clear();
+ Thread.sleep(100);
+ Assert.assertFalse(AssertionLoggerHandler.findText("AMQ111002")); //
there shouldn't be a retry after the last failure
+ Assert.assertFalse(AssertionLoggerHandler.findText("AMQ111003")); //
there shouldn't be a retry after the last failure
+ } finally {
+ AssertionLoggerHandler.stopCapture();
+ }
+ }
+
+ @Test
+ public void testCloseLinkOnMirror() throws Exception {
+ try {
+ AssertionLoggerHandler.startCapture();
+ server.setIdentity("Server1");
+
+ ActiveMQServer server2 = createServer(AMQP_PORT_2, false);
+
+ AMQPBrokerConnectConfiguration amqpConnection = new
AMQPBrokerConnectConfiguration("test", "tcp://localhost:" +
AMQP_PORT_2).setReconnectAttempts(-1).setRetryInterval(10);
+ amqpConnection.addElement(new AMQPMirrorBrokerConnectionElement());
+ server.getConfiguration().addAMQPConnection(amqpConnection);
+
+ server.start();
+ Assert.assertEquals(1, server.getBrokerConnections().size());
+ Wait.assertTrue(() -> AssertionLoggerHandler.findText("AMQ111002"));
+ server.getBrokerConnections().forEach((t) -> Wait.assertTrue(() ->
((AMQPBrokerConnection) t).isConnecting()));
+
+ server2.start();
+
+ server.getBrokerConnections().forEach((t) -> Wait.assertFalse(() ->
((AMQPBrokerConnection) t).isConnecting()));
+
+ createAddressAndQueues(server);
+
+ Wait.assertTrue(() -> server2.locateQueue(getQueueName()) != null);
+
+ Thread.sleep(1000);
+
+ Wait.assertEquals(1,
server2.getRemotingService()::getConnectionCount);
+ server2.getRemotingService().getConnections().forEach((t) -> {
+ try {
+ ActiveMQProtonRemotingConnection connection =
(ActiveMQProtonRemotingConnection) t;
+ ConnectionImpl protonConnection = (ConnectionImpl)
connection.getAmqpConnection().getHandler().getConnection();
+ Wait.waitFor(() -> protonConnection.linkHead(of(ACTIVE),
of(ACTIVE)) != null);
+ connection.getAmqpConnection().runNow(() -> {
+ Receiver receiver = (Receiver)
protonConnection.linkHead(of(ACTIVE), of(ACTIVE));
+ receiver.close();
+ connection.flush();
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+
+ ConnectionFactory cf1 = CFUtil.createConnectionFactory("AMQP",
"tcp://localhost:" + AMQP_PORT);
+ ConnectionFactory cf2 = CFUtil.createConnectionFactory("AMQP",
"tcp://localhost:" + AMQP_PORT_2);
+
+ try (Connection connection = cf1.createConnection()) {
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer =
session.createProducer(session.createQueue(getQueueName()));
+ for (int i = 0; i < 10; i++) {
+ producer.send(session.createTextMessage("message " + i));
+ }
+ }
+
+ // messages should still flow after a disconnect on the link
+ // the server should reconnect as if it was a failure
+ try (Connection connection = cf2.createConnection()) {
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer =
session.createConsumer(session.createQueue(getQueueName()));
+ connection.start();
+ for (int i = 0; i < 10; i++) {
+ Assert.assertEquals("message " + i, ((TextMessage)
consumer.receive(5000)).getText());
+ }
+ }
+
+ } finally {
+ AssertionLoggerHandler.stopCapture();
+ }
+ }
+
+ @Test
+ public void testCloseLinkOnSender() throws Exception {
+ testCloseLink(true);
+ }
+
+ @Test
+ public void testCloseLinkOnReceiver() throws Exception {
+ testCloseLink(false);
+ }
+
+ public void testCloseLink(boolean isSender) throws Exception {
+ try {
+ AssertionLoggerHandler.startCapture();
+ server.setIdentity("Server1");
+
+ ActiveMQServer server2 = createServer(AMQP_PORT_2, false);
+
+ if (isSender) {
+ AMQPBrokerConnectConfiguration amqpConnection = new
AMQPBrokerConnectConfiguration("test", "tcp://localhost:" +
AMQP_PORT_2).setReconnectAttempts(-1).setRetryInterval(10);
+ amqpConnection.addElement(new
AMQPBrokerConnectionElement().setMatchAddress(getQueueName()).setType(AMQPBrokerConnectionAddressType.SENDER));
+ server.getConfiguration().addAMQPConnection(amqpConnection);
+ } else {
+ AMQPBrokerConnectConfiguration amqpConnection = new
AMQPBrokerConnectConfiguration("test", "tcp://localhost:" +
AMQP_PORT).setReconnectAttempts(-1).setRetryInterval(10);
+ amqpConnection.addElement(new
AMQPBrokerConnectionElement().setMatchAddress(getQueueName()).setType(AMQPBrokerConnectionAddressType.RECEIVER));
+ server2.getConfiguration().addAMQPConnection(amqpConnection);
+ }
+
+ if (isSender) {
+ server.start();
+ Assert.assertEquals(1, server.getBrokerConnections().size());
+ } else {
+ server2.start();
+ Assert.assertEquals(1, server2.getBrokerConnections().size());
+ }
+ Wait.assertTrue(() -> AssertionLoggerHandler.findText("AMQ111002"));
+ server.getBrokerConnections().forEach((t) -> Wait.assertTrue(() ->
((AMQPBrokerConnection) t).isConnecting()));
+
+ if (isSender) {
+ server2.start();
+ } else {
+ server.start();
+ }
+
+ server.getBrokerConnections().forEach((t) -> Wait.assertFalse(() ->
((AMQPBrokerConnection) t).isConnecting()));
+
+ createAddressAndQueues(server);
+ createAddressAndQueues(server2);
+
+ Wait.assertTrue(() -> server.locateQueue(getQueueName()) != null);
+ Wait.assertTrue(() -> server2.locateQueue(getQueueName()) != null);
+
+ Thread.sleep(1000);
+
+ ActiveMQServer serverReceivingConnections = isSender ? server2 :
server;
+ Wait.assertEquals(1,
serverReceivingConnections.getRemotingService()::getConnectionCount);
+
serverReceivingConnections.getRemotingService().getConnections().forEach((t) ->
{
+ try {
+ ActiveMQProtonRemotingConnection connection =
(ActiveMQProtonRemotingConnection) t;
+ ConnectionImpl protonConnection = (ConnectionImpl)
connection.getAmqpConnection().getHandler().getConnection();
+ Wait.waitFor(() -> protonConnection.linkHead(of(ACTIVE),
of(ACTIVE)) != null);
+ connection.getAmqpConnection().runNow(() -> {
+ Link theLink = protonConnection.linkHead(of(ACTIVE),
of(ACTIVE));
+ theLink.close();
+ connection.flush();
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+
+ ConnectionFactory cf1 = CFUtil.createConnectionFactory("AMQP",
"tcp://localhost:" + AMQP_PORT);
+ ConnectionFactory cf2 = CFUtil.createConnectionFactory("AMQP",
"tcp://localhost:" + AMQP_PORT_2);
+
+ try (Connection connection = cf1.createConnection()) {
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer =
session.createProducer(session.createQueue(getQueueName()));
+ for (int i = 0; i < 10; i++) {
+ producer.send(session.createTextMessage("message " + i));
+ }
+ }
+
+ // messages should still flow after a disconnect on the link
+ // the server should reconnect as if it was a failure
+ try (Connection connection = cf2.createConnection()) {
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer =
session.createConsumer(session.createQueue(getQueueName()));
+ connection.start();
+ for (int i = 0; i < 10; i++) {
+ Assert.assertEquals("message " + i, ((TextMessage)
consumer.receive(5000)).getText());
+ }
+ }
+
+ } finally {
+ AssertionLoggerHandler.stopCapture();
+ }
+ }
+
+ @Test
+ public void testTimeoutOpenOnReceiver() throws Exception {
Review comment:
I'd suggest testTimeoutOnSenderOpen since its the broker sender handling
being tested.
I'd possibly also allow it to succeed on a retry to ensure it recovers.
Right now it looks like it would just repeatedly try and fail while the log
scrape and shutdown happens. The test could then verify there were 2
connections to the test server, and the first closes due to the error.
I'm glad to see use of a vertx-proton based test server though, makes for
better faster tests, I was going to suggest that yesterday when I saw the above
tests but didnt do it in the end.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 627139)
Time Spent: 27.5h (was: 27h 20m)
> Enhance AMQP Mirror support with dual mirror
> --------------------------------------------
>
> Key: ARTEMIS-3243
> URL: https://issues.apache.org/jira/browse/ARTEMIS-3243
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Affects Versions: 2.17.0
> Reporter: Clebert Suconic
> Assignee: Clebert Suconic
> Priority: Major
> Fix For: 2.18.0
>
> Time Spent: 27.5h
> Remaining Estimate: 0h
>
> at the current Mirror version, we can only mirror into a single direction.
> With this enhancement the two (or more brokers) would be connected to each
> other, each one having its own ID, and each one would send updates to the
> other broker.
> The outcome is that if you just transferred producers and consumers from one
> broker into the other, the fallback would be automatic and simple. No need to
> disable and enable mirror options.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)