You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2022/07/22 14:24:55 UTC

[activemq-artemis] 01/03: ARTEMIS-3901 Fix artemis perf client --durable fails on exception

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 4737c5c88978899d304ef1029b5adeea8df372ae
Author: Å mucr Jan <ja...@aimtec.cz>
AuthorDate: Fri Jul 22 14:19:09 2022 +0200

    ARTEMIS-3901 Fix artemis perf client --durable fails on exception
---
 .../commands/messages/perf/PerfClientCommand.java  | 12 ++++
 .../activemq/cli/test/CliPerfClientTest.java       | 71 ++++++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/PerfClientCommand.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/PerfClientCommand.java
index 2e2985688d..e8e7159fd4 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/PerfClientCommand.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/perf/PerfClientCommand.java
@@ -18,6 +18,7 @@ package org.apache.activemq.artemis.cli.commands.messages.perf;
 
 import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
+import java.util.Collections;
 import java.util.Queue;
 import java.util.concurrent.Executor;
 import java.util.concurrent.LinkedTransferQueue;
@@ -30,6 +31,7 @@ import io.netty.channel.DefaultEventLoop;
 import io.netty.channel.DefaultEventLoopGroup;
 import io.netty.channel.EventLoop;
 import org.apache.activemq.artemis.cli.commands.ActionContext;
+import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
 
 @Command(name = "client", description = "It will produce and consume messages to a broker instance")
 public class PerfClientCommand extends PerfCommand {
@@ -199,4 +201,14 @@ public class PerfClientCommand extends PerfCommand {
          benchmark.close();
       }
    }
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      if (durableSubscription && (destinations == null || destinations.isEmpty())) {
+         // An empty destination list would create a single queue://TEST destination but durable subscriptions require
+         // topic destinations instead.
+         destinations = Collections.singletonList(ActiveMQDestination.TOPIC_QUALIFIED_PREFIX + "TEST");
+      }
+      return super.execute(context);
+   }
 }
diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/CliPerfClientTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/CliPerfClientTest.java
new file mode 100644
index 0000000000..aa487ec599
--- /dev/null
+++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/CliPerfClientTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.cli.test;
+
+import org.apache.activemq.artemis.cli.commands.ActionContext;
+import org.apache.activemq.artemis.cli.commands.messages.perf.PerfClientCommand;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.jms.Connection;
+
+public class CliPerfClientTest extends CliTestBase {
+   private Connection connection;
+   private ActiveMQConnectionFactory cf;
+
+   @Before
+   @Override
+   public void setup() throws Exception {
+      setupAuth();
+      super.setup();
+      startServer();
+      cf = getConnectionFactory(61616);
+      connection = cf.createConnection("admin", "admin");
+   }
+
+   @After
+   @Override
+   public void tearDown() throws Exception {
+      closeConnection(cf, connection);
+      super.tearDown();
+   }
+
+   private void start(boolean durable) throws Exception {
+      PerfClientCommand command = new PerfClientCommand() {
+         @Override
+         public Object execute(ActionContext context) throws Exception {
+            clientID = "perfClientTest";
+            durableSubscription = durable;
+            messageCount = 1;
+            return super.execute(context);
+         }
+      };
+      command.setUser("admin").setPassword("admin").execute(new TestActionContext());
+   }
+
+   @Test
+   public void testNonDurableStarts() throws Exception {
+      start(false);
+   }
+
+   @Test
+   public void testDurableStarts() throws Exception {
+      start(true);
+   }
+}
\ No newline at end of file