cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r915437 [2/2] - in /incubator/cassandra/branches/cassandra-0.5: ./ src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/dht/ src/java/org/apache/cassandra/io/ src/java/org/apache/cassandra/locator/ src/java/org/apache/cassandra/s...
Date Tue, 23 Feb 2010 17:05:47 GMT
Modified: incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeTest.java?rev=915437&r1=915436&r2=915437&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeTest.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeTest.java
Tue Feb 23 17:05:46 2010
@@ -18,11 +18,16 @@
 */
 package org.apache.cassandra.dht;
 
+import java.util.Arrays;
+import java.util.List;
+
 import org.junit.Test;
 
-public class RangeTest {
+public class RangeTest
+{
     @Test
-    public void testContains() {
+    public void testContains()
+    {
         Range left = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
         assert !left.contains(new BigIntegerToken("0"));
         assert left.contains(new BigIntegerToken("10"));
@@ -31,7 +36,8 @@
     }
 
     @Test
-    public void testContainsWrapping() {
+    public void testContainsWrapping()
+    {
         Range range = new Range(new BigIntegerToken("0"), new BigIntegerToken("0"));
         assert range.contains(new BigIntegerToken("0"));
         assert range.contains(new BigIntegerToken("10"));
@@ -46,7 +52,8 @@
     }
 
     @Test
-    public void testContainsRange() {
+    public void testContainsRange()
+    {
         Range one = new Range(new BigIntegerToken("2"), new BigIntegerToken("10"));
         Range two = new Range(new BigIntegerToken("2"), new BigIntegerToken("5"));
         Range thr = new Range(new BigIntegerToken("5"), new BigIntegerToken("10"));
@@ -70,11 +77,13 @@
     }
 
     @Test
-    public void testContainsRangeWrapping() {
+    public void testContainsRangeWrapping()
+    {
         Range one = new Range(new BigIntegerToken("10"), new BigIntegerToken("2"));
         Range two = new Range(new BigIntegerToken("5"), new BigIntegerToken("3"));
         Range thr = new Range(new BigIntegerToken("10"), new BigIntegerToken("12"));
         Range fou = new Range(new BigIntegerToken("2"), new BigIntegerToken("6"));
+        Range fiv = new Range(new BigIntegerToken("0"), new BigIntegerToken("0"));
 
         assert !one.contains(two);
         assert one.contains(thr);
@@ -91,14 +100,43 @@
         assert !fou.contains(one);
         assert !fou.contains(two);
         assert !fou.contains(thr);
+
+        assert fiv.contains(one);
+        assert fiv.contains(two);
+        assert fiv.contains(thr);
+        assert fiv.contains(fou);
+    }
+
+    @Test
+    public void testContainsRangeOneWrapping()
+    {
+        Range wrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("0"));
+        Range wrap2 = new Range(new BigIntegerToken("10"), new BigIntegerToken("2"));
+
+        Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("2"));
+        Range nowrap2 = new Range(new BigIntegerToken("2"), new BigIntegerToken("10"));
+        Range nowrap3 = new Range(new BigIntegerToken("10"), new BigIntegerToken("100"));
+
+        assert wrap1.contains(nowrap1);
+        assert wrap1.contains(nowrap2);
+        assert wrap1.contains(nowrap3);
+
+        assert wrap2.contains(nowrap1);
+        assert !wrap2.contains(nowrap2);
+        assert wrap2.contains(nowrap3);
     }
 
     @Test
-    public void testIntersects() {
+    public void testIntersects()
+    {
+        Range all = new Range(new BigIntegerToken("0"), new BigIntegerToken("0")); // technically,
this is a wrapping range
         Range one = new Range(new BigIntegerToken("2"), new BigIntegerToken("10"));
         Range two = new Range(new BigIntegerToken("0"), new BigIntegerToken("8"));
         Range not = new Range(new BigIntegerToken("10"), new BigIntegerToken("12"));
 
+        assert all.intersects(one);
+        assert all.intersects(two);
+
         assert one.intersects(two);
         assert two.intersects(one);
 
@@ -110,11 +148,19 @@
     }
 
     @Test
-    public void testIntersectsWrapping() {
+    public void testIntersectsWrapping()
+    {
         Range onewrap = new Range(new BigIntegerToken("10"), new BigIntegerToken("2"));
+        Range onecomplement = new Range(onewrap.right, onewrap.left);
+        Range onestartswith = new Range(onewrap.left, new BigIntegerToken("12"));
+        Range oneendswith = new Range(new BigIntegerToken("1"), onewrap.right);
         Range twowrap = new Range(new BigIntegerToken("5"), new BigIntegerToken("3"));
         Range not = new Range(new BigIntegerToken("2"), new BigIntegerToken("6"));
 
+        assert !onewrap.intersects(onecomplement);
+        assert onewrap.intersects(onestartswith);
+        assert onewrap.intersects(oneendswith);
+
         assert onewrap.intersects(twowrap);
         assert twowrap.intersects(onewrap);
 

Modified: incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java?rev=915437&r1=915436&r2=915437&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java
Tue Feb 23 17:05:46 2010
@@ -405,7 +405,7 @@
         // validate the tree
         TreeRangeIterator ranges = mt.invalids(new Range(tok(0), tok(0)));
         for (TreeRange range : ranges)
-            range.addHash(new RowHash(range.right(), new byte[0]));
+            range.addHash(new RowHash(range.right, new byte[0]));
 
         assert null != mt.hash(new Range(tok(0), tok(0))) :
             "Could not hash tree " + mt;
@@ -475,7 +475,7 @@
         mt.maxsize(256);
         mt.init();
         for (TreeRange range : mt.invalids(full))
-            range.addAll(new HIterator(range.right()));
+            range.addAll(new HIterator(range.right));
 
         byte[] initialhash = mt.hash(full);
         oout.writeObject(mt);
@@ -511,26 +511,26 @@
         rightmost = null;
         while (ranges.hasNext())
             rightmost = ranges.next();
-        mt.compact(leftmost.right());
-        leftmost = mt.get(leftmost.right()); // leftmost is now a larger range
-        mt.split(rightmost.right());
+        mt.compact(leftmost.right);
+        leftmost = mt.get(leftmost.right); // leftmost is now a larger range
+        mt.split(rightmost.right);
         
         // set the hash for the left neighbor of rightmost
-        middle = mt.get(rightmost.left());
+        middle = mt.get(rightmost.left);
         middle.hash("arbitrary!".getBytes());
         byte depth = middle.depth;
 
         // add dummy hashes to the rest of both trees
         for (TreeRange range : mt.invalids(full))
-            range.addAll(new HIterator(range.right()));
+            range.addAll(new HIterator(range.right));
         for (TreeRange range : mt2.invalids(full))
-            range.addAll(new HIterator(range.right()));
+            range.addAll(new HIterator(range.right));
         
         // trees should disagree for leftmost, (middle.left, rightmost.right]
         List<TreeRange> diffs = MerkleTree.difference(mt, mt2);
         assertEquals(diffs + " contains wrong number of differences:", 2, diffs.size());
         assertTrue(diffs.contains(leftmost));
-        assertTrue(diffs.contains(new Range(middle.left(), rightmost.right())));
+        assertTrue(diffs.contains(new Range(middle.left, rightmost.right)));
     }
 
     /**



Mime
View raw message