cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1065099 - /cassandra/trunk/test/distributed/org/apache/cassandra/CountersTest.java
Date Sat, 29 Jan 2011 20:20:51 GMT
Author: jbellis
Date: Sat Jan 29 20:20:51 2011
New Revision: 1065099

URL: http://svn.apache.org/viewvc?rev=1065099&view=rev
Log:
Adds a write ONE read ALL test for counters
patch by stuhood; reviewed by jbellis for CASSANDRA-2005

Added:
    cassandra/trunk/test/distributed/org/apache/cassandra/CountersTest.java

Added: cassandra/trunk/test/distributed/org/apache/cassandra/CountersTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/distributed/org/apache/cassandra/CountersTest.java?rev=1065099&view=auto
==============================================================================
--- cassandra/trunk/test/distributed/org/apache/cassandra/CountersTest.java (added)
+++ cassandra/trunk/test/distributed/org/apache/cassandra/CountersTest.java Sat Jan 29 20:20:51
2011
@@ -0,0 +1,88 @@
+/**
+ * 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;
+
+import java.io.*;
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import org.apache.thrift.TException;
+
+import org.apache.cassandra.thrift.*;
+
+import org.apache.cassandra.CassandraServiceController.Failure;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+
+public class CountersTest extends TestBase
+{
+    @Test
+    public void testWriteOneReadAll() throws Exception
+    {
+        List<InetAddress> hosts = controller.getHosts();
+        // create a keyspace that performs counter validation
+        final String keyspace = "TestOneNodeWrite";
+        keyspace(keyspace).rf(3).validator("CounterColumnType").create();
+
+        for (InetAddress host : hosts)
+        {
+            Cassandra.Client client = controller.createClient(host);
+            client.set_keyspace(keyspace);
+
+            ByteBuffer key = newKey();
+
+            add(client, key, "Standard1", "c1", 1, ConsistencyLevel.ONE);
+            add(client, key, "Standard1", "c2", 2, ConsistencyLevel.ONE);
+
+            new CounterGet(client, "Standard1", key).name("c1").value(1L).perform(ConsistencyLevel.ALL);
+            new CounterGet(client, "Standard1", key).name("c2").value(2L).perform(ConsistencyLevel.ALL);
+        }
+    }
+
+    protected class CounterGet extends RetryingAction<Long>
+    {
+        public CounterGet(Cassandra.Client client, String cf, ByteBuffer key)
+        {
+            super(client, cf, key);
+        }
+
+        public void tryPerformAction(ConsistencyLevel cl) throws Exception
+        {
+            ByteBuffer bname = ByteBuffer.wrap(name.getBytes());
+            ColumnPath cpath = new ColumnPath(cf).setColumn(bname);
+            CounterColumn col = client.get_counter(key, cpath, cl).column;
+            assertEquals(bname, col.name);
+            assertEquals(value.longValue(), col.value);
+        }
+    }
+
+    /** NB: Counter increments are unfortunately not idempotent, so we don't provide a RetyingAction
to perform them. */
+    protected void add(Cassandra.Client client, ByteBuffer key, String cf, String name, long
value, ConsistencyLevel cl)
+        throws InvalidRequestException, UnavailableException, TimedOutException, TException
+    {
+        CounterColumn col = new CounterColumn(ByteBuffer.wrap(name.getBytes()), value);
+        client.add(key, new ColumnParent(cf), col, cl);
+    }
+}



Mime
View raw message