cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [1/3] git commit: Fix CellName comparison bugs
Date Wed, 14 May 2014 13:07:23 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 3cb736101 -> 4b8f667d0


Fix CellName comparison bugs

Patch by tjake; reviewed by bes for CASSANDRA-7227


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

Branch: refs/heads/trunk
Commit: 0f977c597a6b70984de96bcc49474acdb12ad2ea
Parents: 50c18fd
Author: Jake Luciani <jake@apache.org>
Authored: Wed May 14 08:37:34 2014 -0400
Committer: Jake Luciani <jake@apache.org>
Committed: Wed May 14 08:37:34 2014 -0400

----------------------------------------------------------------------
 .../composites/AbstractSimpleCellNameType.java  |   2 +-
 .../cassandra/db/composites/SimpleCType.java    |   4 +-
 .../cassandra/db/composites/CTypeTest.java      | 123 +++++++++++++++++++
 3 files changed, 126 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/0f977c59/src/java/org/apache/cassandra/db/composites/AbstractSimpleCellNameType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/composites/AbstractSimpleCellNameType.java b/src/java/org/apache/cassandra/db/composites/AbstractSimpleCellNameType.java
index 6500069..95386fd 100644
--- a/src/java/org/apache/cassandra/db/composites/AbstractSimpleCellNameType.java
+++ b/src/java/org/apache/cassandra/db/composites/AbstractSimpleCellNameType.java
@@ -64,7 +64,7 @@ public abstract class AbstractSimpleCellNameType extends AbstractCellNameType
         boolean c1isEmpty = c1.isEmpty();
         boolean c2isEmpty = c2.isEmpty();
         if (c1isEmpty || c2isEmpty)
-            return c1isEmpty ? 1 : (c2isEmpty ? -1 : 0);
+            return !c1isEmpty ? 1 : (!c2isEmpty ? -1 : 0);
 
         return type.compare(c1.get(0), c2.get(0));
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0f977c59/src/java/org/apache/cassandra/db/composites/SimpleCType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/composites/SimpleCType.java b/src/java/org/apache/cassandra/db/composites/SimpleCType.java
index fe86655..35e14f9 100644
--- a/src/java/org/apache/cassandra/db/composites/SimpleCType.java
+++ b/src/java/org/apache/cassandra/db/composites/SimpleCType.java
@@ -58,14 +58,14 @@ public class SimpleCType extends AbstractCType
             ByteBuffer b1 = c1.toByteBuffer();
             ByteBuffer b2 = c2.toByteBuffer();
             if (!b1.hasRemaining() || !b2.hasRemaining())
-
+                return b1.hasRemaining() ? 1 : (b2.hasRemaining() ? -1 : 0);
             return ByteBufferUtil.compareUnsigned(b1, b2);
         }
 
         boolean c1isEmpty = c1.isEmpty();
         boolean c2isEmpty = c2.isEmpty();
         if (c1isEmpty || c2isEmpty)
