cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1027349 [1/2] - in /cassandra/branches/cassandra-0.7: contrib/client_only/ contrib/pig/src/java/org/apache/cassandra/hadoop/pig/ contrib/word_count/src/ src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/db/migration/ src/java...
Date Tue, 26 Oct 2010 03:14:10 GMT
Author: jbellis
Date: Tue Oct 26 03:14:08 2010
New Revision: 1027349

URL: http://svn.apache.org/viewvc?rev=1027349&view=rev
Log:
include offset in buffer calculations.  patch by Jake Luciani; reviewed by Stu Hood for CASSANDRA-1661

Modified:
    cassandra/branches/cassandra-0.7/contrib/client_only/ClientOnlyExample.java
    cassandra/branches/cassandra-0.7/contrib/pig/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java
    cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCount.java
    cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCountSetup.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DefsTable.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/HintedHandOffManager.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SystemTable.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/migration/Migration.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/Range.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/OutboundTcpConnection.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/GuidGenerator.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/client/TestRingCache.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/DefsTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/NameSortTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/OneCompactionTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ReadMessageTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RecoveryManagerTruncateTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RemoveColumnFamilyTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush1Test.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RemoveColumnFamilyWithFlush2Test.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RemoveColumnTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RemoveSubColumnTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RowIterationTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/RowTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/SuperColumnTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/TableTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/TimeSortTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/marshal/TypeCompareTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/LazilyCompactedRowTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableWriterTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/EmbeddedCassandraServiceTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/tools/SSTableImportTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/utils/BloomFilterTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/utils/FilterTest.java

Modified: cassandra/branches/cassandra-0.7/contrib/client_only/ClientOnlyExample.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/contrib/client_only/ClientOnlyExample.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/contrib/client_only/ClientOnlyExample.java (original)
+++ cassandra/branches/cassandra-0.7/contrib/client_only/ClientOnlyExample.java Tue Oct 26 03:14:08 2010
@@ -80,7 +80,7 @@ public class ClientOnlyExample
         // do some queries.
         Collection<ByteBuffer> cols = new ArrayList<ByteBuffer>()
         {{
-            add(ByteBuffer.wrap("colb".getBytes()));
+            add(ByteBufferUtil.bytes("colb"));
         }};
         for (int i = 0; i < 100; i++)
         {
@@ -97,7 +97,7 @@ public class ClientOnlyExample
             {
                 for (IColumn col : cf.getSortedColumns())
                 {
-                    System.out.println(ByteBufferUtil.string(col.name(), Charsets.UTF_8) + ", " + ByteBufferUtil.string(col.value(), Charsets.UTF_8));
+                    System.out.println(ByteBufferUtil.string(col.name()) + ", " + ByteBufferUtil.string(col.value()));
                 }
             }
             else

Modified: cassandra/branches/cassandra-0.7/contrib/pig/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/contrib/pig/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/contrib/pig/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java (original)
+++ cassandra/branches/cassandra-0.7/contrib/pig/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java Tue Oct 26 03:14:08 2010
@@ -17,6 +17,7 @@
 package org.apache.cassandra.hadoop.pig;
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.util.*;
 
 import org.apache.cassandra.db.Column;
@@ -25,6 +26,7 @@ import org.apache.cassandra.db.SuperColu
 import org.apache.cassandra.hadoop.*;
 import org.apache.cassandra.thrift.SlicePredicate;
 import org.apache.cassandra.thrift.SliceRange;
+import org.apache.cassandra.utils.FBUtilities;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
@@ -52,7 +54,7 @@ public class CassandraStorage extends Lo
     public final static String PIG_INITIAL_ADDRESS = "PIG_INITIAL_ADDRESS";
     public final static String PIG_PARTITIONER = "PIG_PARTITIONER";
 
-    private final static byte[] BOUND = new byte[0];
+    private final static ByteBuffer BOUND = FBUtilities.EMPTY_BYTE_BUFFER;
     private final static int LIMIT = 1024;
 
     private Configuration conf;
@@ -75,7 +77,11 @@ public class CassandraStorage extends Lo
             ArrayList<Tuple> columns = new ArrayList<Tuple>();
             tuple.set(0, new DataByteArray(key));
             for (Map.Entry<byte[], IColumn> entry : cf.entrySet())
-                columns.add(columnToTuple(entry.getKey(), entry.getValue()));
+            {                    
+                byte[] name = entry.getKey();
+                columns.add(columnToTuple(name, 0, name.length, entry.getValue()));
+            }
+         
             tuple.set(1, new DefaultDataBag(columns));
             return tuple;
         }
@@ -85,21 +91,26 @@ public class CassandraStorage extends Lo
         }
     }
 
-    private Tuple columnToTuple(byte[] name, IColumn col) throws IOException
+    private Tuple columnToTuple(byte[] name, int nameOffset, int nameLength, IColumn col) throws IOException
     {
         Tuple pair = TupleFactory.getInstance().newTuple(2);
-        pair.set(0, new DataByteArray(name));
+        pair.set(0, new DataByteArray(name, nameOffset, nameLength));
         if (col instanceof Column)
         {
             // standard
-            pair.set(1, new DataByteArray(col.value()));
+            pair.set(1, new DataByteArray(col.value().array(), 
+                                          col.value().position()+col.value().arrayOffset(),
+                                          col.value().remaining()));
             return pair;
         }
 
         // super
         ArrayList<Tuple> subcols = new ArrayList<Tuple>();
         for (IColumn subcol : ((SuperColumn)col).getSubColumns())
-            subcols.add(columnToTuple(subcol.name(), subcol));
+            subcols.add(columnToTuple(subcol.name().array(), 
+                                      subcol.name().position()+subcol.name().arrayOffset(),
+                                      subcol.name().remaining(), subcol));
+        
         pair.set(1, new DefaultDataBag(subcols));
         return pair;
     }

Modified: cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCount.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCount.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCount.java (original)
+++ cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCount.java Tue Oct 26 03:14:08 2010
@@ -81,7 +81,7 @@ public class WordCount extends Configure
             IColumn column = columns.get(columnName.getBytes());
             if (column == null)
                 return;
-            String value = ByteBufferUtil.string(column.value(), Charsets.UTF_8);
+            String value = ByteBufferUtil.string(column.value());
             logger.debug("read " + key + ":" + value + " from " + context.getInputSplit());
 
             StringTokenizer itr = new StringTokenizer(value);

Modified: cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCountSetup.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCountSetup.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCountSetup.java (original)
+++ cassandra/branches/cassandra-0.7/contrib/word_count/src/WordCountSetup.java Tue Oct 26 03:14:08 2010
@@ -16,9 +16,11 @@
  * limitations under the License.
  */
 
+import java.nio.ByteBuffer;
 import java.util.*;
 
 import org.apache.cassandra.thrift.*;
+import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.protocol.TProtocol;
@@ -43,29 +45,29 @@ public class WordCountSetup
 
         client.set_keyspace(WordCount.KEYSPACE);
 
-        Map<byte[], Map<String,List<Mutation>>> mutationMap;
+        Map<ByteBuffer, Map<String,List<Mutation>>> mutationMap;
         Column c;
 
         // text0: no rows
 
         // text1: 1 row, 1 word
-        c = new Column("text1".getBytes(), "word1".getBytes(), System.currentTimeMillis());
-        mutationMap = getMutationMap("key0".getBytes(), WordCount.COLUMN_FAMILY, c);
+        c = new Column(ByteBufferUtil.bytes("text1"), ByteBufferUtil.bytes("word1"), System.currentTimeMillis());
+        mutationMap = getMutationMap(ByteBufferUtil.bytes("key0"), WordCount.COLUMN_FAMILY, c);
         client.batch_mutate(mutationMap, ConsistencyLevel.ONE);
         logger.info("added text1");
 
         // text1: 1 row, 2 word
-        c = new Column("text2".getBytes(), "word1 word2".getBytes(), System.currentTimeMillis());
-        mutationMap = getMutationMap("key0".getBytes(), WordCount.COLUMN_FAMILY, c);
+        c = new Column(ByteBufferUtil.bytes("text2"), ByteBufferUtil.bytes("word1 word2"), System.currentTimeMillis());
+        mutationMap = getMutationMap(ByteBufferUtil.bytes("key0"), WordCount.COLUMN_FAMILY, c);
         client.batch_mutate(mutationMap, ConsistencyLevel.ONE);
         logger.info("added text2");
 
         // text3: 1000 rows, 1 word
