You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by mc...@apache.org on 2021/03/16 20:47:44 UTC

[cassandra] branch trunk updated: Fix flaky ClientRequestSizeMetricsTest

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

mck 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 ecc7c2f  Fix flaky ClientRequestSizeMetricsTest
ecc7c2f is described below

commit ecc7c2fc393568076c30243b48a26045d61d03f3
Author: jacek-lewandowski <ja...@datastax.com>
AuthorDate: Tue Mar 16 10:33:39 2021 +0100

    Fix flaky ClientRequestSizeMetricsTest
    
     patch by Jacek Lewandowski; reviewed by Andres de la Peña, Benjamin Lerer, Jeremiah Jordan, Mick Semb Wever for CASSANDRA-16522
---
 test/unit/org/apache/cassandra/cql3/CQLTester.java | 14 ++++--
 .../metrics/ClientRequestSizeMetricsTest.java      | 50 +++++++++++++---------
 2 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index 14f7a41..2f88f7c 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -422,11 +422,16 @@ public abstract class CQLTester
         VirtualKeyspaceRegistry.instance.register(VirtualSchemaKeyspace.instance);
         StorageService.instance.initServer();
         SchemaLoader.startGossiper();
-        initializeNetwork(decorator);
+        initializeNetwork(decorator, null);
     }
 
     protected static void reinitializeNetwork()
     {
+        reinitializeNetwork(null);
+    }
+
+    protected static void reinitializeNetwork(Consumer<Cluster.Builder> clusterConfigurator)
+    {
         if (server != null && server.isRunning())
         {
             server.stop();
@@ -441,10 +446,10 @@ public abstract class CQLTester
         clusters.clear();
         sessions.clear();
 
-        initializeNetwork(server -> {});
+        initializeNetwork(server -> {}, clusterConfigurator);
     }
 
-    private static void initializeNetwork(Consumer<Server.Builder> decorator)
+    private static void initializeNetwork(Consumer<Server.Builder> decorator, Consumer<Cluster.Builder> clusterConfigurator)
     {
         Server.Builder serverBuilder = new Server.Builder().withHost(nativeAddr).withPort(nativePort);
         decorator.accept(serverBuilder);
@@ -470,6 +475,9 @@ public abstract class CQLTester
                                              .withPort(nativePort)
                                              .withSocketOptions(socketOptions);
 
+            if (clusterConfigurator != null)
+                clusterConfigurator.accept(builder);
+
             if (version.isBeta())
                 builder = builder.allowBetaProtocolVersion();
             else
diff --git a/test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java b/test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java
index be0138e..1f2f771 100644
--- a/test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java
+++ b/test/unit/org/apache/cassandra/metrics/ClientRequestSizeMetricsTest.java
@@ -29,7 +29,7 @@ import org.junit.runners.Parameterized;
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Histogram;
 import com.codahale.metrics.Snapshot;
-
+import com.datastax.driver.core.QueryOptions;
 import org.apache.cassandra.cql3.CQLTester;
 import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.EstimatedHistogramReservoirSnapshot;
 import org.apache.cassandra.metrics.DecayingEstimatedHistogramReservoir.Range;
@@ -52,7 +52,7 @@ public class ClientRequestSizeMetricsTest extends CQLTester
     public static Collection<Object[]> versions()
     {
         return ProtocolVersion.SUPPORTED.stream()
-                                        .map(v -> new Object[]{v})
+                                        .map(v -> new Object[]{ v })
                                         .collect(Collectors.toList());
     }
 
@@ -65,24 +65,34 @@ public class ClientRequestSizeMetricsTest extends CQLTester
     @Test
     public void testReadAndWriteMetricsAreRecordedDuringNativeRequests() throws Throwable
     {
-        // We want to ignore all the messages sent by the driver upon connection as well as
-        // the event sent upon schema updates
-        clearMetrics();
-
-        executeNet(version, "SELECT * from system.peers");
-
-        long requestLength = ClientMessageSizeMetrics.bytesReceived.getCount();
-        long responseLength = ClientMessageSizeMetrics.bytesSent.getCount();
-
-        assertThat(requestLength).isGreaterThan(0);
-        assertThat(responseLength).isGreaterThan(0);
-
-        checkMetrics(1, requestLength, responseLength);
-
-        // Let's fire the same request again and test that the changes are the same that previously
-        executeNet(version, "SELECT * from system.peers");
-
-        checkMetrics(2, requestLength, responseLength);
+        // It may happen that the schema refreshment is done in the middle of the test which can pollute the results
+        // We explicitly disable scheme fetching to avoid that effect
+        try
+        {
+            reinitializeNetwork(builder -> builder.withQueryOptions(new QueryOptions().setMetadataEnabled(false)));
+            // We want to ignore all the messages sent by the driver upon connection as well as
+            // the event sent upon schema updates
+            clearMetrics();
+
+            executeNet(version, "SELECT * from system.peers");
+
+            long requestLength = ClientMessageSizeMetrics.bytesReceived.getCount();
+            long responseLength = ClientMessageSizeMetrics.bytesSent.getCount();
+
+            assertThat(requestLength).isGreaterThan(0);
+            assertThat(responseLength).isGreaterThan(0);
+
+            checkMetrics(1, requestLength, responseLength);
+
+            // Let's fire the same request again and test that the changes are the same that previously
+            executeNet(version, "SELECT * from system.peers");
+
+            checkMetrics(2, requestLength, responseLength);
+        }
+        finally
+        {
+            reinitializeNetwork();
+        }
     }
 
     private void checkMetrics(int numberOfRequests, long requestLength, long responseLength)


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