-            return c1isEmpty ? 1 : (c2isEmpty ? -1 : 0);
+            return !c1isEmpty ? 1 : (!c2isEmpty ? -1 : 0);
 
         return type.compare(c1.get(0), c2.get(0));
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0f977c59/test/unit/org/apache/cassandra/db/composites/CTypeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/composites/CTypeTest.java b/test/unit/org/apache/cassandra/db/composites/CTypeTest.java
new file mode 100644
index 0000000..4bd755b
--- /dev/null
+++ b/test/unit/org/apache/cassandra/db/composites/CTypeTest.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.db.composites;
+
+import com.google.common.collect.Lists;
+import org.apache.cassandra.db.marshal.*;
+import org.apache.cassandra.utils.ByteBufferUtil;
+import org.junit.Test;
+
+import java.util.List;
+
+public class CTypeTest
+{
+    static final List<AbstractType<?>> types = Lists.newArrayList();
+    static
+    {
+        types.add(UTF8Type.instance);
+        types.add(UUIDType.instance);
+        types.add(Int32Type.instance);
+    }
+
+    static final CellNameType cdtype = new CompoundDenseCellNameType(types);
+    static final CellNameType stype1 = new SimpleDenseCellNameType(BytesType.instance);
+    static final CellNameType stype2 = new SimpleDenseCellNameType(UUIDType.instance);
+
+    @Test
+    public void testCompoundType()
+    {
+        Composite a1 = cdtype.makeCellName("a",UUIDType.instance.fromString("00000000-0000-0000-0000-000000000000"),
1);
+        Composite a2 = cdtype.makeCellName("a",UUIDType.instance.fromString("00000000-0000-0000-0000-000000000000"),
100);
+        Composite b1 = cdtype.makeCellName("a",UUIDType.instance.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"),
1);
+        Composite b2 = cdtype.makeCellName("a",UUIDType.instance.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"),
100);
+        Composite c1 = cdtype.makeCellName("z",UUIDType.instance.fromString("00000000-0000-0000-0000-000000000000"),
1);
+        Composite c2 = cdtype.makeCellName("z",UUIDType.instance.fromString("00000000-0000-0000-0000-000000000000"),
100);
+        Composite d1 = cdtype.makeCellName("z",UUIDType.instance.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"),
1);
+        Composite d2 = cdtype.makeCellName("z",UUIDType.instance.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"),
100);
+
+        Composite z1 = cdtype.makeCellName(ByteBufferUtil.EMPTY_BYTE_BUFFER,UUIDType.instance.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"),
100);
+
+        assert cdtype.compare(a1,a2) < 0;
+        assert cdtype.compare(a2,b1) < 0;
+        assert cdtype.compare(b1,b2) < 0;
+        assert cdtype.compare(b2,c1) < 0;
+        assert cdtype.compare(c1,c2) < 0;
+        assert cdtype.compare(c2,d1) < 0;
+        assert cdtype.compare(d1,d2) < 0;
+
+        assert cdtype.compare(a2,a1) > 0;
+        assert cdtype.compare(b1,a2) > 0;
+        assert cdtype.compare(b2,b1) > 0;
+        assert cdtype.compare(c1,b2) > 0;
+        assert cdtype.compare(c2,c1) > 0;
+        assert cdtype.compare(d1,c2) > 0;
+        assert cdtype.compare(d2,d1) > 0;
+
+        assert cdtype.compare(z1,a1) < 0;
+        assert cdtype.compare(z1,a2) < 0;
+        assert cdtype.compare(z1,b1) < 0;
+        assert cdtype.compare(z1,b2) < 0;
+        assert cdtype.compare(z1,c1) < 0;
+        assert cdtype.compare(z1,c2) < 0;
+        assert cdtype.compare(z1,d1) < 0;
+        assert cdtype.compare(z1,d2) < 0;
+
+        assert cdtype.compare(a1,a1) == 0;
+        assert cdtype.compare(a2,a2) == 0;
+        assert cdtype.compare(b1,b1) == 0;
+        assert cdtype.compare(b2,b2) == 0;
+        assert cdtype.compare(c1,c1) == 0;
+        assert cdtype.compare(c2,c2) == 0;
+        assert cdtype.compare(z1,z1) == 0;
+    }
+
+    @Test
+    public void testSimpleType2()
+    {
+        CellName a = stype2.makeCellName(UUIDType.instance.fromString("00000000-0000-0000-0000-000000000000"));
+        CellName z = stype2.makeCellName(UUIDType.instance.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"));
+        Composite empty = Composites.EMPTY;
+
+        assert stype2.compare(a,z) < 0;
+        assert stype2.compare(z,a) > 0;
+        assert stype2.compare(a,a) == 0;
+        assert stype2.compare(z,z) == 0;
+        assert stype2.compare(empty, a) < 0;
+        assert stype2.compare(a,empty) > 0;
+        assert stype2.compare(empty, empty) == 0;
+    }
+
+
+    @Test
+    public void testSimpleType1()
+    {
+        CellName a = stype1.makeCellName(ByteBufferUtil.bytes("a"));
+        CellName z = stype1.makeCellName(ByteBufferUtil.bytes("z"));
+        Composite empty = Composites.EMPTY;
+
+        assert stype1.compare(a,z) < 0;
+        assert stype1.compare(z,a) > 0;
+        assert stype1.compare(a,a) == 0;
+        assert stype1.compare(z,z) == 0;
+        assert stype1.compare(empty, a) < 0;
+        assert stype1.compare(a,empty) > 0;
+        assert stype1.compare(empty, empty) == 0;
+
+    }
+
+}


Mime
View raw message