cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject git commit: Fix CollectionTypeTest
Date Thu, 08 May 2014 15:59:59 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 7da562053 -> 3b299c4ca


Fix CollectionTypeTest


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

Branch: refs/heads/cassandra-2.1
Commit: 3b299c4ca123e66172163bacc05e7ce8e096164c
Parents: 7da5620
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Thu May 8 17:59:52 2014 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Thu May 8 17:59:52 2014 +0200

----------------------------------------------------------------------
 src/java/org/apache/cassandra/db/marshal/ListType.java |  9 +++++----
 src/java/org/apache/cassandra/db/marshal/MapType.java  | 13 +++++++------
 .../cassandra/serializers/CollectionSerializer.java    |  4 ++--
 .../cassandra/db/marshal/CollectionTypeTest.java       | 12 ++++++------
 4 files changed, 20 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3b299c4c/src/java/org/apache/cassandra/db/marshal/ListType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/ListType.java b/src/java/org/apache/cassandra/db/marshal/ListType.java
index 6e6821b..171e179 100644
--- a/src/java/org/apache/cassandra/db/marshal/ListType.java
+++ b/src/java/org/apache/cassandra/db/marshal/ListType.java
@@ -23,6 +23,7 @@ import java.util.*;
 import org.apache.cassandra.db.Cell;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.serializers.CollectionSerializer;
 import org.apache.cassandra.serializers.TypeSerializer;
 import org.apache.cassandra.serializers.ListSerializer;
 import org.apache.cassandra.utils.ByteBufferUtil;
@@ -92,13 +93,13 @@ public class ListType<T> extends CollectionType<List<T>>
         ByteBuffer bb1 = o1.duplicate();
         ByteBuffer bb2 = o2.duplicate();
 
-        int size1 = ByteBufferUtil.readShortLength(bb1);
-        int size2 = ByteBufferUtil.readShortLength(bb2);
+        int size1 = CollectionSerializer.readCollectionSize(bb1, 3);
+        int size2 = CollectionSerializer.readCollectionSize(bb2, 3);
 
         for (int i = 0; i < Math.min(size1, size2); i++)
         {
-            ByteBuffer v1 = ByteBufferUtil.readBytesWithShortLength(bb1);
-            ByteBuffer v2 = ByteBufferUtil.readBytesWithShortLength(bb2);
+            ByteBuffer v1 = CollectionSerializer.readValue(bb1, 3);
+            ByteBuffer v2 = CollectionSerializer.readValue(bb2, 3);
             int cmp = elementsComparator.compare(v1, v2);
             if (cmp != 0)
                 return cmp;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3b299c4c/src/java/org/apache/cassandra/db/marshal/MapType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/MapType.java b/src/java/org/apache/cassandra/db/marshal/MapType.java
index 71023a7..dbf6721 100644
--- a/src/java/org/apache/cassandra/db/marshal/MapType.java
+++ b/src/java/org/apache/cassandra/db/marshal/MapType.java
@@ -23,6 +23,7 @@ import java.util.*;
 import org.apache.cassandra.db.Cell;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
+import org.apache.cassandra.serializers.CollectionSerializer;
 import org.apache.cassandra.serializers.TypeSerializer;
 import org.apache.cassandra.serializers.MapSerializer;
 import org.apache.cassandra.utils.Pair;
@@ -86,19 +87,19 @@ public class MapType<K, V> extends CollectionType<Map<K, V>>
         ByteBuffer bb1 = o1.duplicate();
         ByteBuffer bb2 = o2.duplicate();
 
-        int size1 = ByteBufferUtil.readShortLength(bb1);
-        int size2 = ByteBufferUtil.readShortLength(bb2);
+        int size1 = CollectionSerializer.readCollectionSize(bb1, 3);
+        int size2 = CollectionSerializer.readCollectionSize(bb2, 3);
 
         for (int i = 0; i < Math.min(size1, size2); i++)
         {
-            ByteBuffer k1 = ByteBufferUtil.readBytesWithShortLength(bb1);
-            ByteBuffer k2 = ByteBufferUtil.readBytesWithShortLength(bb2);
+            ByteBuffer k1 = CollectionSerializer.readValue(bb1, 3);
+            ByteBuffer k2 = CollectionSerializer.readValue(bb2, 3);
             int cmp = keys.compare(k1, k2);
             if (cmp != 0)
                 return cmp;
 
-            ByteBuffer v1 = ByteBufferUtil.readBytesWithShortLength(bb1);
-            ByteBuffer v2 = ByteBufferUtil.readBytesWithShortLength(bb2);
+            ByteBuffer v1 = CollectionSerializer.readValue(bb1, 3);
+            ByteBuffer v2 = CollectionSerializer.readValue(bb2, 3);
             cmp = values.compare(v1, v2);
             if (cmp != 0)
                 return cmp;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3b299c4c/src/java/org/apache/cassandra/serializers/CollectionSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/CollectionSerializer.java b/src/java/org/apache/cassandra/serializers/CollectionSerializer.java
index 43b04f3..5452a96 100644
--- a/src/java/org/apache/cassandra/serializers/CollectionSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/CollectionSerializer.java
@@ -73,7 +73,7 @@ public abstract class CollectionSerializer<T> implements TypeSerializer<T>
             output.putShort((short)elements);
     }
 
-    protected static int readCollectionSize(ByteBuffer input, int version)
+    public static int readCollectionSize(ByteBuffer input, int version)
     {
         return version >= 3 ? input.getInt() : ByteBufferUtil.readShortLength(input);
     }
@@ -104,7 +104,7 @@ public abstract class CollectionSerializer<T> implements TypeSerializer<T>
         }
     }
 
