Updated Branches:
  refs/heads/trunk 1218bcacb -> 714c42336

http://git-wip-us.apache.org/repos/asf/cassandra/blob/714c4233/test/unit/org/apache/cassandra/db/context/CounterContextTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/context/CounterContextTest.java 
b/test/unit/org/apache/cassandra/db/context/CounterContextTest.java
index 5c88fd6..ea5dd3e 100644
--- a/test/unit/org/apache/cassandra/db/context/CounterContextTest.java
+++ b/test/unit/org/apache/cassandra/db/context/CounterContextTest.java
@@ -26,7 +26,8 @@ import java.nio.ByteBuffer;
 
 import org.junit.Test;
 
-import org.apache.cassandra.db.context.IContext.ContextRelationship;
+import org.apache.cassandra.db.ClockAndCount;
+import org.apache.cassandra.db.context.CounterContext.Relationship;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.utils.*;
 
@@ -92,7 +93,7 @@ public class CounterContextTest
         left.writeRemote(CounterId.fromInt(9), 1L, 0L);
         right = ContextState.wrap(ByteBufferUtil.clone(left.context));
 
-        assertEquals(ContextRelationship.EQUAL, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.EQUAL, cc.diff(left.context, right.context));
 
         // greater than: left has superset of nodes (counts equal)
         left = ContextState.allocate(0, 0, 4, allocator);
@@ -106,7 +107,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6), 2L, 0L);
         right.writeRemote(CounterId.fromInt(9), 1L, 0L);
 
-        assertEquals(ContextRelationship.GREATER_THAN, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.GREATER_THAN, cc.diff(left.context, 
right.context));
 
         // less than: left has subset of nodes (counts equal)
         left = ContextState.allocate(0, 0, 3, allocator);
@@ -120,7 +121,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(9),  1L, 0L);
         right.writeRemote(CounterId.fromInt(12), 0L, 0L);
 
-        assertEquals(ContextRelationship.LESS_THAN, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.LESS_THAN, cc.diff(left.context, 
right.context));
 
         // greater than: equal nodes, but left has higher counts
         left = ContextState.allocate(0, 0, 3, allocator);
@@ -133,7 +134,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6), 2L, 0L);
         right.writeRemote(CounterId.fromInt(9), 1L, 0L);
 
-        assertEquals(ContextRelationship.GREATER_THAN, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.GREATER_THAN, cc.diff(left.context, 
right.context));
 
         // less than: equal nodes, but right has higher counts
         left = ContextState.allocate(0, 0, 3, allocator);
@@ -146,7 +147,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6), 9L, 0L);
         right.writeRemote(CounterId.fromInt(9), 3L, 0L);
 
-        assertEquals(ContextRelationship.LESS_THAN, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.LESS_THAN, cc.diff(left.context, 
right.context));
 
         // disjoint: right and left have disjoint node sets
         left = ContextState.allocate(0, 0, 3, allocator);
@@ -159,7 +160,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6), 1L, 0L);
         right.writeRemote(CounterId.fromInt(9), 1L, 0L);
 
-        assertEquals(ContextRelationship.DISJOINT, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.DISJOINT, cc.diff(left.context, 
right.context));
 
         left = ContextState.allocate(0, 0, 3, allocator);
         left.writeRemote(CounterId.fromInt(3), 1L, 0L);
@@ -171,7 +172,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6),  1L, 0L);
         right.writeRemote(CounterId.fromInt(12), 1L, 0L);
 
-        assertEquals(ContextRelationship.DISJOINT, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.DISJOINT, cc.diff(left.context, 
right.context));
 
         // disjoint: equal nodes, but right and left have higher counts in 
differing nodes
         left = ContextState.allocate(0, 0, 3, allocator);
@@ -184,7 +185,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6), 1L, 0L);
         right.writeRemote(CounterId.fromInt(9), 5L, 0L);
 
-        assertEquals(ContextRelationship.DISJOINT, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.DISJOINT, cc.diff(left.context, 
right.context));
 
         left = ContextState.allocate(0, 0, 3, allocator);
         left.writeRemote(CounterId.fromInt(3), 2L, 0L);
@@ -196,7 +197,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6), 9L, 0L);
         right.writeRemote(CounterId.fromInt(9), 5L, 0L);
 
