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

brandonwilliams pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 932b0a4  make cassandra-stress -node work with host:port
932b0a4 is described below

commit 932b0a483eb9f7cfd23b29cb90b328e1825a02bc
Author: Adam Holmberg <adam.holmb...@datastax.com>
AuthorDate: Fri Mar 19 12:16:04 2021 -0500

    make cassandra-stress -node work with host:port
    
    Patch by Adam Holmberg; reviewed by brandonwilliams for CASSANDRA-16529
---
 CHANGES.txt                                        |  1 +
 .../tools/cassandrastress/CassandrastressTest.java | 37 ++++++++++++++++++++--
 .../cassandra/stress/util/JavaDriverClient.java    |  8 +++--
 3 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 5cc6693..4091004 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0-beta5
+ * Make cassandra-stress -node support host:port notation (CASSANDRA-16529)
  * Better handle legacy gossip application states during (and after) upgrades 
(CASSANDRA-16525)
  * Mark StreamingMetrics.ActiveOutboundStreams as deprecated (CASSANDRA-11174)
  * Increase the cqlsh version number (CASSANDRA-16509)
diff --git 
a/test/unit/org/apache/cassandra/tools/cassandrastress/CassandrastressTest.java 
b/test/unit/org/apache/cassandra/tools/cassandrastress/CassandrastressTest.java
index 8ba091a..aa64dac 100644
--- 
a/test/unit/org/apache/cassandra/tools/cassandrastress/CassandrastressTest.java
+++ 
b/test/unit/org/apache/cassandra/tools/cassandrastress/CassandrastressTest.java
@@ -18,10 +18,14 @@
 
 package org.apache.cassandra.tools.cassandrastress;
 
+import java.util.Arrays;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.service.GCInspector;
 import org.apache.cassandra.tools.ToolRunner;
 import org.apache.cassandra.tools.ToolRunner.ToolResult;
 import org.hamcrest.CoreMatchers;
@@ -33,9 +37,11 @@ import static org.junit.Assert.assertTrue;
 public class CassandrastressTest extends CQLTester
 {
     @BeforeClass
-    public static void setUp()
+    public static void setUp() throws Exception
     {
         requireNetwork();
+        startJMXServer();
+        GCInspector.register();// required by stress tool metrics
     }
 
     @Test
@@ -46,5 +52,32 @@ public class CassandrastressTest extends CQLTester
         assertTrue("Tool stderr: " +  tool.getCleanedStderr(), 
tool.getCleanedStderr().isEmpty());
         assertEquals(1, tool.getExitCode());
     }
-    
+
+    @Test
+    public void testNodesArg()
+    {
+        String[] baseArgs = new String[] { "write", "n=10", "no-warmup", 
"-rate", "threads=1", "-port",
+                                           String.format("jmx=%d", jmxPort), 
String.format("native=%d", nativePort)};
+        invokeAndAssertCleanExit(baseArgs);
+
+        String ip = "127.0.0.1";
+        invokeAndAssertCleanExit(baseArgs, "-node", ip);
+
+        String ipAndPort = String.format("%s:%d", ip, nativePort);
+        invokeAndAssertCleanExit(baseArgs, "-node", ipAndPort);
+
+        String ipsAndPort = String.format("%s,%s", ipAndPort, ipAndPort);
+        invokeAndAssertCleanExit(baseArgs, "-node", ipsAndPort);
+
+        String hostNameAndPort = String.format("localhost:%s", nativePort);
+        invokeAndAssertCleanExit(baseArgs, "-node", hostNameAndPort);
+    }
+
+    void invokeAndAssertCleanExit(String[] baseArgs, String ... extraArgs)
+    {
+        String[] args = Arrays.copyOf(baseArgs, baseArgs.length + 
extraArgs.length);
+        System.arraycopy(extraArgs, 0, args, baseArgs.length, 
extraArgs.length);
+        ToolResult tool = ToolRunner.invokeCassandraStress(args);
+        tool.assertOnCleanExit();
+    }
 }
diff --git 
a/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java 
b/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java
index 49cb0a8..e0b734e 100644
--- a/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java
+++ b/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java
@@ -17,6 +17,7 @@
  */
 package org.apache.cassandra.stress.util;
 
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
@@ -24,6 +25,8 @@ import java.util.concurrent.ConcurrentMap;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
 
+import com.google.common.net.HostAndPort;
+
 import com.datastax.driver.core.*;
 import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
 import com.datastax.driver.core.policies.LoadBalancingPolicy;
@@ -130,9 +133,10 @@ public class JavaDriverClient
                                      
.setMaxRequestsPerConnection(HostDistance.LOCAL, maxPendingPerConnection)
                                      
.setNewConnectionThreshold(HostDistance.LOCAL, 100);
 
+        HostAndPort hap = HostAndPort.fromString(host).withDefaultPort(port);
+        InetSocketAddress contact = new 
InetSocketAddress(InetAddress.getByName(hap.getHost()), hap.getPort());
         Cluster.Builder clusterBuilder = Cluster.builder()
-                                                .addContactPoint(host)
-                                                .withPort(port)
+                                                
.addContactPointsWithPorts(contact)
                                                 
.withPoolingOptions(poolingOpts)
                                                 .withoutJMXReporting()
                                                 
.withProtocolVersion(protocolVersion)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to