-        mutationMap = new HashMap<byte[],Map<String,List<Mutation>>>();
+        mutationMap = new HashMap<ByteBuffer,Map<String,List<Mutation>>>();
         for (int i=0; i<1000; i++)
         {
-            c = new Column("text3".getBytes(), "word1".getBytes(), System.currentTimeMillis());
-            addToMutationMap(mutationMap, ("key" + i).getBytes(), WordCount.COLUMN_FAMILY, c);
+            c = new Column(ByteBufferUtil.bytes("text3"), ByteBufferUtil.bytes("word1"), System.currentTimeMillis());
+            addToMutationMap(mutationMap, ByteBufferUtil.bytes("key" + i), WordCount.COLUMN_FAMILY, c);
         }
         client.batch_mutate(mutationMap, ConsistencyLevel.ONE);
         logger.info("added text3");
@@ -73,14 +75,14 @@ public class WordCountSetup
         System.exit(0);
     }
 
-    private static Map<byte[],Map<String,List<Mutation>>> getMutationMap(byte[] key, String cf, Column c)
+    private static Map<ByteBuffer,Map<String,List<Mutation>>> getMutationMap(ByteBuffer key, String cf, Column c)
     {
-        Map<byte[],Map<String,List<Mutation>>> mutationMap = new HashMap<byte[],Map<String,List<Mutation>>>();
+        Map<ByteBuffer,Map<String,List<Mutation>>> mutationMap = new HashMap<ByteBuffer,Map<String,List<Mutation>>>();
         addToMutationMap(mutationMap, key, cf, c);
         return mutationMap;
     }
 
-    private static void addToMutationMap(Map<byte[],Map<String,List<Mutation>>> mutationMap, byte[] key, String cf, Column c)
+    private static void addToMutationMap(Map<ByteBuffer,Map<String,List<Mutation>>> mutationMap, ByteBuffer key, String cf, Column c)
     {
         Map<String,List<Mutation>> cfMutation = new HashMap<String,List<Mutation>>();
         List<Mutation> mList = new ArrayList<Mutation>();

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DefsTable.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DefsTable.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DefsTable.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DefsTable.java Tue Oct 26 03:14:08 2010
@@ -40,12 +40,13 @@ import org.apache.cassandra.db.migration
 import org.apache.cassandra.io.SerDeUtils;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.UUIDGen;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class DefsTable
 {
     // column name for the schema storing serialized keyspace definitions
     // NB: must be an invalid keyspace name
-    public static final ByteBuffer DEFINITION_SCHEMA_COLUMN_NAME = ByteBuffer.wrap("Avro/Schema".getBytes(UTF_8));
+    public static final ByteBuffer DEFINITION_SCHEMA_COLUMN_NAME = ByteBufferUtil.bytes("Avro/Schema");
 
     /** dumps current keyspace definitions to storage */
     public static synchronized void dumpToStorage(UUID version) throws IOException

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/HintedHandOffManager.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/HintedHandOffManager.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/HintedHandOffManager.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/HintedHandOffManager.java Tue Oct 26 03:14:08 2010
@@ -180,7 +180,7 @@ public class HintedHandOffManager
             throw new RuntimeException("Corrupted hint name " + joined.toString());
         String[] parts = new String[2];
         parts[0] = new String(ArrayUtils.subarray(joined.array(), joined.position()+joined.arrayOffset(), index));
-        parts[1] = new String(ArrayUtils.subarray(joined.array(), index+1, joined.limit()));
+        parts[1] = new String(ArrayUtils.subarray(joined.array(), index+1, joined.limit()+joined.arrayOffset()));
         return parts;
 
     }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SystemTable.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SystemTable.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SystemTable.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SystemTable.java Tue Oct 26 03:14:08 2010
@@ -51,15 +51,15 @@ public class SystemTable
     private static Logger logger = LoggerFactory.getLogger(SystemTable.class);
     public static final String STATUS_CF = "LocationInfo"; // keep the old CF string for backwards-compatibility
     public static final String INDEX_CF = "IndexInfo";
-    private static final ByteBuffer LOCATION_KEY = ByteBuffer.wrap("L".getBytes(UTF_8));
-    private static final ByteBuffer RING_KEY = ByteBuffer.wrap("Ring".getBytes(UTF_8));
-    private static final ByteBuffer BOOTSTRAP_KEY = ByteBuffer.wrap("Bootstrap".getBytes(UTF_8));
-    private static final ByteBuffer COOKIE_KEY = ByteBuffer.wrap("Cookies".getBytes(UTF_8));
-    private static final ByteBuffer BOOTSTRAP = ByteBuffer.wrap("B".getBytes(UTF_8));
-    private static final ByteBuffer TOKEN = ByteBuffer.wrap("Token".getBytes(UTF_8));
-    private static final ByteBuffer GENERATION = ByteBuffer.wrap("Generation".getBytes(UTF_8));
-    private static final ByteBuffer CLUSTERNAME = ByteBuffer.wrap("ClusterName".getBytes(UTF_8));
-    private static final ByteBuffer PARTITIONER = ByteBuffer.wrap("Partioner".getBytes(UTF_8));
+    private static final ByteBuffer LOCATION_KEY = ByteBufferUtil.bytes("L");
+    private static final ByteBuffer RING_KEY = ByteBufferUtil.bytes("Ring");
+    private static final ByteBuffer BOOTSTRAP_KEY = ByteBufferUtil.bytes("Bootstrap");
+    private static final ByteBuffer COOKIE_KEY = ByteBufferUtil.bytes("Cookies");
+    private static final ByteBuffer BOOTSTRAP = ByteBufferUtil.bytes("B");
+    private static final ByteBuffer TOKEN = ByteBufferUtil.bytes("Token");
+    private static final ByteBuffer GENERATION = ByteBufferUtil.bytes("Generation");
+    private static final ByteBuffer CLUSTERNAME = ByteBufferUtil.bytes("ClusterName");
+    private static final ByteBuffer PARTITIONER = ByteBufferUtil.bytes("Partioner");
 
     private static DecoratedKey decorate(ByteBuffer key)
     {
@@ -70,7 +70,7 @@ public class SystemTable
     public static void purgeIncompatibleHints() throws IOException
     {
         // 0.6->0.7
-        final ByteBuffer hintsPurged6to7 = ByteBuffer.wrap("Hints purged as part of upgrading from 0.6.x to 0.7".getBytes());
+        final ByteBuffer hintsPurged6to7 = ByteBufferUtil.bytes("Hints purged as part of upgrading from 0.6.x to 0.7");
         Table table = Table.open(Table.SYSTEM_TABLE);
         QueryFilter dotSeven = QueryFilter.getNamesFilter(decorate(COOKIE_KEY), new QueryPath(STATUS_CF), hintsPurged6to7);
         ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(dotSeven);
@@ -80,7 +80,7 @@ public class SystemTable
             logger.info("Upgrading to 0.7. Purging hints if there are any. Old hints will be snapshotted.");
             new Truncation(Table.SYSTEM_TABLE, HintedHandOffManager.HINTS_CF).apply();
             RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, COOKIE_KEY);
-            rm.add(new QueryPath(STATUS_CF, null, hintsPurged6to7), ByteBuffer.wrap("oh yes, it they were purged.".getBytes()), System.currentTimeMillis());
+            rm.add(new QueryPath(STATUS_CF, null, hintsPurged6to7), ByteBufferUtil.bytes("oh yes, it they were purged."), System.currentTimeMillis());
             rm.apply();
         }
     }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/migration/Migration.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/migration/Migration.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/migration/Migration.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/migration/Migration.java Tue Oct 26 03:14:08 2010
@@ -44,6 +44,7 @@ import org.apache.cassandra.io.util.Data
 import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.UUIDGen;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 import static com.google.common.base.Charsets.UTF_8;
 
@@ -71,8 +72,8 @@ public abstract class Migration
     public static final String NAME_VALIDATOR_REGEX = "\\w+";
     public static final String MIGRATIONS_CF = "Migrations";
     public static final String SCHEMA_CF = "Schema";