-        assertEquals(ContextRelationship.DISJOINT, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.DISJOINT, cc.diff(left.context, 
right.context));
 
         // disjoint: left has more nodes, but lower counts
         left = ContextState.allocate(0, 0, 4, allocator);
@@ -210,7 +211,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6), 9L, 0L);
         right.writeRemote(CounterId.fromInt(9), 5L, 0L);
 
-        assertEquals(ContextRelationship.DISJOINT, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.DISJOINT, cc.diff(left.context, 
right.context));
 
         // disjoint: left has less nodes, but higher counts
         left = ContextState.allocate(0, 0, 3, allocator);
@@ -224,7 +225,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(9),  2L, 0L);
         right.writeRemote(CounterId.fromInt(12), 1L, 0L);
 
-        assertEquals(ContextRelationship.DISJOINT, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.DISJOINT, cc.diff(left.context, 
right.context));
 
         // disjoint: mixed nodes and counts
         left = ContextState.allocate(0, 0, 3, allocator);
@@ -238,7 +239,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(9),  2L, 0L);
         right.writeRemote(CounterId.fromInt(12), 1L, 0L);
 
-        assertEquals(ContextRelationship.DISJOINT, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.DISJOINT, cc.diff(left.context, 
right.context));
 
         left = ContextState.allocate(0, 0, 4, allocator);
         left.writeRemote(CounterId.fromInt(3), 5L, 0L);
@@ -251,7 +252,7 @@ public class CounterContextTest
         right.writeRemote(CounterId.fromInt(6), 3L, 0L);
         right.writeRemote(CounterId.fromInt(9), 2L, 0L);
 
-        assertEquals(ContextRelationship.DISJOINT, cc.diff(left.context, 
right.context));
+        assertEquals(Relationship.DISJOINT, cc.diff(left.context, 
right.context));
     }
 
     @Test
@@ -499,4 +500,67 @@ public class CounterContextTest
         cleared = cc.clearAllLocal(marked);
         assertSame(cleared, marked);
     }
