Modified: cassandra/trunk/test/unit/org/apache/cassandra/tools/SSTableExportTest.java URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/tools/SSTableExportTest.java?rev=1026200&r1=1026199&r2=1026200&view=diff ============================================================================== --- cassandra/trunk/test/unit/org/apache/cassandra/tools/SSTableExportTest.java (original) +++ cassandra/trunk/test/unit/org/apache/cassandra/tools/SSTableExportTest.java Fri Oct 22 03:23:26 2010 @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintStream; +import java.nio.ByteBuffer; import java.util.Arrays; import org.apache.cassandra.SchemaLoader; @@ -51,7 +52,7 @@ public class SSTableExportTest extends S { public String asHex(String str) { - return bytesToHex(str.getBytes()); + return bytesToHex(ByteBuffer.wrap(str.getBytes())); } @Test @@ -62,12 +63,12 @@ public class SSTableExportTest extends S SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(new QueryPath("Standard1", null, "colA".getBytes()), "valA".getBytes(), 1); + cfamily.addColumn(new QueryPath("Standard1", null, ByteBuffer.wrap("colA".getBytes())), ByteBuffer.wrap("valA".getBytes()), 1); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); // Add rowB - cfamily.addColumn(new QueryPath("Standard1", null, "colB".getBytes()), "valB".getBytes(), 1); + cfamily.addColumn(new QueryPath("Standard1", null, ByteBuffer.wrap("colB".getBytes())), ByteBuffer.wrap("valB".getBytes()), 1); writer.append(Util.dk("rowB"), cfamily); cfamily.clear(); @@ -94,17 +95,17 @@ public class SSTableExportTest extends S SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(new QueryPath("Standard1", null, "colA".getBytes()), "valA".getBytes(), 1); + cfamily.addColumn(new QueryPath("Standard1", null, ByteBuffer.wrap("colA".getBytes())), ByteBuffer.wrap("valA".getBytes()), 1); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); // Add rowB - cfamily.addColumn(new QueryPath("Standard1", null, "colB".getBytes()), "valB".getBytes(), 1); + cfamily.addColumn(new QueryPath("Standard1", null, ByteBuffer.wrap("colB".getBytes())), ByteBuffer.wrap("valB".getBytes()), 1); writer.append(Util.dk("rowB"), cfamily); cfamily.clear(); // Add rowExclude - cfamily.addColumn(new QueryPath("Standard1", null, "colX".getBytes()), "valX".getBytes(), 1); + cfamily.addColumn(new QueryPath("Standard1", null, ByteBuffer.wrap("colX".getBytes())), ByteBuffer.wrap("valX".getBytes()), 1); writer.append(Util.dk("rowExclude"), cfamily); cfamily.clear(); @@ -136,17 +137,17 @@ public class SSTableExportTest extends S SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(new QueryPath("Super4", "superA".getBytes(), "colA".getBytes()), "valA".getBytes(), 1); + cfamily.addColumn(new QueryPath("Super4", ByteBuffer.wrap("superA".getBytes()), ByteBuffer.wrap("colA".getBytes())), ByteBuffer.wrap("valA".getBytes()), 1); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); // Add rowB - cfamily.addColumn(new QueryPath("Super4", "superB".getBytes(), "colB".getBytes()), "valB".getBytes(), 1); + cfamily.addColumn(new QueryPath("Super4", ByteBuffer.wrap("superB".getBytes()), ByteBuffer.wrap("colB".getBytes())), ByteBuffer.wrap("valB".getBytes()), 1); writer.append(Util.dk("rowB"), cfamily); cfamily.clear(); // Add rowExclude - cfamily.addColumn(new QueryPath("Super4", "superX".getBytes(), "colX".getBytes()), "valX".getBytes(), 1); + cfamily.addColumn(new QueryPath("Super4", ByteBuffer.wrap("superX".getBytes()), ByteBuffer.wrap("colX".getBytes())), ByteBuffer.wrap("valX".getBytes()), 1); writer.append(Util.dk("rowExclude"), cfamily); cfamily.clear(); @@ -159,7 +160,7 @@ public class SSTableExportTest extends S JSONObject json = (JSONObject)JSONValue.parse(new FileReader(tempJson)); JSONObject rowA = (JSONObject)json.get(asHex("rowA")); - JSONObject superA = (JSONObject)rowA.get(cfamily.getComparator().getString("superA".getBytes())); + JSONObject superA = (JSONObject)rowA.get(cfamily.getComparator().getString(ByteBuffer.wrap("superA".getBytes()))); JSONArray subColumns = (JSONArray)superA.get("subColumns"); JSONArray colA = (JSONArray)subColumns.get(0); JSONObject rowExclude = (JSONObject)json.get(asHex("rowExclude")); @@ -176,12 +177,12 @@ public class SSTableExportTest extends S SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2); // Add rowA - cfamily.addColumn(new QueryPath("Standard1", null, "name".getBytes()), "val".getBytes(), 1); + cfamily.addColumn(new QueryPath("Standard1", null, ByteBuffer.wrap("name".getBytes())), ByteBuffer.wrap("val".getBytes()), 1); writer.append(Util.dk("rowA"), cfamily); cfamily.clear(); // Add rowExclude - cfamily.addColumn(new QueryPath("Standard1", null, "name".getBytes()), "val".getBytes(), 1); + cfamily.addColumn(new QueryPath("Standard1", null, ByteBuffer.wrap("name".getBytes())), ByteBuffer.wrap("val".getBytes()), 1); writer.append(Util.dk("rowExclude"), cfamily); cfamily.clear(); @@ -196,12 +197,12 @@ public class SSTableExportTest extends S SSTableImport.importJson(tempJson.getPath(), "Keyspace1", "Standard1", tempSS2.getPath()); reader = SSTableReader.open(Descriptor.fromFilename(tempSS2.getPath())); - QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Standard1", null, null), "name".getBytes()); + QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Standard1", null, null), ByteBuffer.wrap("name".getBytes())); ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily(); assertTrue(cf != null); - assertTrue(Arrays.equals(cf.getColumn("name".getBytes()).value(), hexToBytes("76616c"))); + assertTrue(cf.getColumn(ByteBuffer.wrap("name".getBytes())).value().equals(ByteBuffer.wrap(hexToBytes("76616c")))); - qf = QueryFilter.getNamesFilter(Util.dk("rowExclude"), new QueryPath("Standard1", null, null), "name".getBytes()); + qf = QueryFilter.getNamesFilter(Util.dk("rowExclude"), new QueryPath("Standard1", null, null), ByteBuffer.wrap("name".getBytes())); cf = qf.getSSTableColumnIterator(reader).getColumnFamily(); assert cf == null; }
Modified: cassandra/trunk/test/unit/org/apache/cassandra/tools/SSTableImportTest.java URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/tools/SSTableImportTest.java?rev=1026200&r1=1026199&r2=1026200&view=diff ============================================================================== --- cassandra/trunk/test/unit/org/apache/cassandra/tools/SSTableImportTest.java (original) +++ cassandra/trunk/test/unit/org/apache/cassandra/tools/SSTableImportTest.java Fri Oct 22 03:23:26 2010 @@ -20,6 +20,7 @@ package org.apache.cassandra.tools; import java.io.File; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.Arrays; import org.apache.cassandra.SchemaLoader; @@ -50,9 +51,9 @@ public class SSTableImportTest extends S // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); - QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Standard1", null, null), "colAA".getBytes()); + QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Standard1", null, null), ByteBuffer.wrap("colAA".getBytes())); ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily(); - assert Arrays.equals(cf.getColumn("colAA".getBytes()).value(), hexToBytes("76616c4141")); + assert cf.getColumn(ByteBuffer.wrap("colAA".getBytes())).value().equals(ByteBuffer.wrap(hexToBytes("76616c4141"))); } @Test @@ -64,9 +65,9 @@ public class SSTableImportTest extends S // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); - QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Super4", null, null), "superA".getBytes()); + QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Super4", null, null), ByteBuffer.wrap("superA".getBytes())); ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily(); - IColumn superCol = cf.getColumn("superA".getBytes()); - assert Arrays.equals(superCol.getSubColumn("colAA".getBytes()).value(), hexToBytes("76616c75654141")); + IColumn superCol = cf.getColumn(ByteBuffer.wrap("superA".getBytes())); + assert superCol.getSubColumn(ByteBuffer.wrap("colAA".getBytes())).value().equals(ByteBuffer.wrap(hexToBytes("76616c75654141"))); } } Modified: cassandra/trunk/test/unit/org/apache/cassandra/utils/BloomFilterTest.java URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/utils/BloomFilterTest.java?rev=1026200&r1=1026199&r2=1026200&view=diff ============================================================================== --- cassandra/trunk/test/unit/org/apache/cassandra/utils/BloomFilterTest.java (original) +++ cassandra/trunk/test/unit/org/apache/cassandra/utils/BloomFilterTest.java Fri Oct 22 03:23:26 2010 @@ -19,6 +19,7 @@ package org.apache.cassandra.utils; import java.io.IOException; +import java.nio.ByteBuffer; import org.junit.Before; import org.junit.Test; @@ -54,9 +55,9 @@ public class BloomFilterTest @Test public void testOne() { - bf.add("a".getBytes()); - assert bf.isPresent("a".getBytes()); - assert !bf.isPresent("b".getBytes()); + bf.add(ByteBuffer.wrap("a".getBytes())); + assert bf.isPresent(ByteBuffer.wrap("a".getBytes())); + assert !bf.isPresent(ByteBuffer.wrap("b".getBytes())); } @Test Modified: cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java?rev=1026200&r1=1026199&r2=1026200&view=diff ============================================================================== --- cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java (original) +++ cassandra/trunk/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java Fri Oct 22 03:23:26 2010 @@ -22,6 +22,7 @@ import static org.junit.Assert.assertArr import static org.junit.Assert.assertEquals; import java.io.IOException; +import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; import java.util.Arrays; @@ -35,7 +36,7 @@ public class FBUtilitiesTest for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { byte[] b = new byte[]{ (byte)i }; - String s = FBUtilities.bytesToHex(b); + String s = FBUtilities.bytesToHex(ByteBuffer.wrap(b)); byte[] c = FBUtilities.hexToBytes(s); assertArrayEquals(b, c); } @@ -78,7 +79,7 @@ public class FBUtilitiesTest }; for (int i : ints) { - byte[] ba = FBUtilities.toByteArray(i); + ByteBuffer ba = FBUtilities.toByteArray(i); int actual = FBUtilities.byteArrayToInt(ba); assertEquals(i, actual); } @@ -87,7 +88,7 @@ public class FBUtilitiesTest @Test(expected=CharacterCodingException.class) public void testDecode() throws IOException { - byte[] bytes = new byte[]{(byte)0xff, (byte)0xfe}; + ByteBuffer bytes = ByteBuffer.wrap(new byte[]{(byte)0xff, (byte)0xfe}); FBUtilities.decodeToUTF8(bytes); } } Modified: cassandra/trunk/test/unit/org/apache/cassandra/utils/FilterTest.java URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/utils/FilterTest.java?rev=1026200&r1=1026199&r2=1026200&view=diff ============================================================================== --- cassandra/trunk/test/unit/org/apache/cassandra/utils/FilterTest.java (original) +++ cassandra/trunk/test/unit/org/apache/cassandra/utils/FilterTest.java Fri Oct 22 03:23:26 2010 @@ -21,17 +21,17 @@ package org.apache.cassandra.utils; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import org.junit.Test; - import org.apache.cassandra.io.util.DataOutputBuffer; +import org.junit.Test; public class FilterTest { - public void testManyHashes(Iterator<byte[]> keys) + public void testManyHashes(Iterator<ByteBuffer> keys) { int MAX_HASH_COUNT = 128; Set<Integer> hashes = new HashSet<Integer>(); @@ -60,22 +60,22 @@ public class FilterTest public static final BloomCalculations.BloomSpecification spec = BloomCalculations.computeBloomSpec(15, MAX_FAILURE_RATE); static final int ELEMENTS = 10000; - static final ResetableIterator<byte[]> intKeys() + static final ResetableIterator<ByteBuffer> intKeys() { return new KeyGenerator.IntGenerator(ELEMENTS); } - static final ResetableIterator<byte[]> randomKeys() + static final ResetableIterator<ByteBuffer> randomKeys() { return new KeyGenerator.RandomStringGenerator(314159, ELEMENTS); } - static final ResetableIterator<byte[]> randomKeys2() + static final ResetableIterator<ByteBuffer> randomKeys2() { return new KeyGenerator.RandomStringGenerator(271828, ELEMENTS); } - public static void testFalsePositives(Filter f, ResetableIterator<byte[]> keys, ResetableIterator<byte[]> otherkeys) + public static void testFalsePositives(Filter f, ResetableIterator<ByteBuffer> keys, ResetableIterator<ByteBuffer> otherkeys) { assert keys.size() == otherkeys.size(); @@ -99,15 +99,15 @@ public class FilterTest public static Filter testSerialize(Filter f) throws IOException { - f.add("a".getBytes()); + f.add(ByteBuffer.wrap("a".getBytes())); DataOutputBuffer out = new DataOutputBuffer(); f.getSerializer().serialize(f, out); ByteArrayInputStream in = new ByteArrayInputStream(out.getData(), 0, out.getLength()); Filter f2 = f.getSerializer().deserialize(new DataInputStream(in)); - assert f2.isPresent("a".getBytes()); - assert !f2.isPresent("b".getBytes()); + assert f2.isPresent(ByteBuffer.wrap("a".getBytes())); + assert !f2.isPresent(ByteBuffer.wrap("b".getBytes())); return f2; } Modified: cassandra/trunk/test/unit/org/apache/cassandra/utils/KeyGenerator.java URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/utils/KeyGenerator.java?rev=1026200&r1=1026199&r2=1026200&view=diff ============================================================================== --- cassandra/trunk/test/unit/org/apache/cassandra/utils/KeyGenerator.java (original) +++ cassandra/trunk/test/unit/org/apache/cassandra/utils/KeyGenerator.java Fri Oct 22 03:23:26 2010 @@ -18,17 +18,22 @@ */ package org.apache.cassandra.utils; -import java.io.*; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.ByteBuffer; import java.util.Random; public class KeyGenerator { - private static byte[] randomKey(Random r) { + private static ByteBuffer randomKey(Random r) { byte[] bytes = new byte[48]; r.nextBytes(bytes); - return bytes; + return ByteBuffer.wrap(bytes); } - static class RandomStringGenerator implements ResetableIterator<byte[]> { + static class RandomStringGenerator implements ResetableIterator<ByteBuffer> { int i, n, seed; Random random; @@ -51,7 +56,7 @@ public class KeyGenerator { return i < n; } - public byte[] next() { + public ByteBuffer next() { i++; return randomKey(random); } @@ -61,7 +66,7 @@ public class KeyGenerator { } } - static class IntGenerator implements ResetableIterator<byte[]> { + static class IntGenerator implements ResetableIterator<ByteBuffer> { private int i, start, n; IntGenerator(int n) { @@ -86,8 +91,8 @@ public class KeyGenerator { return i < n; } - public byte[] next() { - return Integer.toString(i++).getBytes(); + public ByteBuffer next() { + return ByteBuffer.wrap(Integer.toString(i++).getBytes()); } public void remove() { @@ -95,7 +100,7 @@ public class KeyGenerator { } } - static class WordGenerator implements ResetableIterator<byte[]> { + static class WordGenerator implements ResetableIterator<ByteBuffer> { static int WORDS; static { @@ -145,14 +150,14 @@ public class KeyGenerator { return next != null; } - public byte[] next() { + public ByteBuffer next() { try { byte[] s = next; for (int i = 0; i < modulo; i++) { String line = reader.readLine(); next = line == null ? null : line.getBytes(); } - return s; + return s == null ? null : ByteBuffer.wrap(s); } catch (IOException e) { throw new RuntimeException(e); } Modified: cassandra/trunk/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java?rev=1026200&r1=1026199&r2=1026200&view=diff ============================================================================== --- cassandra/trunk/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java (original) +++ cassandra/trunk/test/unit/org/apache/cassandra/utils/MerkleTreeTest.java Fri Oct 22 03:23:26 2010 @@ -18,22 +18,42 @@ */ package org.apache.cassandra.utils; -import java.io.*; -import java.util.*; +import static org.apache.cassandra.utils.MerkleTree.RECOMMENDED_DEPTH; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.math.BigInteger; - -import org.apache.cassandra.dht.*; -import static org.apache.cassandra.utils.MerkleTree.*; - +import java.nio.ByteBuffer; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; + +import org.apache.cassandra.dht.BigIntegerToken; +import org.apache.cassandra.dht.IPartitioner; +import org.apache.cassandra.dht.RandomPartitioner; +import org.apache.cassandra.dht.Range; +import org.apache.cassandra.dht.Token; +import org.apache.cassandra.utils.MerkleTree.Hashable; +import org.apache.cassandra.utils.MerkleTree.RowHash; +import org.apache.cassandra.utils.MerkleTree.TreeRange; +import org.apache.cassandra.utils.MerkleTree.TreeRangeIterator; +import org.junit.Before; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.AbstractIterator; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - public class MerkleTreeTest { private static final Logger logger = LoggerFactory.getLogger(MerkleTreeTest.class); @@ -64,8 +84,8 @@ public class MerkleTreeTest public static void assertHashEquals(String message, final byte[] left, final byte[] right) { - String lstring = left == null ? "null" : FBUtilities.bytesToHex(left); - String rstring = right == null ? "null" : FBUtilities.bytesToHex(right); + String lstring = left == null ? "null" : FBUtilities.bytesToHex(ByteBuffer.wrap(left)); + String rstring = right == null ? "null" : FBUtilities.bytesToHex(ByteBuffer.wrap(right)); assertEquals(message, lstring, rstring); } Modified: cassandra/trunk/test/unit/org/apache/cassandra/utils/UUIDTests.java URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/utils/UUIDTests.java?rev=1026200&r1=1026199&r2=1026200&view=diff ============================================================================== --- cassandra/trunk/test/unit/org/apache/cassandra/utils/UUIDTests.java (original) +++ cassandra/trunk/test/unit/org/apache/cassandra/utils/UUIDTests.java Fri Oct 22 03:23:26 2010 @@ -27,6 +27,7 @@ import org.junit.Test; import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; +import java.nio.ByteBuffer; import java.util.UUID; @@ -54,7 +55,7 @@ public class UUIDTests { UUID a = UUIDGen.makeType1UUIDFromHost(InetAddress.getByName("127.0.0.1")); byte[] decomposed = UUIDGen.decompose(a); - UUID b = UUIDGen.makeType1UUID(decomposed); + UUID b = UUIDGen.makeType1UUID(ByteBuffer.wrap(decomposed)); assert a.equals(b); } @@ -62,11 +63,11 @@ public class UUIDTests public void testTimeUUIDType() throws UnknownHostException { TimeUUIDType comp = TimeUUIDType.instance; - byte[] first = UUIDGen.decompose(UUIDGen.makeType1UUIDFromHost(InetAddress.getByName("127.0.0.1"))); - byte[] second = UUIDGen.decompose(UUIDGen.makeType1UUIDFromHost(InetAddress.getByName("127.0.0.1"))); + ByteBuffer first = ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.makeType1UUIDFromHost(InetAddress.getByName("127.0.0.1")))); + ByteBuffer second = ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.makeType1UUIDFromHost(InetAddress.getByName("127.0.0.1")))); assert comp.compare(first, second) < 0; assert comp.compare(second, first) > 0; - byte[] sameAsFirst = UUIDGen.decompose(UUIDGen.makeType1UUID(first)); + ByteBuffer sameAsFirst = ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.makeType1UUID(first))); assert comp.compare(first, sameAsFirst) == 0; }
