cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasobr...@apache.org
Subject [1/9] cassandra git commit: Remove timing window in test case
Date Tue, 29 Nov 2016 19:09:57 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.11 d5dbd0c75 -> c4cb915ea
  refs/heads/cassandra-3.X 40043021b -> 979f5f58e
  refs/heads/trunk 50b8be4e7 -> db0be3465


Remove timing window in test case

patch by Chris Lohfink; reviewed by Stefan Podkowinski for CASSANDRA-12875


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

Branch: refs/heads/cassandra-3.11
Commit: f87d074cd2eadd34cc496d6267a8039e8a54cbd4
Parents: d5dbd0c
Author: Chris Lohfink <Chris.Lohfink@datastax.com>
Authored: Wed Nov 9 08:41:41 2016 -0600
Committer: Jason Brown <jasedbrown@gmail.com>
Committed: Tue Nov 29 11:05:25 2016 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../cassandra/net/IncomingTcpConnection.java    |  5 +++--
 .../org/apache/cassandra/net/MessageIn.java     |  4 +---
 .../cassandra/net/MessagingServiceTest.java     | 20 ++++++++------------
 4 files changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f87d074c/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 2cd0eb0..9579781 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 3.10
+ * Remove timing window in test case (CASSANDRA-12875)
+ * Resolve unit testing without JCE security libraries installed (CASSANDRA-12945)
  * Fix inconsistencies in cassandra-stress load balancing policy (CASSANDRA-12919)
  * Fix validation of non-frozen UDT cells (CASSANDRA-12916)
  * Don't shut down socket input/output on StreamSession (CASSANDRA-12903)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f87d074c/src/java/org/apache/cassandra/net/IncomingTcpConnection.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/net/IncomingTcpConnection.java b/src/java/org/apache/cassandra/net/IncomingTcpConnection.java
index 7d3c607..9878590 100644
--- a/src/java/org/apache/cassandra/net/IncomingTcpConnection.java
+++ b/src/java/org/apache/cassandra/net/IncomingTcpConnection.java
@@ -39,6 +39,7 @@ import org.apache.cassandra.config.Config;
 import org.xerial.snappy.SnappyInputStream;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.UnknownColumnFamilyException;
+import org.apache.cassandra.db.monitoring.ApproximateTime;
 import org.apache.cassandra.io.util.DataInputPlus;
 import org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus;
 import org.apache.cassandra.io.util.NIODataInputStream;
@@ -187,8 +188,8 @@ public class IncomingTcpConnection extends FastThreadLocalThread implements
Clos
             id = Integer.parseInt(input.readUTF());
         else
             id = input.readInt();
-
-        MessageIn message = MessageIn.read(input, version, id, MessageIn.readConstructionTime(from,
input));
+        long currentTime = ApproximateTime.currentTimeMillis();
+        MessageIn message = MessageIn.read(input, version, id, MessageIn.readConstructionTime(from,
input, currentTime));
         if (message == null)
         {
             // callback expired; nothing to do

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f87d074c/src/java/org/apache/cassandra/net/MessageIn.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/net/MessageIn.java b/src/java/org/apache/cassandra/net/MessageIn.java
index a254741..0de9520 100644
--- a/src/java/org/apache/cassandra/net/MessageIn.java
+++ b/src/java/org/apache/cassandra/net/MessageIn.java
@@ -124,10 +124,8 @@ public class MessageIn<T>
         return MessageIn.create(from, payload, parameters, verb, version, constructionTime);
     }
 
-    public static long readConstructionTime(InetAddress from, DataInputPlus input) throws
IOException
+    public static long readConstructionTime(InetAddress from, DataInputPlus input, long currentTime)
throws IOException
     {
-        long currentTime = ApproximateTime.currentTimeMillis();
-
         // Reconstruct the message construction time sent by the remote host (we sent only
the lower 4 bytes, assuming the
         // higher 4 bytes wouldn't change between the sender and receiver)
         int partial = input.readInt(); // make sure to readInt, even if cross_node_to is
not enabled

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f87d074c/test/unit/org/apache/cassandra/net/MessagingServiceTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/net/MessagingServiceTest.java b/test/unit/org/apache/cassandra/net/MessagingServiceTest.java
index ec27b7e..11d17b8 100644
--- a/test/unit/org/apache/cassandra/net/MessagingServiceTest.java
+++ b/test/unit/org/apache/cassandra/net/MessagingServiceTest.java
@@ -34,20 +34,18 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 
 import com.google.common.collect.Iterables;
-
 import com.codahale.metrics.Timer;
 
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.monitoring.ApproximateTime;
 import org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus;
 import org.apache.cassandra.io.util.DataOutputStreamPlus;
 import org.apache.cassandra.io.util.WrappedDataOutputStreamPlus;
 import org.caffinitas.ohc.histo.EstimatedHistogram;
-
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import org.apache.cassandra.config.DatabaseDescriptor;
-
 import static org.junit.Assert.*;
 
 public class MessagingServiceTest
@@ -100,15 +98,13 @@ public class MessagingServiceTest
     public void testDCLatency() throws Exception
     {
         int latency = 100;
-
         ConcurrentHashMap<String, Timer> dcLatency = MessagingService.instance().metrics.dcLatency;
         dcLatency.clear();
 
-        long now = System.currentTimeMillis();
+        long now = ApproximateTime.currentTimeMillis();
         long sentAt = now - latency;
-
         assertNull(dcLatency.get("datacenter1"));
-        addDCLatency(sentAt);
+        addDCLatency(sentAt, now);
         assertNotNull(dcLatency.get("datacenter1"));
         assertEquals(1, dcLatency.get("datacenter1").getCount());
         long expectedBucket = bucketOffsets[Math.abs(Arrays.binarySearch(bucketOffsets, TimeUnit.MILLISECONDS.toNanos(latency)))
- 1];
@@ -124,11 +120,11 @@ public class MessagingServiceTest
         ConcurrentHashMap<String, Timer> dcLatency = MessagingService.instance().metrics.dcLatency;
         dcLatency.clear();
 
-        long now = System.currentTimeMillis();
+        long now = ApproximateTime.currentTimeMillis();
         long sentAt = now - latency;
 
         assertNull(dcLatency.get("datacenter1"));
-        addDCLatency(sentAt);
+        addDCLatency(sentAt, now);
         assertNull(dcLatency.get("datacenter1"));
     }
 
@@ -221,7 +217,7 @@ public class MessagingServiceTest
         assertFalse(MockBackPressureStrategy.applied);
     }
 
-    private static void addDCLatency(long sentAt) throws IOException
+    private static void addDCLatency(long sentAt, long nowTime) throws IOException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try (DataOutputStreamPlus out = new WrappedDataOutputStreamPlus(baos))
@@ -229,7 +225,7 @@ public class MessagingServiceTest
             out.writeInt((int) sentAt);
         }
         DataInputStreamPlus in = new DataInputStreamPlus(new ByteArrayInputStream(baos.toByteArray()));
-        MessageIn.readConstructionTime(InetAddress.getLocalHost(), in);
+        MessageIn.readConstructionTime(InetAddress.getLocalHost(), in, nowTime);
     }
 
     public static class MockBackPressureStrategy implements BackPressureStrategy<MockBackPressureStrategy.MockBackPressureState>


Mime
View raw message