-    protected static ByteBuffer readValue(ByteBuffer input, int version)
+    public static ByteBuffer readValue(ByteBuffer input, int version)
     {
         if (version >= 3)
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3b299c4c/test/unit/org/apache/cassandra/db/marshal/CollectionTypeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/marshal/CollectionTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/CollectionTypeTest.java
index 2878820..c51d304 100644
--- a/test/unit/org/apache/cassandra/db/marshal/CollectionTypeTest.java
+++ b/test/unit/org/apache/cassandra/db/marshal/CollectionTypeTest.java
@@ -51,8 +51,8 @@ public class CollectionTypeTest
         {
             for (int j = i+1; j < lists.length; j++)
             {
-                assertEquals(lt.compare(lists[i], lists[j]), -1);
-                assertEquals(lt.compare(lists[j], lists[i]), 1);
+                assertEquals(String.format("compare(lists[%d], lists[%d])", i, j), -1, lt.compare(lists[i],
lists[j]));
+                assertEquals(String.format("compare(lists[%d], lists[%d])", j, i),  1, lt.compare(lists[j],
lists[i]));
             }
         }
     }
@@ -78,8 +78,8 @@ public class CollectionTypeTest
         {
             for (int j = i+1; j < sets.length; j++)
             {
-                assertEquals(st.compare(sets[i], sets[j]), -1);
-                assertEquals(st.compare(sets[j], sets[i]), 1);
+                assertEquals(String.format("compare(sets[%d], sets[%d])", i, j), -1, st.compare(sets[i],
sets[j]));
+                assertEquals(String.format("compare(sets[%d], sets[%d])", j, i),  1, st.compare(sets[j],
sets[i]));
             }
         }
     }
@@ -107,8 +107,8 @@ public class CollectionTypeTest
         {
             for (int j = i+1; j < maps.length; j++)
             {
-                assertEquals(mt.compare(maps[i], maps[j]), -1);
-                assertEquals(mt.compare(maps[j], maps[i]), 1);
+                assertEquals(String.format("compare(maps[%d], maps[%d])", i, j), mt.compare(maps[i],
maps[j]), -1);
+                assertEquals(String.format("compare(maps[%d], maps[%d])", j, i), mt.compare(maps[j],
maps[i]), 1);
             }
         }
     }


Mime
View raw message