Repository: cassandra-dtest
Updated Branches:
  refs/heads/master 7cc06a086 -> 01df7c498


Add test for digest requests with RandomPartitioner and tracing enabled

Patch by Sam Tunnicliffe; reviewed by Jason Brown and Philip Thompson
for CASSANDRA-13964


Project: http://git-wip-us.apache.org/repos/asf/cassandra-dtest/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra-dtest/commit/01df7c49
Tree: http://git-wip-us.apache.org/repos/asf/cassandra-dtest/tree/01df7c49
Diff: http://git-wip-us.apache.org/repos/asf/cassandra-dtest/diff/01df7c49

Branch: refs/heads/master
Commit: 01df7c49864ed5fa66db2181599a463a33b1f877
Parents: 7cc06a0
Author: Sam Tunnicliffe <s...@beobal.com>
Authored: Tue Oct 17 14:50:25 2017 +0100
Committer: Sam Tunnicliffe <s...@beobal.com>
Committed: Tue Nov 7 16:20:55 2017 +0000

----------------------------------------------------------------------
 cql_tracing_test.py | 39 +++++++++++++++++++++++++++++++++++++--
 tools/jmxutils.py   | 12 ++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra-dtest/blob/01df7c49/cql_tracing_test.py
----------------------------------------------------------------------
diff --git a/cql_tracing_test.py b/cql_tracing_test.py
index aaf55aa..549e4d0 100644
--- a/cql_tracing_test.py
+++ b/cql_tracing_test.py
@@ -3,6 +3,7 @@ from distutils.version import LooseVersion
 
 from dtest import Tester, debug, create_ks
 from tools.decorators import since
+from tools.jmxutils import make_mbean, JolokiaAgent, 
remove_perf_disable_shared_mem
 
 
 class TestCqlTracing(Tester):
@@ -15,16 +16,23 @@ class TestCqlTracing(Tester):
     #      instantiated when specified as a custom tracing implementation.
     """
 
-    def prepare(self, create_keyspace=True, nodes=3, rf=3, protocol_version=3, 
jvm_args=None, **kwargs):
+    def prepare(self, create_keyspace=True, nodes=3, rf=3, protocol_version=3, 
jvm_args=None, random_partitioner=False, **kwargs):
         if jvm_args is None:
             jvm_args = []
 
         jvm_args.append('-Dcassandra.wait_for_tracing_events_timeout_secs=15')
 
         cluster = self.cluster
-        cluster.populate(nodes).start(wait_for_binary_proto=True, 
jvm_args=jvm_args)
 
+        if random_partitioner:
+            
cluster.set_partitioner("org.apache.cassandra.dht.RandomPartitioner")
+        else:
+            
cluster.set_partitioner("org.apache.cassandra.dht.Murmur3Partitioner")
+
+        cluster.populate(nodes)
         node1 = cluster.nodelist()[0]
+        remove_perf_disable_shared_mem(node1)  # necessary for jmx
+        cluster.start(wait_for_binary_proto=True, jvm_args=jvm_args)
 
         session = self.patient_cql_connection(node1, 
protocol_version=protocol_version)
         if create_keyspace:
@@ -176,3 +184,30 @@ class TestCqlTracing(Tester):
         self.assertIn("Default constructor for Tracing class "
                       "'org.apache.cassandra.tracing.TracingImpl' is 
inaccessible.",
                       check_for_errs_in)
+
+    @since('3.0')
+    def test_tracing_does_not_interfere_with_digest_calculation(self):
+        """
+        Test that enabling tracing doesn't interfere with digest responses 
when using RandomPartitioner.
+        The use of a threadlocal MessageDigest for generating both 
DigestResponse messages and for
+        calculating tokens meant that the DigestResponse was always incorrect 
when both RP and tracing
+        were enabled, leading to unnecessary data reads.
+
+        @jira_ticket CASSANDRA-13964
+        """
+
+        session = self.prepare(random_partitioner=True)
+        self.trace(session)
+
+        node1 = self.cluster.nodelist()[0]
+
+        rr_count = make_mbean('metrics', type='ReadRepair', 
name='RepairedBlocking')
+        with JolokiaAgent(node1) as jmx:
+            # the MBean may not have been initialized, in which case Jolokia 
agent will return
+            # a HTTP 404 response. If we receive such, we know that no digest 
mismatch was reported
+            # If we are able to read the MBean attribute, assert that the 
count is 0
+            if jmx.has_mbean(rr_count):
+                # expect 0 digest mismatches
+                self.assertEqual(0, jmx.read_attribute(rr_count, 'Count'))
+            else:
+                pass

http://git-wip-us.apache.org/repos/asf/cassandra-dtest/blob/01df7c49/tools/jmxutils.py
----------------------------------------------------------------------
diff --git a/tools/jmxutils.py b/tools/jmxutils.py
index 8c20eb8..7468226 100644
--- a/tools/jmxutils.py
+++ b/tools/jmxutils.py
@@ -243,6 +243,18 @@ class JolokiaAgent(object):
             raise Exception("Jolokia agent returned non-200 status: %s" % 
(response,))
         return response
 
+    def has_mbean(self, mbean, verbose=True):
+        """
+        Check for the existence of an MBean
+
+        `mbean` should be the full name of an mbean.  See the mbean() utility
+        function for an easy way to create this.
+        """
+        body = {'type': 'search',
+                'mbean': mbean}
+        response = self._query(body, verbose=verbose)
+        return len(response['value']) > 0
+
     def read_attribute(self, mbean, attribute, path=None, verbose=True):
         """
         Reads a single JMX attribute.


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

Reply via email to