-    public static final ByteBuffer MIGRATIONS_KEY = ByteBuffer.wrap("Migrations Key".getBytes(UTF_8));
-    public static final ByteBuffer LAST_MIGRATION_KEY = ByteBuffer.wrap("Last Migration".getBytes(UTF_8));
+    public static final ByteBuffer MIGRATIONS_KEY = ByteBufferUtil.bytes("Migrations Key");
+    public static final ByteBuffer LAST_MIGRATION_KEY = ByteBufferUtil.bytes("Last Migration");
     
     protected RowMutation rm;
     protected UUID newVersion;

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java Tue Oct 26 03:14:08 2010
@@ -49,7 +49,7 @@ public class RandomPartitioner implement
     {
         // find the delimiter position
         int splitPoint = -1;
-        for (int i = fromdisk.position()+fromdisk.arrayOffset(); i < fromdisk.limit(); i++)
+        for (int i = fromdisk.position()+fromdisk.arrayOffset(); i < fromdisk.limit()+fromdisk.arrayOffset(); i++)
         {
             if (fromdisk.array()[i] == DELIMITER_BYTE)
             {
@@ -61,7 +61,7 @@ public class RandomPartitioner implement
 
         // and decode the token and key
         String token = new String(fromdisk.array(), fromdisk.position()+fromdisk.arrayOffset(), splitPoint, UTF_8);
-        byte[] key = Arrays.copyOfRange(fromdisk.array(), splitPoint + 1, fromdisk.limit());
+        byte[] key = Arrays.copyOfRange(fromdisk.array(), splitPoint + 1, fromdisk.limit()+fromdisk.arrayOffset());
         return new DecoratedKey<BigIntegerToken>(new BigIntegerToken(token), ByteBuffer.wrap(key));
     }
 

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/Range.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/Range.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/Range.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/Range.java Tue Oct 26 03:14:08 2010
@@ -230,7 +230,7 @@ public class Range extends AbstractBound
         {
             l  = ((ByteBuffer)left.token).array();
             lo = ((ByteBuffer)left.token).position()+((ByteBuffer)left.token).arrayOffset();
-            ll = ((ByteBuffer)left.token).limit();
+            ll = ((ByteBuffer)left.token).limit()+((ByteBuffer)left.token).arrayOffset();
         }else{
             //Handles other token types
             return left.compareTo(right);
@@ -246,7 +246,7 @@ public class Range extends AbstractBound
         {
             r  = ((ByteBuffer)right.token).array();
             ro = ((ByteBuffer)right.token).position()+((ByteBuffer)right.token).arrayOffset();
-            rl = ((ByteBuffer)right.token).limit();
+            rl = ((ByteBuffer)right.token).limit()+((ByteBuffer)right.token).arrayOffset();
         }
        
             

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/OutboundTcpConnection.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/OutboundTcpConnection.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/OutboundTcpConnection.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/net/OutboundTcpConnection.java Tue Oct 26 03:14:08 2010
@@ -104,7 +104,7 @@ public class OutboundTcpConnection exten
     {
         try
         {
-            output.write(bb.array(), 0, bb.limit());
+            output.write(bb.array(), bb.position()+bb.arrayOffset(), bb.limit()+bb.arrayOffset());
             if (queue.peek() == null)
             {
                 output.flush();

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java Tue Oct 26 03:14:08 2010
@@ -18,28 +18,63 @@
  */
 package org.apache.cassandra.utils;
 
+import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 
 /**
  * Utility methods to make ByteBuffers less painful
+ * The following should illustrate the different ways byte buffers can be used 
+ * 
+ *        public void testArrayOffet()
+ *        {
+ *                
+ *            byte[] b = "test_slice_array".getBytes();
+ *            ByteBuffer bb = ByteBuffer.allocate(1024);
+ *    
+ *            assert bb.position() == 0;
+ *            assert bb.limit()    == 1024;
+ *            assert bb.capacity() == 1024;
+ *    
+ *            bb.put(b);
+ *            
+ *            assert bb.position()  == b.length;
+ *            assert bb.remaining() == bb.limit() - bb.position();
+ *            
+ *            ByteBuffer bb2 = bb.slice();
+ *            
+ *            assert bb2.position()    == 0;
+ *            
+ *            //slice should begin at other buffers current position
+ *            assert bb2.arrayOffset() == bb.position();
+ *            
+ *            //to match the position in the underlying array one needs to 
+ *            //track arrayOffset
+ *            assert bb2.limit()+bb2.arrayOffset() == bb.limit();
+ *            
+ *           
+ *            assert bb2.remaining() == bb.remaining();
+ *                             
+ *        }
+ *
+ * }
  *
  */
 public class ByteBufferUtil {
 
     public static int compareUnsigned(ByteBuffer o1, ByteBuffer o2)
     {
-        return FBUtilities.compareUnsigned(o1.array(), o2.array(), o1.arrayOffset()+o1.position(), o2.arrayOffset()+o2.position(), o1.limit(), o2.limit());
+        return FBUtilities.compareUnsigned(o1.array(), o2.array(), o1.arrayOffset()+o1.position(), o2.arrayOffset()+o2.position(), o1.limit()+o1.arrayOffset(), o2.limit()+o2.arrayOffset());
     }
     
     public static int compare(byte[] o1, ByteBuffer o2)
     {
-        return FBUtilities.compareUnsigned(o1, o2.array(), 0, o2.arrayOffset()+o2.position(), o1.length, o2.limit());
+        return FBUtilities.compareUnsigned(o1, o2.array(), 0, o2.arrayOffset()+o2.position(), o1.length, o2.limit()+o2.arrayOffset());
     }
 
     public static int compare(ByteBuffer o1, byte[] o2)
     {
-        return FBUtilities.compareUnsigned(o1.array(), o2, o1.arrayOffset()+o1.position(), 0, o1.limit(), o2.length);
+        return FBUtilities.compareUnsigned(o1.array(), o2, o1.arrayOffset()+o1.position(), 0, o1.limit()+o1.arrayOffset(), o2.length);
     }
 
     public static String string(ByteBuffer b, Charset charset)
@@ -51,4 +86,16 @@ public class ByteBufferUtil {
     {
         return new String(b.array(), b.arrayOffset() + b.position(), b.remaining());
     }
+    
+    public static ByteBuffer bytes(String s) 
+    { 
+        try
+        {
+            return ByteBuffer.wrap(s.getBytes("UTF-8"));
+        }
+        catch (UnsupportedEncodingException e)
+        {
+           throw new RuntimeException(e);
+        } 
+    }
 }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java Tue Oct 26 03:14:08 2010
@@ -67,14 +67,6 @@ public class FBUtilities
 
     public static final int MAX_UNSIGNED_SHORT = 0xFFFF;
 
-    /*public static final Comparator<byte[]> byteArrayComparator = new Comparator<byte[]>()
-    {
-        public int compare(byte[] o1, byte[] o2)
-        {
-            return compareByteArrays(o1, o2);
-        }
-    };*/
-
     /**
      * Parses a string representing either a fraction, absolute value or percentage.
      */
@@ -264,12 +256,13 @@ public class FBUtilities
         {
             throw new IOException("Corrupt (negative) value length encountered");
         }
-        byte[] value = new byte[length];
+       
+        ByteBuffer bb = ByteBuffer.allocate(length);
         if (length > 0)
         {
-            in.readFully(value);
+            in.readFully(bb.array(),bb.position(),bb.remaining());
         }
-        return ByteBuffer.wrap(value);
+        return bb;
     }
 
     public static void writeShortByteArray(ByteBuffer name, DataOutput out)
@@ -299,9 +292,10 @@ public class FBUtilities
 
     public static ByteBuffer readShortByteArray(DataInput in) throws IOException
     {
-        byte[] bytes = new byte[readShortLength(in)];
-        in.readFully(bytes);
-        return ByteBuffer.wrap(bytes);
+        int length = readShortLength(in);
+        ByteBuffer bb = ByteBuffer.allocate(length);
+        in.readFully(bb.array(),bb.position(),bb.remaining());
+        return bb;
     }
 
     /** @return null */
@@ -346,7 +340,7 @@ public class FBUtilities
     public static String bytesToHex(ByteBuffer bytes)
     {
         StringBuilder sb = new StringBuilder();
-        for (int i=bytes.position()+bytes.arrayOffset(); i<bytes.limit(); i++)
+        for (int i=bytes.position()+bytes.arrayOffset(); i<bytes.limit()+bytes.arrayOffset(); i++)
         {
             int bint = bytes.array()[i] & 0xff;
             if (bint <= 0xF)

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/GuidGenerator.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/GuidGenerator.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/GuidGenerator.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/GuidGenerator.java Tue Oct 26 03:14:08 2010
@@ -64,7 +64,7 @@ public class GuidGenerator {
         ByteBuffer array = guidAsBytes();
         
         StringBuilder sb = new StringBuilder();
-        for (int j = array.position()+array.arrayOffset(); j < array.limit(); ++j) {
+        for (int j = array.position()+array.arrayOffset(); j < array.limit()+array.arrayOffset(); ++j) {
             int b = array.array()[j] & 0xFF;
             if (b < 0x10) sb.append('0');
             sb.append(Integer.toHexString(b));

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/client/TestRingCache.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/client/TestRingCache.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/client/TestRingCache.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/client/TestRingCache.java Tue Oct 26 03:14:08 2010
@@ -32,6 +32,8 @@ import org.apache.commons.lang.StringUti
 import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.transport.TFramedTransport;
 import org.apache.thrift.transport.TSocket;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 
 /**
  *  Sample code that uses RingCache in the client.
@@ -101,7 +103,7 @@ public class TestRingCache
             // now, read the row back directly from the host owning the row locally
             tester.setup(firstEndpoint.getHostAddress(), DatabaseDescriptor.getRpcPort());
             tester.thriftClient.set_keyspace(keyspace);
-            tester.thriftClient.insert(row, parent, new Column(ByteBuffer.wrap("col1".getBytes()), ByteBuffer.wrap("val1".getBytes()), 1), ConsistencyLevel.ONE);
+            tester.thriftClient.insert(row, parent, new Column(ByteBufferUtil.bytes("col1"), ByteBufferUtil.bytes("val1"), 1), ConsistencyLevel.ONE);
             Column column = tester.thriftClient.get(row, col, ConsistencyLevel.ONE).column;
             System.out.println("read row " + new String(row.array()) + " " + new String(column.name.array()) + ":" + new String(column.value.array()) + ":" + column.timestamp);
         }

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java Tue Oct 26 03:14:08 2010
@@ -22,22 +22,21 @@ package org.apache.cassandra.config;
 
 
 import java.nio.ByteBuffer;
-
 import org.junit.Test;
-
 import org.apache.cassandra.thrift.IndexType;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class ColumnDefinitionTest
 {
     @Test
     public void testSerializeDeserialize() throws Exception
     {
-        ColumnDefinition cd0 = new ColumnDefinition(ByteBuffer.wrap("TestColumnDefinitionName0".getBytes("UTF8")),
+        ColumnDefinition cd0 = new ColumnDefinition(ByteBufferUtil.bytes("TestColumnDefinitionName0"),
                                                     "BytesType",
                                                     IndexType.KEYS,
                                                     "random index name 0");
 
-        ColumnDefinition cd1 = new ColumnDefinition(ByteBuffer.wrap("TestColumnDefinition1".getBytes("UTF8")),
+        ColumnDefinition cd1 = new ColumnDefinition(ByteBufferUtil.bytes("TestColumnDefinition1"),
                                                     "LongType",
                                                     null,
                                                     null);

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java Tue Oct 26 03:14:08 2010
@@ -49,6 +49,7 @@ import org.apache.cassandra.utils.Wrappe
 
 import static junit.framework.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class ColumnFamilyStoreTest extends CleanupHelper
 {
@@ -68,9 +69,9 @@ public class ColumnFamilyStoreTest exten
     {
         List<RowMutation> rms = new LinkedList<RowMutation>();
         RowMutation rm;
-        rm = new RowMutation("Keyspace1", ByteBuffer.wrap("key1".getBytes()));
-        rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap("Column1".getBytes())), ByteBuffer.wrap("asdf".getBytes()), 0);
-        rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap("Column2".getBytes())), ByteBuffer.wrap("asdf".getBytes()), 0);
+        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1"));
+        rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0);
+        rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column2")), ByteBufferUtil.bytes("asdf"), 0);
         rms.add(rm);
         ColumnFamilyStore store = Util.writeColumnFamily(rms);
 
@@ -78,7 +79,7 @@ public class ColumnFamilyStoreTest exten
         List<SSTableReader> ssTables = table.getAllSSTables();
         assertEquals(1, ssTables.size());
         ssTables.get(0).forceFilterFailures();
-        ColumnFamily cf = store.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("key2"), new QueryPath("Standard1", null, ByteBuffer.wrap("Column1".getBytes()))));
+        ColumnFamily cf = store.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("key2"), new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1"))));
         assertNull(cf);
     }
 
@@ -89,7 +90,7 @@ public class ColumnFamilyStoreTest exten
         final ColumnFamilyStore store = table.getColumnFamilyStore("Standard2");
         RowMutation rm;
 
-        rm = new RowMutation("Keyspace1", ByteBuffer.wrap("key1".getBytes()));
+        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key1"));
         rm.delete(new QueryPath("Standard2", null, null), System.currentTimeMillis());
         rm.apply();
 
@@ -102,7 +103,7 @@ public class ColumnFamilyStoreTest exten
                 assert cf.isMarkedForDelete();
                 assert cf.getColumnsMap().isEmpty();
 
-                QueryFilter namesFilter = QueryFilter.getNamesFilter(Util.dk("key1"), new QueryPath("Standard2", null, null), ByteBuffer.wrap("a".getBytes()));
+                QueryFilter namesFilter = QueryFilter.getNamesFilter(Util.dk("key1"), new QueryPath("Standard2", null, null), ByteBufferUtil.bytes("a"));
                 cf = store.getColumnFamily(namesFilter);
                 assert cf.isMarkedForDelete();
                 assert cf.getColumnsMap().isEmpty();
@@ -121,9 +122,9 @@ public class ColumnFamilyStoreTest exten
         List<Row> result = cfs.getRangeSlice(FBUtilities.EMPTY_BYTE_BUFFER,
                                              Util.range(p, "key1", "key2"),
                                              10,
-                                             new NamesQueryFilter(ByteBuffer.wrap("asdf".getBytes())));
+                                             new NamesQueryFilter(ByteBufferUtil.bytes("asdf")));
         assertEquals(1, result.size());
-        assert result.get(0).key.key.equals(ByteBuffer.wrap("key2".getBytes()));
+        assert result.get(0).key.key.equals(ByteBufferUtil.bytes("key2"));
     }
 
     @Test
@@ -131,28 +132,28 @@ public class ColumnFamilyStoreTest exten
     {
         RowMutation rm;
 
-        rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k1".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0);
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0);
+        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k1"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), FBUtilities.toByteBuffer(1L), 0);
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(1L), 0);
         rm.apply();
 
-        rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k2".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 0);
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 0);
+        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k2"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), FBUtilities.toByteBuffer(2L), 0);
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(2L), 0);
         rm.apply();
 
-        rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k3".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 0);
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0);
+        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k3"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), FBUtilities.toByteBuffer(2L), 0);
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(1L), 0);
         rm.apply();
 
-        rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k4aaaa".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("notbirthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 0);
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(3L), 0);
+        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k4aaaa"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), FBUtilities.toByteBuffer(2L), 0);
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(3L), 0);
         rm.apply();
 
         // basic single-expression query
-        IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L));
+        IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, FBUtilities.toByteBuffer(1L));
         IndexClause clause = new IndexClause(Arrays.asList(expr),FBUtilities.EMPTY_BYTE_BUFFER, 100);
         IFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
@@ -161,24 +162,32 @@ public class ColumnFamilyStoreTest exten
 
         assert rows != null;
         assert rows.size() == 2 : StringUtils.join(rows, ",");
-        assert Arrays.equals("k1".getBytes(), rows.get(0).key.key.array());
-        assert Arrays.equals("k3".getBytes(), rows.get(1).key.key.array());
-        assert FBUtilities.toByteBuffer(1L).equals( rows.get(0).cf.getColumn(ByteBuffer.wrap("birthdate".getBytes("UTF8"))).value());
-        assert FBUtilities.toByteBuffer(1L).equals( rows.get(1).cf.getColumn(ByteBuffer.wrap("birthdate".getBytes("UTF8"))).value());
+        
+        String key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k1".equals( key );
+    
+        key = new String(rows.get(1).key.key.array(),rows.get(1).key.key.position(),rows.get(1).key.key.remaining()); 
+        assert "k3".equals(key);
+        
+        assert FBUtilities.toByteBuffer(1L).equals( rows.get(0).cf.getColumn(ByteBufferUtil.bytes("birthdate")).value());
+        assert FBUtilities.toByteBuffer(1L).equals( rows.get(1).cf.getColumn(ByteBufferUtil.bytes("birthdate")).value());
 
         // add a second expression
-        IndexExpression expr2 = new IndexExpression(ByteBuffer.wrap("notbirthdate".getBytes("UTF8")), IndexOperator.GTE, FBUtilities.toByteBuffer(2L));
+        IndexExpression expr2 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"), IndexOperator.GTE, FBUtilities.toByteBuffer(2L));
         clause = new IndexClause(Arrays.asList(expr, expr2), FBUtilities.EMPTY_BYTE_BUFFER, 100);
         rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").scan(clause, range, filter);
 
         assert rows.size() == 1 : StringUtils.join(rows, ",");
-        assert Arrays.equals("k3".getBytes(), rows.get(0).key.key.array());
-
+        key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k3".equals( key );
+    
         // same query again, but with resultset not including the subordinate expression
-        rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").scan(clause, range, new NamesQueryFilter(ByteBuffer.wrap("birthdate".getBytes("UTF8"))));
+        rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").scan(clause, range, new NamesQueryFilter(ByteBufferUtil.bytes("birthdate")));
 
         assert rows.size() == 1 : StringUtils.join(rows, ",");
-        assert Arrays.equals("k3".getBytes(), rows.get(0).key.key.array());
+        key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k3".equals( key );
+    
         assert rows.get(0).cf.getColumnCount() == 1 : rows.get(0).cf;
 
         // once more, this time with a slice rowset that needs to be expanded
@@ -186,12 +195,14 @@ public class ColumnFamilyStoreTest exten
         rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").scan(clause, range, emptyFilter);
       
         assert rows.size() == 1 : StringUtils.join(rows, ",");
-        assert Arrays.equals("k3".getBytes(), rows.get(0).key.key.array());
+        key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k3".equals( key );
+    
         assert rows.get(0).cf.getColumnCount() == 0;
 
         // query with index hit but rejected by secondary clause, with a small enough count that just checking count
         // doesn't tell the scan loop that it's done
-        IndexExpression expr3 = new IndexExpression(ByteBuffer.wrap("notbirthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(-1L));
+        IndexExpression expr3 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"), IndexOperator.EQ, FBUtilities.toByteBuffer(-1L));
         clause = new IndexClause(Arrays.asList(expr, expr3), FBUtilities.EMPTY_BYTE_BUFFER, 1);
         rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").scan(clause, range, filter);
 
@@ -204,43 +215,45 @@ public class ColumnFamilyStoreTest exten
         ColumnFamilyStore cfs = Table.open("Keyspace3").getColumnFamilyStore("Indexed1");
         RowMutation rm;
 
-        rm = new RowMutation("Keyspace3", ByteBuffer.wrap("k1".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 0);
+        rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(1L), 0);
         rm.apply();
 
-        IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L));
+        IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, FBUtilities.toByteBuffer(1L));
         IndexClause clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100);
         IFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
         Range range = new Range(p.getMinimumToken(), p.getMinimumToken());
         List<Row> rows = cfs.scan(clause, range, filter);
         assert rows.size() == 1 : StringUtils.join(rows, ",");
-        assert Arrays.equals("k1".getBytes(), rows.get(0).key.key.array());
-
+        String key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k1".equals( key );
+    
         // delete the column directly
-        rm = new RowMutation("Keyspace3", ByteBuffer.wrap("k1".getBytes()));
-        rm.delete(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), 1);
+        rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1"));
+        rm.delete(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), 1);
         rm.apply();
         rows = cfs.scan(clause, range, filter);
         assert rows.isEmpty();
 
         // verify that it's not being indexed under the deletion column value either
         IColumn deletion = rm.getColumnFamilies().iterator().next().iterator().next();
-        IndexExpression expr0 = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, deletion.value());
+        IndexExpression expr0 = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, deletion.value());
         IndexClause clause0 = new IndexClause(Arrays.asList(expr0), FBUtilities.EMPTY_BYTE_BUFFER, 100);
         rows = cfs.scan(clause0, range, filter);
         assert rows.isEmpty();
 
         // resurrect w/ a newer timestamp
-        rm = new RowMutation("Keyspace3", ByteBuffer.wrap("k1".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 2);
+        rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(1L), 2);
         rm.apply();
         rows = cfs.scan(clause, range, filter);
         assert rows.size() == 1 : StringUtils.join(rows, ",");
-        assert Arrays.equals("k1".getBytes(), rows.get(0).key.key.array());
+        key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k1".equals( key );  
 
         // delete the entire row
-        rm = new RowMutation("Keyspace3", ByteBuffer.wrap("k1".getBytes()));
+        rm = new RowMutation("Keyspace3", ByteBufferUtil.bytes("k1"));
         rm.delete(new QueryPath("Indexed1"), 3);
         rm.apply();
         rows = cfs.scan(clause, range, filter);
@@ -254,14 +267,14 @@ public class ColumnFamilyStoreTest exten
 
         // create a row and update the birthdate value, test that the index query fetches the new version
         RowMutation rm;
-        rm = new RowMutation("Keyspace2", ByteBuffer.wrap("k1".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 1);
+        rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("k1"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(1L), 1);
         rm.apply();
-        rm = new RowMutation("Keyspace2", ByteBuffer.wrap("k1".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(2L), 2);
+        rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("k1"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(2L), 2);
         rm.apply();
 
-        IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L));
+        IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, FBUtilities.toByteBuffer(1L));
         IndexClause clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100);
         IFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
@@ -269,18 +282,21 @@ public class ColumnFamilyStoreTest exten
         List<Row> rows = table.getColumnFamilyStore("Indexed1").scan(clause, range, filter);
         assert rows.size() == 0;
 
-        expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(2L));
+        expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, FBUtilities.toByteBuffer(2L));
         clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100);
         rows = table.getColumnFamilyStore("Indexed1").scan(clause, range, filter);
-        assert Arrays.equals("k1".getBytes(), rows.get(0).key.key.array());
-
+        String key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k1".equals( key );
+        
         // update the birthdate value with an OLDER timestamp, and test that the index ignores this
-        rm = new RowMutation("Keyspace2", ByteBuffer.wrap("k1".getBytes()));
-        rm.add(new QueryPath("Indexed1", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(3L), 0);
+        rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("k1"));
+        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(3L), 0);
         rm.apply();
 
         rows = table.getColumnFamilyStore("Indexed1").scan(clause, range, filter);
-        assert Arrays.equals("k1".getBytes(), rows.get(0).key.key.array());
+        key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k1".equals( key );
+    
     }
 
     @Test
@@ -290,38 +306,39 @@ public class ColumnFamilyStoreTest exten
 
         // create a row and update the birthdate value, test that the index query fetches the new version
         RowMutation rm;
-        rm = new RowMutation("Keyspace1", ByteBuffer.wrap("k1".getBytes()));
-        rm.add(new QueryPath("Indexed2", null, ByteBuffer.wrap("birthdate".getBytes("UTF8"))), FBUtilities.toByteBuffer(1L), 1);
+        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k1"));
+        rm.add(new QueryPath("Indexed2", null, ByteBufferUtil.bytes("birthdate")), FBUtilities.toByteBuffer(1L), 1);
         rm.apply();
 
         ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed2");
-        ColumnDefinition old = cfs.metadata.column_metadata.get(ByteBuffer.wrap("birthdate".getBytes("UTF8")));
+        ColumnDefinition old = cfs.metadata.column_metadata.get(ByteBufferUtil.bytes("birthdate"));
         ColumnDefinition cd = new ColumnDefinition(old.name, old.validator.getClass().getName(), IndexType.KEYS, "birthdate_index");
         cfs.addIndex(cd);
-        while (!SystemTable.isIndexBuilt("Keyspace1", cfs.getIndexedColumnFamilyStore(ByteBuffer.wrap("birthdate".getBytes("UTF8"))).columnFamily))
+        while (!SystemTable.isIndexBuilt("Keyspace1", cfs.getIndexedColumnFamilyStore(ByteBufferUtil.bytes("birthdate")).columnFamily))
             TimeUnit.MILLISECONDS.sleep(100);
 
-        IndexExpression expr = new IndexExpression(ByteBuffer.wrap("birthdate".getBytes("UTF8")), IndexOperator.EQ, FBUtilities.toByteBuffer(1L));
+        IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, FBUtilities.toByteBuffer(1L));
         IndexClause clause = new IndexClause(Arrays.asList(expr), FBUtilities.EMPTY_BYTE_BUFFER, 100);
         IFilter filter = new IdentityQueryFilter();
         IPartitioner p = StorageService.getPartitioner();
         Range range = new Range(p.getMinimumToken(), p.getMinimumToken());
         List<Row> rows = table.getColumnFamilyStore("Indexed2").scan(clause, range, filter);
         assert rows.size() == 1 : StringUtils.join(rows, ",");
-        assert Arrays.equals("k1".getBytes(), rows.get(0).key.key.array());
+        String key = new String(rows.get(0).key.key.array(),rows.get(0).key.key.position(),rows.get(0).key.key.remaining()); 
+        assert "k1".equals( key );        
     }
 
     private ColumnFamilyStore insertKey1Key2() throws IOException, ExecutionException, InterruptedException
     {
         List<RowMutation> rms = new LinkedList<RowMutation>();
         RowMutation rm;
-        rm = new RowMutation("Keyspace2", ByteBuffer.wrap("key1".getBytes()));
-        rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap("Column1".getBytes())), ByteBuffer.wrap("asdf".getBytes()), 0);
+        rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("key1"));
+        rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0);
         rms.add(rm);
         Util.writeColumnFamily(rms);
 
-        rm = new RowMutation("Keyspace2", ByteBuffer.wrap("key2".getBytes()));
-        rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap("Column1".getBytes())), ByteBuffer.wrap("asdf".getBytes()), 0);
+        rm = new RowMutation("Keyspace2", ByteBufferUtil.bytes("key2"));
+        rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("Column1")), ByteBufferUtil.bytes("asdf"), 0);
         rms.add(rm);
         return Util.writeColumnFamily(rms);
     }

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/ColumnFamilyTest.java Tue Oct 26 03:14:08 2010
@@ -31,6 +31,8 @@ import org.junit.Test;
 import org.apache.cassandra.io.util.DataOutputBuffer;
 import org.apache.cassandra.db.filter.QueryPath;
 import static org.apache.cassandra.Util.column;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 
 public class ColumnFamilyTest extends SchemaLoader
 {
@@ -78,7 +80,8 @@ public class ColumnFamilyTest extends Sc
         cf = ColumnFamily.serializer().deserialize(new DataInputStream(bufIn));
         for (String cName : map.navigableKeySet())
         {
-            assert new String(cf.getColumn(ByteBuffer.wrap(cName.getBytes())).value().array()).equals(map.get(cName));
+            ByteBuffer val = cf.getColumn(ByteBuffer.wrap(cName.getBytes())).value();
+            assert new String(val.array(),val.position(),val.remaining()).equals(map.get(cName));
         }
         assert cf.getColumnNames().size() == map.size();
     }
@@ -105,7 +108,7 @@ public class ColumnFamilyTest extends Sc
         cf.addColumn(column("col1", "val2", 2)); // same timestamp, new value
         cf.addColumn(column("col1", "val3", 1)); // older timestamp -- should be ignored
 
-        assert Arrays.equals("val2".getBytes(), cf.getColumn(ByteBuffer.wrap("col1".getBytes())).value().array());
+        assert ByteBufferUtil.bytes("val2").equals(cf.getColumn(ByteBufferUtil.bytes("col1")).value());
     }
 
     @Test
@@ -114,33 +117,33 @@ public class ColumnFamilyTest extends Sc
         ColumnFamily cf_new = ColumnFamily.create("Keyspace1", "Standard1");
         ColumnFamily cf_old = ColumnFamily.create("Keyspace1", "Standard1");
         ColumnFamily cf_result = ColumnFamily.create("Keyspace1", "Standard1");
-        ByteBuffer val = ByteBuffer.wrap("sample value".getBytes());
-        ByteBuffer val2 = ByteBuffer.wrap("x value ".getBytes());
+        ByteBuffer val = ByteBufferUtil.bytes("sample value");
+        ByteBuffer val2 = ByteBufferUtil.bytes("x value ");
 
         // exercise addColumn(QueryPath, ...)
-        cf_new.addColumn(QueryPath.column(ByteBuffer.wrap("col1".getBytes())), val, 3);
-        cf_new.addColumn(QueryPath.column(ByteBuffer.wrap("col2".getBytes())), val, 4);
+        cf_new.addColumn(QueryPath.column(ByteBufferUtil.bytes("col1")), val, 3);
+        cf_new.addColumn(QueryPath.column(ByteBufferUtil.bytes("col2")), val, 4);
 
-        cf_old.addColumn(QueryPath.column(ByteBuffer.wrap("col2".getBytes())), val2, 1);
-        cf_old.addColumn(QueryPath.column(ByteBuffer.wrap("col3".getBytes())), val2, 2);
+        cf_old.addColumn(QueryPath.column(ByteBufferUtil.bytes("col2")), val2, 1);
+        cf_old.addColumn(QueryPath.column(ByteBufferUtil.bytes("col3")), val2, 2);
 
         cf_result.addAll(cf_new);
         cf_result.addAll(cf_old);
 
         assert 3 == cf_result.getColumnCount() : "Count is " + cf_new.getColumnCount();
         //addcolumns will only add if timestamp >= old timestamp
-        assert val.equals(cf_result.getColumn(ByteBuffer.wrap("col2".getBytes())).value());
+        assert val.equals(cf_result.getColumn(ByteBufferUtil.bytes("col2")).value());
 
         // check that tombstone wins timestamp ties
-        cf_result.addTombstone(ByteBuffer.wrap("col1".getBytes()), 0, 3);
-        assert cf_result.getColumn(ByteBuffer.wrap("col1".getBytes())).isMarkedForDelete();
-        cf_result.addColumn(QueryPath.column(ByteBuffer.wrap("col1".getBytes())), val2, 3);
-        assert cf_result.getColumn(ByteBuffer.wrap("col1".getBytes())).isMarkedForDelete();
+        cf_result.addTombstone(ByteBufferUtil.bytes("col1"), 0, 3);
+        assert cf_result.getColumn(ByteBufferUtil.bytes("col1")).isMarkedForDelete();
+        cf_result.addColumn(QueryPath.column(ByteBufferUtil.bytes("col1")), val2, 3);
+        assert cf_result.getColumn(ByteBufferUtil.bytes("col1")).isMarkedForDelete();
 
         // check that column value wins timestamp ties in absence of tombstone
-        cf_result.addColumn(QueryPath.column(ByteBuffer.wrap("col3".getBytes())), val, 2);
-        assert cf_result.getColumn(ByteBuffer.wrap("col3".getBytes())).value().equals(val2);
-        cf_result.addColumn(QueryPath.column(ByteBuffer.wrap("col3".getBytes())), ByteBuffer.wrap("z".getBytes()), 2);
-        assert cf_result.getColumn(ByteBuffer.wrap("col3".getBytes())).value().equals(ByteBuffer.wrap("z".getBytes()));
+        cf_result.addColumn(QueryPath.column(ByteBufferUtil.bytes("col3")), val, 2);
+        assert cf_result.getColumn(ByteBufferUtil.bytes("col3")).value().equals(val2);
+        cf_result.addColumn(QueryPath.column(ByteBufferUtil.bytes("col3")), ByteBufferUtil.bytes("z"), 2);
+        assert cf_result.getColumn(ByteBufferUtil.bytes("col3")).value().equals(ByteBufferUtil.bytes("z"));
     }
 }

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java Tue Oct 26 03:14:08 2010
@@ -35,6 +35,8 @@ import org.apache.cassandra.Util;
 
 import static junit.framework.Assert.assertEquals;
 import static org.apache.cassandra.db.TableTest.assertColumns;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 
 public class CompactionsPurgeTest extends CleanupHelper
 {
@@ -209,18 +211,18 @@ public class CompactionsPurgeTest extend
 
         // inserts
         rm = new RowMutation(TABLE1, key1.key);
-        rm.add(new QueryPath(cfName, null, ByteBuffer.wrap("1".getBytes())), FBUtilities.EMPTY_BYTE_BUFFER, 0);
+        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("1")), FBUtilities.EMPTY_BYTE_BUFFER, 0);
         rm.apply();
         rm = new RowMutation(TABLE1, key2.key);
-        rm.add(new QueryPath(cfName, null, ByteBuffer.wrap("2".getBytes())), FBUtilities.EMPTY_BYTE_BUFFER, 0);
+        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("2")), FBUtilities.EMPTY_BYTE_BUFFER, 0);
         rm.apply();
 
         // deletes
         rm = new RowMutation(TABLE1, key1.key);
-        rm.delete(new QueryPath(cfName, null, ByteBuffer.wrap("1".getBytes())), 1);
+        rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes("1")), 1);
         rm.apply();
         rm = new RowMutation(TABLE1, key2.key);
-        rm.delete(new QueryPath(cfName, null, ByteBuffer.wrap("2".getBytes())), 1);
+        rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes("2")), 1);
         rm.apply();
 
         // After a flush, the cache should expand to be X% of indices * INDEX_INTERVAL.

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/DefsTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/DefsTest.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/DefsTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/DefsTest.java Tue Oct 26 03:14:08 2010
@@ -18,29 +18,50 @@
 
 package org.apache.cassandra.db;
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.File;
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 
-import org.apache.cassandra.io.SerDeUtils;
-import org.apache.cassandra.locator.OldNetworkTopologyStrategy;
-import org.apache.cassandra.thrift.CfDef;
-import org.apache.cassandra.thrift.ColumnDef;
-import org.junit.Test;
-
 import org.apache.cassandra.CleanupHelper;
 import org.apache.cassandra.Util;
-import org.apache.cassandra.config.*;
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.ColumnDefinition;
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.config.KSMetaData;
 import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.db.marshal.BytesType;
 import org.apache.cassandra.db.marshal.UTF8Type;
-import org.apache.cassandra.db.migration.*;
+import org.apache.cassandra.db.migration.AddColumnFamily;
+import org.apache.cassandra.db.migration.AddKeyspace;
+import org.apache.cassandra.db.migration.DropColumnFamily;
+import org.apache.cassandra.db.migration.DropKeyspace;
+import org.apache.cassandra.db.migration.Migration;
+import org.apache.cassandra.db.migration.RenameColumnFamily;
+import org.apache.cassandra.db.migration.RenameKeyspace;
+import org.apache.cassandra.db.migration.UpdateColumnFamily;
+import org.apache.cassandra.db.migration.UpdateKeyspace;
+import org.apache.cassandra.locator.OldNetworkTopologyStrategy;
 import org.apache.cassandra.locator.SimpleStrategy;
+import org.apache.cassandra.thrift.CfDef;
+import org.apache.cassandra.thrift.ColumnDef;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
+import org.junit.Test;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 
 public class DefsTest extends CleanupHelper
 {   
@@ -172,16 +193,16 @@ public class DefsTest extends CleanupHel
         // now read and write to it.
         DecoratedKey dk = Util.dk("key0");
         RowMutation rm = new RowMutation(ks, dk.key);
-        rm.add(new QueryPath(cf, null, ByteBuffer.wrap("col0".getBytes())), ByteBuffer.wrap("value0".getBytes()), 1L);
+        rm.add(new QueryPath(cf, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
         rm.apply();
         ColumnFamilyStore store = Table.open(ks).getColumnFamilyStore(cf);
         assert store != null;
         store.forceBlockingFlush();
         
-        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cf), ByteBuffer.wrap("col0".getBytes())));
-        assert cfam.getColumn(ByteBuffer.wrap("col0".getBytes())) != null;
-        IColumn col = cfam.getColumn(ByteBuffer.wrap("col0".getBytes()));
-        assert ByteBuffer.wrap("value0".getBytes()).equals(col.value());
+        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cf), ByteBufferUtil.bytes("col0")));
+        assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
+        IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
+        assert ByteBufferUtil.bytes("value0").equals(col.value());
     }
 
     @Test
@@ -197,7 +218,7 @@ public class DefsTest extends CleanupHel
         // write some data, force a flush, then verify that files exist on disk.
         RowMutation rm = new RowMutation(ks.name, dk.key);
         for (int i = 0; i < 100; i++)
-            rm.add(new QueryPath(cfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBuffer.wrap("anyvalue".getBytes()), 1L);
+            rm.add(new QueryPath(cfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBufferUtil.bytes("anyvalue"), 1L);
         rm.apply();
         ColumnFamilyStore store = Table.open(cfm.tableName).getColumnFamilyStore(cfm.cfName);
         assert store != null;
@@ -214,7 +235,7 @@ public class DefsTest extends CleanupHel
         boolean success = true;
         try
         {
-            rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap("col0".getBytes())), ByteBuffer.wrap("value0".getBytes()), 1L);
+            rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
             rm.apply();
         }
         catch (Throwable th)
@@ -243,7 +264,7 @@ public class DefsTest extends CleanupHel
         // write some data, force a flush, then verify that files exist on disk.
         RowMutation rm = new RowMutation(ks.name, dk.key);
         for (int i = 0; i < 100; i++)
-            rm.add(new QueryPath(oldCfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBuffer.wrap("anyvalue".getBytes()), 1L);
+            rm.add(new QueryPath(oldCfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBufferUtil.bytes("anyvalue"), 1L);
         rm.apply();
         ColumnFamilyStore store = Table.open(oldCfm.tableName).getColumnFamilyStore(oldCfm.cfName);
         assert store != null;
@@ -268,13 +289,13 @@ public class DefsTest extends CleanupHel
         
         // do some writes
         rm = new RowMutation(ks.name, dk.key);
-        rm.add(new QueryPath(cfName, null, ByteBuffer.wrap("col5".getBytes())), ByteBuffer.wrap("updated".getBytes()), 2L);
+        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("col5")), ByteBufferUtil.bytes("updated"), 2L);
         rm.apply();
         store.forceBlockingFlush();
         
-        cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cfName), ByteBuffer.wrap("col5".getBytes())));
+        cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cfName), ByteBufferUtil.bytes("col5")));
         assert cfam.getColumnCount() == 1;
-        assert cfam.getColumn(ByteBuffer.wrap("col5".getBytes())).value().equals( ByteBuffer.wrap("updated".getBytes()));
+        assert cfam.getColumn(ByteBufferUtil.bytes("col5")).value().equals( ByteBufferUtil.bytes("updated"));
     }
     
     @Test
@@ -292,16 +313,16 @@ public class DefsTest extends CleanupHel
 
         // test reads and writes.
         RowMutation rm = new RowMutation(newCf.tableName, dk.key);
-        rm.add(new QueryPath(newCf.cfName, null, ByteBuffer.wrap("col0".getBytes())), ByteBuffer.wrap("value0".getBytes()), 1L);
+        rm.add(new QueryPath(newCf.cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
         rm.apply();
         ColumnFamilyStore store = Table.open(newCf.tableName).getColumnFamilyStore(newCf.cfName);
         assert store != null;
         store.forceBlockingFlush();
         
-        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), ByteBuffer.wrap("col0".getBytes())));
-        assert cfam.getColumn(ByteBuffer.wrap("col0".getBytes())) != null;
-        IColumn col = cfam.getColumn(ByteBuffer.wrap("col0".getBytes()));
-        assert ByteBuffer.wrap("value0".getBytes()).equals(col.value());
+        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), ByteBufferUtil.bytes("col0")));
+        assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
+        IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
+        assert ByteBufferUtil.bytes("value0").equals(col.value());
     }
     
     @Test
@@ -317,7 +338,7 @@ public class DefsTest extends CleanupHel
         // write some data, force a flush, then verify that files exist on disk.
         RowMutation rm = new RowMutation(ks.name, dk.key);
         for (int i = 0; i < 100; i++)
-            rm.add(new QueryPath(cfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBuffer.wrap("anyvalue".getBytes()), 1L);
+            rm.add(new QueryPath(cfm.cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBufferUtil.bytes("anyvalue"), 1L);
         rm.apply();
         ColumnFamilyStore store = Table.open(cfm.tableName).getColumnFamilyStore(cfm.cfName);
         assert store != null;
@@ -333,7 +354,7 @@ public class DefsTest extends CleanupHel
         boolean success = true;
         try
         {
-            rm.add(new QueryPath("Standard1", null, ByteBuffer.wrap("col0".getBytes())), ByteBuffer.wrap("value0".getBytes()), 1L);
+            rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
             rm.apply();
         }
         catch (Throwable th)
@@ -367,7 +388,7 @@ public class DefsTest extends CleanupHel
         // write some data that we hope to read back later.
         RowMutation rm = new RowMutation(oldKs.name, dk.key);
         for (int i = 0; i < 10; i++)
-            rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBuffer.wrap("value".getBytes()), 1L);
+            rm.add(new QueryPath(cfName, null, ByteBuffer.wrap(("col" + i).getBytes())), ByteBufferUtil.bytes("value"), 1L);
         rm.apply();
         ColumnFamilyStore store = Table.open(oldKs.name).getColumnFamilyStore(cfName);
         assert store != null;
@@ -396,11 +417,11 @@ public class DefsTest extends CleanupHel
         }
         
         // write on old should fail.
-        rm = new RowMutation(oldKs.name, ByteBuffer.wrap("any key will do".getBytes()));
+        rm = new RowMutation(oldKs.name, ByteBufferUtil.bytes("any key will do"));
         boolean success = true;
         try
         {
-            rm.add(new QueryPath(cfName, null, ByteBuffer.wrap("col0".getBytes())), ByteBuffer.wrap("value0".getBytes()), 1L);
+            rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
             rm.apply();
         }
         catch (Throwable th)
@@ -411,7 +432,7 @@ public class DefsTest extends CleanupHel
         
         // write on new should work.
         rm = new RowMutation(newKsName, dk.key);
-        rm.add(new QueryPath(cfName, null, ByteBuffer.wrap("col0".getBytes())), ByteBuffer.wrap("newvalue".getBytes()), 2L);
+        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("newvalue"), 2L);
         rm.apply();
         store = Table.open(newKs.name).getColumnFamilyStore(cfName);
         assert store != null;
@@ -419,14 +440,17 @@ public class DefsTest extends CleanupHel
         
         // read on new should work.
         SortedSet<ByteBuffer> cols = new TreeSet<ByteBuffer>(BytesType.instance);
-        cols.add(ByteBuffer.wrap("col0".getBytes()));
-        cols.add(ByteBuffer.wrap("col1".getBytes()));
+        cols.add(ByteBufferUtil.bytes("col0"));
+        cols.add(ByteBufferUtil.bytes("col1"));
         ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cfName), cols));
         assert cfam.getColumnCount() == cols.size();
         // tests new write.
-        assert Arrays.equals(cfam.getColumn(ByteBuffer.wrap("col0".getBytes())).value().array(), "newvalue".getBytes());
+        
+        ByteBuffer val = cfam.getColumn(ByteBufferUtil.bytes("col0")).value();
+        assertEquals( new String(val.array(),val.position(),val.remaining()), "newvalue");
         // tests old write.
-        assert Arrays.equals(cfam.getColumn(ByteBuffer.wrap("col1".getBytes())).value().array(), "value".getBytes());
+         val = cfam.getColumn(ByteBufferUtil.bytes("col1")).value();
+        assertEquals( new String(val.array(),val.position(),val.remaining()), "value");
     }
 
     @Test
@@ -453,16 +477,16 @@ public class DefsTest extends CleanupHel
         // now read and write to it.
         DecoratedKey dk = Util.dk("key0");
         RowMutation rm = new RowMutation(newKs.name, dk.key);
-        rm.add(new QueryPath(newCf.cfName, null, ByteBuffer.wrap("col0".getBytes())), ByteBuffer.wrap("value0".getBytes()), 1L);
+        rm.add(new QueryPath(newCf.cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
         rm.apply();
         ColumnFamilyStore store = Table.open(newKs.name).getColumnFamilyStore(newCf.cfName);
         assert store != null;
         store.forceBlockingFlush();
 
-        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), ByteBuffer.wrap("col0".getBytes())));
-        assert cfam.getColumn(ByteBuffer.wrap("col0".getBytes())) != null;
-        IColumn col = cfam.getColumn(ByteBuffer.wrap("col0".getBytes()));
-        assert ByteBuffer.wrap("value0".getBytes()).equals(col.value());
+        ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), ByteBufferUtil.bytes("col0")));
+        assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
+        IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
+        assert ByteBufferUtil.bytes("value0").equals(col.value());
     }
     
     @Test

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/NameSortTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/NameSortTest.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/NameSortTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/NameSortTest.java Tue Oct 26 03:14:08 2010
@@ -1,40 +1,35 @@
 /*
-* 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.
-*/
+ * 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;
 
+import static junit.framework.Assert.assertEquals;
+import static org.apache.cassandra.Util.addMutation;
+
 import java.io.IOException;
-import java.util.concurrent.ExecutionException;
-import java.util.Collection;
-import java.util.Arrays;
 import java.nio.ByteBuffer;
-
-import org.apache.cassandra.Util;
-import org.junit.Test;
+import java.util.Collection;
+import java.util.concurrent.ExecutionException;
 
 import org.apache.cassandra.CleanupHelper;
 import org.apache.cassandra.Util;
-import static org.apache.cassandra.Util.addMutation;
-
 import org.apache.cassandra.db.filter.QueryPath;
-import org.apache.cassandra.utils.ByteBufferUtil;
-
-import static junit.framework.Assert.assertEquals;
+import org.junit.Test;
 
 public class NameSortTest extends CleanupHelper
 {
@@ -59,7 +54,6 @@ public class NameSortTest extends Cleanu
         testNameSort(100);
     }
 
-
     private void testNameSort(int N) throws IOException, ExecutionException, InterruptedException
     {
         Table table = Table.open("Keyspace1");
@@ -109,9 +103,10 @@ public class NameSortTest extends Cleanu
             Collection<IColumn> columns = cf.getSortedColumns();
             for (IColumn column : columns)
             {
-                int j = Integer.valueOf(new String(column.name().array()).split("-")[1]);
+                int j = Integer.valueOf(new String(column.name().array(),column.name().position(),column.name().remaining()).split("-")[1]);
                 byte[] bytes = j % 2 == 0 ? "a".getBytes() : "b".getBytes();
-                assert Arrays.equals(bytes, column.value().array());
+                assertEquals(new String(bytes), new String(column.value().array(), column.value().position(), column
+                        .value().remaining()));
             }
 
             cf = Util.getColumnFamily(table, key, "Super1");
@@ -120,14 +115,15 @@ public class NameSortTest extends Cleanu
             assert superColumns.size() == 8 : cf;
             for (IColumn superColumn : superColumns)
             {
-                int j = Integer.valueOf(new String(superColumn.name().array()).split("-")[1]);
+                int j = Integer.valueOf(new String(superColumn.name().array(),superColumn.name().position(),superColumn.name().remaining()).split("-")[1]);
                 Collection<IColumn> subColumns = superColumn.getSubColumns();
                 assert subColumns.size() == 4;
                 for (IColumn subColumn : subColumns)
                 {
-                    long k = subColumn.name().getLong(subColumn.name().position()+subColumn.name().arrayOffset());                   
+                    long k = subColumn.name().getLong(subColumn.name().position() + subColumn.name().arrayOffset());
                     byte[] bytes = (j + k) % 2 == 0 ? "a".getBytes() : "b".getBytes();
-                    assert Arrays.equals(bytes, subColumn.value().array());
+                    assertEquals(new String(bytes), new String(subColumn.value().array(), subColumn.value().position(),
+                            subColumn.value().remaining()));
                 }
             }
         }

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/OneCompactionTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/OneCompactionTest.java?rev=1027349&r1=1027348&r2=1027349&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/OneCompactionTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/OneCompactionTest.java Tue Oct 26 03:14:08 2010
@@ -32,6 +32,8 @@ import static junit.framework.Assert.ass
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.CleanupHelper;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 
 public class OneCompactionTest extends CleanupHelper
 {
@@ -46,7 +48,7 @@ public class OneCompactionTest extends C
         for (int j = 0; j < insertsPerTable; j++) {
             DecoratedKey key = Util.dk(String.valueOf(j));
             RowMutation rm = new RowMutation("Keyspace1", key.key);
-            rm.add(new QueryPath(columnFamilyName, null, ByteBuffer.wrap("0".getBytes())), FBUtilities.EMPTY_BYTE_BUFFER, j);
+            rm.add(new QueryPath(columnFamilyName, null, ByteBufferUtil.bytes("0")), FBUtilities.EMPTY_BYTE_BUFFER, j);
             rm.apply();
             inserted.add(key);
             store.forceBlockingFlush();



Mime
View raw message