cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r785697 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/dht/Range.java test/unit/org/apache/cassandra/dht/RangeTest.java
Date Wed, 17 Jun 2009 16:08:39 GMT
Author: jbellis
Date: Wed Jun 17 16:08:39 2009
New Revision: 785697

URL: http://svn.apache.org/viewvc?rev=785697&view=rev
Log:
fix off-by-one error in Range.contains(Token): the endpoint (right) of the range is always
supposed to be exclusive, but it was inclusive in the non-wrapping case.  patch by Stu Hood;
reviewed by jbellis for CASSANDRA-236

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java?rev=785697&r1=785696&r2=785697&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java Wed Jun 17 16:08:39
2009
@@ -31,6 +31,9 @@
 
 /**
  * A representation of the range that a node is responsible for on the DHT ring.
+ *
+ * A Range is responsible for the tokens between [left, right).
+ * 
  * Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com
)
  */
 
@@ -46,7 +49,7 @@
     {
         return serializer_;
     }
-    
+
     private final Token left_;
     private final Token right_;
 
@@ -101,7 +104,7 @@
             /*
              * This is the range [a, b) where a < b. 
             */
-            return ( bi.compareTo(left_) >= 0 && right_.compareTo(bi) >=0 );
+            return ( bi.compareTo(left_) >= 0 && right_.compareTo(bi) > 0 );
         }        
         else
     	{

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java?rev=785697&r1=785696&r2=785697&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java Wed Jun 17
16:08:39 2009
@@ -24,13 +24,17 @@
     @Test
     public void testRange() {
         Range left = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
+		assert left.contains(new BigIntegerToken("0"));
         assert left.contains(new BigIntegerToken("10"));
         assert !left.contains(new BigIntegerToken("-1"));
+        assert !left.contains(new BigIntegerToken("100"));
         assert !left.contains(new BigIntegerToken("101"));
 
         Range right = new Range(new BigIntegerToken("100"), new BigIntegerToken("0"));
+        assert right.contains(new BigIntegerToken("100"));
         assert right.contains(new BigIntegerToken("200"));
         assert right.contains(new BigIntegerToken("-10"));
+        assert !right.contains(new BigIntegerToken("0"));
         assert !right.contains(new BigIntegerToken("1"));
     }
 }



Mime
View raw message