+
+    @Test
+    public void testFindPositionOf()
+    {
+        ContextState state = ContextState.allocate(3, 3, 3, 
HeapAllocator.instance);
+
+        state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
+        state.writeRemote(CounterId.fromInt(2), 2L, 2L);
+        state.writeLocal( CounterId.fromInt(3), 3L, 3L);
+        state.writeGlobal(CounterId.fromInt(4), 4L, 4L);
+        state.writeRemote(CounterId.fromInt(5), 5L, 5L);
+        state.writeLocal( CounterId.fromInt(6), 6L, 6L);
+        state.writeGlobal(CounterId.fromInt(7), 7L, 7L);
+        state.writeRemote(CounterId.fromInt(8), 8L, 8L);
+        state.writeLocal(CounterId.fromInt(9), 9L, 9L);
+
+        int headerLength = headerSizeLength + 6 * headerEltLength;
+        assertEquals(headerLength, cc.findPositionOf(state.context, 
CounterId.fromInt(1)));
+        assertEquals(headerLength + stepLength, 
cc.findPositionOf(state.context, CounterId.fromInt(2)));
+        assertEquals(headerLength + 2 * stepLength, 
cc.findPositionOf(state.context, CounterId.fromInt(3)));
+        assertEquals(headerLength + 3 * stepLength, 
cc.findPositionOf(state.context, CounterId.fromInt(4)));
+        assertEquals(headerLength + 4 * stepLength, 
cc.findPositionOf(state.context, CounterId.fromInt(5)));
+        assertEquals(headerLength + 5 * stepLength, 
cc.findPositionOf(state.context, CounterId.fromInt(6)));
+        assertEquals(headerLength + 6 * stepLength, 
cc.findPositionOf(state.context, CounterId.fromInt(7)));
+        assertEquals(headerLength + 7 * stepLength, 
cc.findPositionOf(state.context, CounterId.fromInt(8)));
+        assertEquals(headerLength + 8 * stepLength, 
cc.findPositionOf(state.context, CounterId.fromInt(9)));
+
+        assertEquals(-1, cc.findPositionOf(state.context, 
CounterId.fromInt(0)));
+        assertEquals(-1, cc.findPositionOf(state.context, 
CounterId.fromInt(10)));
+        assertEquals(-1, cc.findPositionOf(state.context, 
CounterId.fromInt(15)));
+        assertEquals(-1, cc.findPositionOf(state.context, 
CounterId.fromInt(20)));
+    }
+
+    @Test
+    public void testGetGlockAndCountOf()
+    {
+        ContextState state = ContextState.allocate(3, 3, 3, 
HeapAllocator.instance);
+
+        state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
+        state.writeRemote(CounterId.fromInt(2), 2L, 2L);
+        state.writeLocal( CounterId.fromInt(3), 3L, 3L);
+        state.writeGlobal(CounterId.fromInt(4), 4L, 4L);
+        state.writeRemote(CounterId.fromInt(5), 5L, 5L);
+        state.writeLocal( CounterId.fromInt(6), 6L, 6L);
+        state.writeGlobal(CounterId.fromInt(7), 7L, 7L);
+        state.writeRemote(CounterId.fromInt(8), 8L, 8L);
+        state.writeLocal(CounterId.fromInt(9), 9L, 9L);
+
+        assertEquals(ClockAndCount.create(1L, 1L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(1)));
+        assertEquals(ClockAndCount.create(2L, 2L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(2)));
+        assertEquals(ClockAndCount.create(3L, 3L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(3)));
+        assertEquals(ClockAndCount.create(4L, 4L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(4)));
+        assertEquals(ClockAndCount.create(5L, 5L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(5)));
+        assertEquals(ClockAndCount.create(6L, 6L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(6)));
+        assertEquals(ClockAndCount.create(7L, 7L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(7)));
+        assertEquals(ClockAndCount.create(8L, 8L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(8)));
+        assertEquals(ClockAndCount.create(9L, 9L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(9)));
+
+        assertEquals(ClockAndCount.create(0L, 0L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(0)));
+        assertEquals(ClockAndCount.create(0L, 0L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(10)));
+        assertEquals(ClockAndCount.create(0L, 0L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(15)));
+        assertEquals(ClockAndCount.create(0L, 0L), 
cc.getClockAndCountOf(state.context, CounterId.fromInt(20)));
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/714c4233/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java 
b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
index ea7516f..5f0fb5c 100644
--- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
+++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile;
 import static org.apache.cassandra.utils.ByteBufferUtil.bytesToHex;
 import static org.apache.cassandra.utils.ByteBufferUtil.hexToBytes;
-import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.FileReader;
@@ -216,7 +215,7 @@ public class SSTableExportTest extends SchemaLoader
         SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
 
         // Add rowA
-        cfamily.addColumn(new CounterCell(Util.cellname("colA"), 42, 
System.currentTimeMillis()));
+        cfamily.addColumn(CounterCell.createLocal(Util.cellname("colA"), 42, 
System.currentTimeMillis(), Long.MIN_VALUE));
         writer.append(Util.dk("rowA"), cfamily);
         cfamily.clear();
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/714c4233/test/unit/org/apache/cassandra/utils/CounterIdTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/CounterIdTest.java 
b/test/unit/org/apache/cassandra/utils/CounterIdTest.java
new file mode 100644
index 0000000..e7975f2
--- /dev/null
+++ b/test/unit/org/apache/cassandra/utils/CounterIdTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.utils;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.db.SystemKeyspace;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class CounterIdTest extends SchemaLoader
+{
+    @Test
+    public void testGetCurrentIdFromSystemKeyspace() throws IOException
+    {
+        // Renewing a bunch of times and checking we get the same thing from
+        // the system keyspace that what is in memory
+        CounterId id0 = CounterId.getLocalId();
+        assertEquals(id0, SystemKeyspace.getCurrentLocalCounterId());
+
+        CounterId.renewLocalId();
+        CounterId id1 = CounterId.getLocalId();
+        assertEquals(id1, SystemKeyspace.getCurrentLocalCounterId());
+        assertTrue(id1.compareTo(id0) == 1);
+
+        CounterId.renewLocalId();
+        CounterId id2 = CounterId.getLocalId();
+        assertEquals(id2, SystemKeyspace.getCurrentLocalCounterId());
+        assertTrue(id2.compareTo(id1) == 1);
+    }
+}
+

Reply via email to