cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1095262 - /cassandra/branches/cassandra-0.8/test/distributed/org/apache/cassandra/MutationTest.java
Date Wed, 20 Apr 2011 04:27:56 GMT
Author: jbellis
Date: Wed Apr 20 04:27:56 2011
New Revision: 1095262

URL: http://svn.apache.org/viewvc?rev=1095262&view=rev
Log:
r/m duplicate code from MutationTest
patch by stuhood; reviewed by jbellis for CASSANDRA-2517

Modified:
    cassandra/branches/cassandra-0.8/test/distributed/org/apache/cassandra/MutationTest.java

Modified: cassandra/branches/cassandra-0.8/test/distributed/org/apache/cassandra/MutationTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/test/distributed/org/apache/cassandra/MutationTest.java?rev=1095262&r1=1095261&r2=1095262&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/test/distributed/org/apache/cassandra/MutationTest.java
(original)
+++ cassandra/branches/cassandra-0.8/test/distributed/org/apache/cassandra/MutationTest.java
Wed Apr 20 04:27:56 2011
@@ -180,190 +180,6 @@ public class MutationTest extends TestBa
         }
     }
 
-    protected void insert(Cassandra.Client client, ByteBuffer key, String cf, String name,
String value, long timestamp, ConsistencyLevel cl)
-        throws InvalidRequestException, UnavailableException, TimedOutException, TException
-    {
-        Column col = new Column(
-             ByteBufferUtil.bytes(name),
-             ByteBufferUtil.bytes(value),
-             timestamp
-             );
-        client.insert(key, new ColumnParent(cf), col, cl);
-    }
-
-    protected Column getColumn(Cassandra.Client client, ByteBuffer key, String cf, String
col, ConsistencyLevel cl)
-        throws InvalidRequestException, UnavailableException, TimedOutException, TException,
NotFoundException
-    {
-        ColumnPath cpath = new ColumnPath(cf);
-        cpath.setColumn(col.getBytes());
-        return client.get(key, cpath, cl).column;
-    }
-
-    protected class Get extends RetryingAction
-    {
-        public Get(Cassandra.Client client, String cf, ByteBuffer key)
-        {
-            super(client, cf, key);
-        }
-
-        public void tryPerformAction(ConsistencyLevel cl) throws Exception
-        {
-            assertColumnEqual(name, value, timestamp, getColumn(client, key, cf, name, cl));
-        }
-    }
-
-    protected class Insert extends RetryingAction
-    {
-        public Insert(Cassandra.Client client, String cf, ByteBuffer key)
-        {
-            super(client, cf, key);
-        }
-
-        public void tryPerformAction(ConsistencyLevel cl) throws Exception
-        {
-            insert(client, key, cf, name, value, timestamp, cl);
-        }
-    }
-
-    /** Performs an action repeatedly until timeout, success or failure. */
-    protected abstract class RetryingAction
-    {
-        protected Cassandra.Client client;
-        protected String cf;
-        protected ByteBuffer key;
-        protected String name;
-        protected String value;
-        protected long timestamp;
-
-        private Set<Class<Exception>> expected = new HashSet<Class<Exception>>();
-        private long timeout = StorageService.RING_DELAY;
-
-        public RetryingAction(Cassandra.Client client, String cf, ByteBuffer key)
-        {
-            this.client = client;
-            this.cf = cf;
-            this.key = key;
-            this.timestamp = 0;
-        }
-
-        public RetryingAction name(String name)
-        {
-            this.name = name; return this;
-        }
-
-        /** The value to expect for the return column, or null to expect the column to be
missing. */
-        public RetryingAction value(String value)
-        {
-            this.value = value; return this;
-        }
-        
-        /** The total time to allow before failing. */
-        public RetryingAction timeout(long timeout)
-        {
-            this.timeout = timeout; return this;
-        }
-
-        /** The expected timestamp of the returned column. */
-        public RetryingAction timestamp(long timestamp)
-        {
-            this.timestamp = timestamp; return this;
-        }
-
-        /** The exception classes that indicate success. */
-        public RetryingAction expecting(Class... tempExceptions)
-        {
-            this.expected.clear();
-            for (Class exclass : tempExceptions)
-                expected.add((Class<Exception>)exclass);
-            return this;
-        }
-
-        public void perform(ConsistencyLevel cl) throws AssertionError
-        {
-            long deadline = System.currentTimeMillis() + timeout;
-            int attempts = 0;
-            String template = "%s for " + this + " after %d attempt(s) with %d ms to spare.";
-            Exception e = null;
-            while(deadline > System.currentTimeMillis())
-            {
-                try
-                {
-                    attempts++;
-                    tryPerformAction(cl);
-                    logger.info(String.format(template, "Succeeded", attempts, deadline -
System.currentTimeMillis()));
-                    return;
-                }
-                catch (Exception ex)
-                {
-                    e = ex;
-                    if (!expected.contains(ex.getClass()))
-                        continue;
-                    logger.info(String.format(template, "Caught expected exception: " + e,
attempts, deadline - System.currentTimeMillis()));
-                    return;
-                }
-            }
-            String err = String.format(template, "Caught unexpected: " + e, attempts, deadline
- System.currentTimeMillis());
-            logger.error(err);
-            throw new AssertionError(err);
-        }
-        
-        public String toString()
-        {
-            return this.getClass() + "(" + key + "," + name + ")";
-        }
-
-        protected abstract void tryPerformAction(ConsistencyLevel cl) throws Exception;
-    }
-
-    protected List<ColumnOrSuperColumn> get_slice(Cassandra.Client client, ByteBuffer
key, String cf, ConsistencyLevel cl)
-      throws InvalidRequestException, UnavailableException, TimedOutException, TException
-    {
-        SlicePredicate sp = new SlicePredicate();
-        sp.setSlice_range(
-            new SliceRange(
-                ByteBuffer.wrap(new byte[0]),
-                ByteBuffer.wrap(new byte[0]),
-                false,
-                1000
-                )
-            );
-        return client.get_slice(key, new ColumnParent(cf), sp, cl);
-    }
-
-    protected void assertColumnEqual(String name, String value, long timestamp, Column col)
-    {
-        assertEquals(ByteBufferUtil.bytes(name), col.name);
-        assertEquals(ByteBufferUtil.bytes(value), col.value);
-        assertEquals(timestamp, col.timestamp);
-    }
-
-    protected List<InetAddress> endpointsForKey(InetAddress seed, ByteBuffer key, String
keyspace)
-        throws IOException
-    {
-        RingCache ring = new RingCache(keyspace, new RandomPartitioner(), seed.getHostAddress(),
9160);
-        List<InetAddress> privateendpoints = ring.getEndpoint(key);
-        List<InetAddress> endpoints = new ArrayList<InetAddress>();
-        for (InetAddress endpoint : privateendpoints)
-        {
-            endpoints.add(controller.getPublicHost(endpoint));
-        }
-        return endpoints;
-    }
-
-    protected InetAddress nonEndpointForKey(InetAddress seed, ByteBuffer key, String keyspace)
-        throws IOException
-    {
-        List<InetAddress> endpoints = endpointsForKey(seed, key, keyspace);
-        for (InetAddress host : controller.getHosts())
-        {
-            if (!endpoints.contains(host))
-            {
-                return host;
-            }
-        }
-        return null;
-    }
-
     protected ByteBuffer newKey()
     {
         return ByteBufferUtil.bytes(String.format("test.key.%d", System.currentTimeMillis()));



Mime
View raw message