Permalink
Browse files

Unit tests to demonstrate using ComponentEquality

  • Loading branch information...
1 parent f64c9be commit 402505cad362a595ea07797e6009be244151c336 @thrykol thrykol committed Nov 16, 2012
View
98 core/src/test/java/me/prettyprint/cassandra/service/CassandraClusterTest.java
@@ -74,7 +74,7 @@ public void testDescribeRing() throws Exception {
public void testDescribeKeyspace() throws Exception {
KeyspaceDefinition keyspaceDetail = cassandraCluster.describeKeyspace("Keyspace1");
assertNotNull(keyspaceDetail);
- assertEquals(21, keyspaceDetail.getCfDefs().size());
+ assertEquals(22, keyspaceDetail.getCfDefs().size());
}
@Test
@@ -89,13 +89,13 @@ public void testAddDropColumnFamily() throws Exception {
cassandraCluster.addColumnFamily(cfDef);
String cfid2 = cassandraCluster.dropColumnFamily("Keyspace1", "DynCf");
assertNotNull(cfid2);
-
+
// Let's wait for agreement
cassandraCluster.addColumnFamily(cfDef, true);
cfid2 = cassandraCluster.dropColumnFamily("Keyspace1", "DynCf", true);
assertNotNull(cfid2);
}
-
+
@Test
public void testTruncateColumnFamily() throws Exception {
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("Keyspace1", "TruncateableCf");
@@ -118,7 +118,7 @@ public void testAddDropKeyspace() throws Exception {
String ksid2 = cassandraCluster.dropKeyspace("DynKeyspace");
assertNotNull(ksid2);
-
+
// Now let's wait for schema agreement.
cassandraCluster.addKeyspace(new ThriftKsDef("DynKeyspace", "org.apache.cassandra.locator.SimpleStrategy", 1, Arrays.asList(cfDef)), true);
ksid2 = cassandraCluster.dropKeyspace("DynKeyspace", true);
@@ -135,32 +135,32 @@ public void testAddKeyspaceNTS() throws Exception {
@Test
public void testEditKeyspace() throws Exception {
-
+
BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
columnFamilyDefinition.setKeyspaceName("DynKeyspace2");
- columnFamilyDefinition.setName("DynamicCF");
-
+ columnFamilyDefinition.setName("DynamicCF");
+
ColumnFamilyDefinition cfDef = new ThriftCfDef(columnFamilyDefinition);
-
- KeyspaceDefinition keyspaceDefinition =
+
+ KeyspaceDefinition keyspaceDefinition =
HFactory.createKeyspaceDefinition("DynKeyspace2", "org.apache.cassandra.locator.SimpleStrategy", 1, Arrays.asList(cfDef));
-
+
cassandraCluster.addKeyspace(keyspaceDefinition);
-
- keyspaceDefinition =
+
+ keyspaceDefinition =
HFactory.createKeyspaceDefinition("DynKeyspace2", "org.apache.cassandra.locator.SimpleStrategy", 2, null);
-
+
cassandraCluster.updateKeyspace(keyspaceDefinition);
-
+
KeyspaceDefinition fromCluster = cassandraCluster.describeKeyspace("DynKeyspace2");
assertEquals(2,fromCluster.getReplicationFactor());
cassandraCluster.dropKeyspace("DynKeyspace2");
}
-
+
@Test
public void testAddColumnDefinitionWhenNoneOnConstructor() {
ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("blah-ks", "blah-cf", ComparatorType.BYTESTYPE);
-
+
assertSame( Collections.emptyList(), cfDef.getColumnMetadata());
//
@@ -176,88 +176,88 @@ public void testAddColumnDefinitionWhenNoneOnConstructor() {
assertEquals( 1, cfDef.getColumnMetadata().size());
assertEquals( cd, cfDef.getColumnMetadata().get(0));
}
-
+
@Test
public void testEditColumnFamily() throws Exception {
-
+
BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
columnFamilyDefinition.setKeyspaceName("DynKeyspace3");
- columnFamilyDefinition.setName("DynamicCF");
-
+ columnFamilyDefinition.setName("DynamicCF");
+
ColumnFamilyDefinition cfDef = new ThriftCfDef(columnFamilyDefinition);
-
- KeyspaceDefinition keyspaceDefinition =
+
+ KeyspaceDefinition keyspaceDefinition =
HFactory.createKeyspaceDefinition("DynKeyspace3", "org.apache.cassandra.locator.SimpleStrategy", 1, Arrays.asList(cfDef));
-
+
cassandraCluster.addKeyspace(keyspaceDefinition);
-
-
+
+
KeyspaceDefinition fromCluster = cassandraCluster.describeKeyspace("DynKeyspace3");
cfDef = fromCluster.getCfDefs().get(0);
-
+
columnFamilyDefinition = new BasicColumnFamilyDefinition(cfDef);
BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
columnDefinition.setName(StringSerializer.get().toByteBuffer("birthdate"));
columnDefinition.setIndexName("birthdate_idx");
columnDefinition.setIndexType(ColumnIndexType.KEYS);
columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());
columnFamilyDefinition.addColumnDefinition(columnDefinition);
-
+
columnDefinition = new BasicColumnDefinition();
- columnDefinition.setName(StringSerializer.get().toByteBuffer("nonindexed_field"));
+ columnDefinition.setName(StringSerializer.get().toByteBuffer("nonindexed_field"));
columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());
- columnFamilyDefinition.addColumnDefinition(columnDefinition);
-
+ columnFamilyDefinition.addColumnDefinition(columnDefinition);
+
cassandraCluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition));
-
+
fromCluster = cassandraCluster.describeKeyspace("DynKeyspace3");
-
+
assertEquals("birthdate",StringSerializer.get().fromByteBuffer(fromCluster.getCfDefs().get(0).getColumnMetadata().get(0).getName()));
assertEquals("birthdate_idx",fromCluster.getCfDefs().get(0).getColumnMetadata().get(0).getIndexName());
assertEquals("nonindexed_field",StringSerializer.get().fromByteBuffer(fromCluster.getCfDefs().get(0).getColumnMetadata().get(1).getName()));
}
-
+
@Test
public void testAddEmptyKeyspace() throws Exception {
-
+
cassandraCluster.addKeyspace(new ThriftKsDef("DynKeyspaceEmpty"));
assertNotNull(cassandraCluster.describeKeyspace("DynKeyspaceEmpty"));
String ksid2 = cassandraCluster.dropKeyspace("DynKeyspaceEmpty");
assertNotNull(ksid2);
}
-
+
@Test
public void testAddEmptyBasicKeyspaceDefinition() throws Exception {
BasicKeyspaceDefinition ksDef = new BasicKeyspaceDefinition();
ksDef.setName("DynKeyspaceEmpty");
ksDef.setReplicationFactor(1);
ksDef.setStrategyClass("SimpleStrategy");
-
+
cassandraCluster.addKeyspace(ksDef);
assertNotNull(cassandraCluster.describeKeyspace("DynKeyspaceEmpty"));
String ksid2 = cassandraCluster.dropKeyspace("DynKeyspaceEmpty");
assertNotNull(ksid2);
}
-
+
@Test
public void testEditBasicKeyspaceDefinition() throws Exception {
BasicKeyspaceDefinition ksDef = new BasicKeyspaceDefinition();
ksDef.setName("DynKeyspace4");
ksDef.setReplicationFactor(1);
ksDef.setStrategyClass("SimpleStrategy");
-
+
cassandraCluster.addKeyspace(ksDef);
assertNotNull(cassandraCluster.describeKeyspace("DynKeyspace4"));
-
+
ksDef.setReplicationFactor(2);
-
+
cassandraCluster.updateKeyspace(ksDef);
-
+
KeyspaceDefinition fromCluster = cassandraCluster.describeKeyspace("DynKeyspace4");
assertEquals(2, fromCluster.getReplicationFactor());
cassandraCluster.dropKeyspace("DynKeyspace4");
}
-
+
@Test
public void testAddDropBasicColumnFamilyDefinition() throws Exception {
BasicColumnFamilyDefinition cfDef = new BasicColumnFamilyDefinition();
@@ -268,28 +268,28 @@ public void testAddDropBasicColumnFamilyDefinition() throws Exception {
String cfid2 = cassandraCluster.dropColumnFamily("Keyspace1", "DynCf");
assertNotNull(cfid2);
}
-
+
@Test
public void testEditBasicColumnFamilyDefinition() throws Exception {
BasicKeyspaceDefinition ksDef = new BasicKeyspaceDefinition();
ksDef.setName("Keyspace2");
ksDef.setReplicationFactor(1);
ksDef.setStrategyClass("SimpleStrategy");
-
+
cassandraCluster.addKeyspace(ksDef);
-
+
BasicColumnFamilyDefinition cfDef = new BasicColumnFamilyDefinition();
cfDef.setName("DynCf2");
cfDef.setKeyspaceName("Keyspace2");
cassandraCluster.addColumnFamily(cfDef);
-
- KeyspaceDefinition fromCluster = cassandraCluster.describeKeyspace("Keyspace2");
+
+ KeyspaceDefinition fromCluster = cassandraCluster.describeKeyspace("Keyspace2");
cfDef = new BasicColumnFamilyDefinition(fromCluster.getCfDefs().get(0));
-
+
cfDef.setDefaultValidationClass(ComparatorType.LONGTYPE.getClassName());
cassandraCluster.updateColumnFamily(cfDef);
-
+
String cfid2 = cassandraCluster.dropColumnFamily("Keyspace2", "DynCf2");
assertNotNull(cfid2);
}
View
254 core/src/test/java/me/prettyprint/hector/api/beans/DynamicCompositeTest.java
@@ -1,32 +1,51 @@
package me.prettyprint.hector.api.beans;
-import static org.junit.Assert.*;
-
import java.nio.ByteBuffer;
-import java.util.UUID;
-
-import me.prettyprint.cassandra.serializers.AsciiSerializer;
-import me.prettyprint.cassandra.serializers.BytesArraySerializer;
-import me.prettyprint.cassandra.serializers.DynamicCompositeSerializer;
-import me.prettyprint.cassandra.serializers.IntegerSerializer;
-import me.prettyprint.cassandra.serializers.LongSerializer;
-import me.prettyprint.cassandra.serializers.StringSerializer;
-import me.prettyprint.cassandra.serializers.TimeUUIDSerializer;
-import me.prettyprint.cassandra.serializers.UUIDSerializer;
+import java.util.Map.Entry;
+import java.util.*;
+import me.prettyprint.cassandra.serializers.*;
+import me.prettyprint.cassandra.service.ColumnSliceIterator;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.Serializer;
import me.prettyprint.hector.api.beans.AbstractComposite.ComponentEquality;
-
+import me.prettyprint.hector.api.factory.HFactory;
+import static me.prettyprint.hector.api.factory.HFactory.*;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.SliceQuery;
+import me.prettyprint.hector.testutils.EmbeddedServerHelper;
+import org.junit.AfterClass;
+import static org.junit.Assert.*;
+import org.junit.BeforeClass;
import org.junit.Test;
public class DynamicCompositeTest {
+ private static DynamicCompositeSerializer ds = DynamicCompositeSerializer.get();
+ private static StringSerializer ss = StringSerializer.get();
+ private static UUIDSerializer us = UUIDSerializer.get();
+ private static Serializer<UUID> uss = UUIDSerializer.get();
+
+ private static EmbeddedServerHelper embedded;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ embedded = new EmbeddedServerHelper();
+ embedded.setup();
+ }
+
+ @AfterClass
+ public static void teardown() throws Exception {
+ EmbeddedServerHelper.teardown();
+ }
@Test
public void allTypesSerialize() {
DynamicComposite composite = new DynamicComposite();
-
+
UUID lexUUID = UUID.randomUUID();
com.eaio.uuid.UUID timeUUID = new com.eaio.uuid.UUID();
-
-
+
+
//add all forward comparators
composite.addComponent(0, "AsciiText", AsciiSerializer.get(), "AsciiType", ComponentEquality.EQUAL);
composite.addComponent(1, new byte[]{0, 1, 2, 3}, BytesArraySerializer.get(), "BytesType", ComponentEquality.EQUAL);
@@ -36,7 +55,7 @@ public void allTypesSerialize() {
composite.addComponent(5, timeUUID, TimeUUIDSerializer.get(), "TimeUUIDType", ComponentEquality.EQUAL);
composite.addComponent(6, "UTF8Text", StringSerializer.get(), "UTF8Type", ComponentEquality.EQUAL);
composite.addComponent(7, lexUUID, UUIDSerializer.get(), "UUIDType", ComponentEquality.EQUAL);
-
+
//add all reverse comparators
composite.addComponent(8, "AsciiText", AsciiSerializer.get(), "AsciiType(reversed=true)", ComponentEquality.EQUAL);
composite.addComponent(9, new byte[]{0, 1, 2, 3}, BytesArraySerializer.get(), "BytesType(reversed=true)", ComponentEquality.EQUAL);
@@ -47,15 +66,15 @@ public void allTypesSerialize() {
composite.addComponent(14, "UTF8Text", StringSerializer.get(), "UTF8Type(reversed=true)", ComponentEquality.EQUAL);
composite.addComponent(15, lexUUID, UUIDSerializer.get(), "UUIDType(reversed=true)", ComponentEquality.EQUAL);
composite.addComponent(16, "My element", ComponentEquality.EQUAL);
-
+
//serialize to the native bytes value
-
+
ByteBuffer buffer = DynamicCompositeSerializer.get().toByteBuffer(composite);
-
-
+
+
//now deserialize and ensure the values are the same
DynamicComposite parsed = DynamicCompositeSerializer.get().fromByteBuffer(buffer);
-
+
assertEquals("AsciiText", parsed.get(0, AsciiSerializer.get()));
assertArrayEquals(new byte[]{0, 1, 2, 3}, parsed.get(1, BytesArraySerializer.get()));
assertEquals(Integer.valueOf(-1), parsed.get(2, IntegerSerializer.get()));
@@ -64,7 +83,7 @@ public void allTypesSerialize() {
assertEquals(timeUUID, parsed.get(5, TimeUUIDSerializer.get()));
assertEquals("UTF8Text", parsed.get(6, StringSerializer.get()));
assertEquals(lexUUID, parsed.get(7, UUIDSerializer.get()));
-
+
//now test all the reversed values
assertEquals("AsciiText", parsed.get(8, AsciiSerializer.get()));
assertArrayEquals(new byte[]{0, 1, 2, 3}, parsed.get(9, BytesArraySerializer.get()));
@@ -75,8 +94,195 @@ public void allTypesSerialize() {
assertEquals("UTF8Text", parsed.get(14, StringSerializer.get()));
assertEquals(lexUUID, parsed.get(15, UUIDSerializer.get()));
assertEquals("My element", parsed.get(16, StringSerializer.get()));
-
+
+ }
+
+ @Test
+ public void testUUIDGetAll() {
+ // Gets all columns in the row regardless of the column name
+ Cluster c = getOrCreateCluster("MyCluster", "localhost:9170");
+ Keyspace ks = createKeyspace("Keyspace1", c);
+ String key = "rowKey";
+ String cf = "DynamicComposite1";
+
+ init(ks, key, cf);
+
+ // Get all rows
+ Set<UUID> results = new HashSet<UUID>();
+ ColumnSliceIterator<String, DynamicComposite, String> iterator = getIterator(ks, cf, key, null, null);
+ while(iterator.hasNext()) {
+ HColumn<DynamicComposite, String> column = iterator.next();
+ DynamicComposite composite = column.getName();
+ UUID component1 = composite.get(1, us);
+ results.add(component1);
+ }
+
+ assertEquals("Failed to retrieve all columns", 8, results.size());
+
+ clear(ks, key, cf);
+ }
+
+ @Test
+ public void testUUIDGetSlice() {
+ // Gets all columns based on the first component in the column name
+ Cluster c = getOrCreateCluster("MyCluster", "localhost:9170");
+ Keyspace ks = createKeyspace("Keyspace1", c);
+ String key = "rowKey";
+ String cf = "DynamicComposite1";
+
+ Map<UUID, Set<UUID>> ids = init(ks, key, cf);
+
+ for(Entry<UUID, Set<UUID>> entry : ids.entrySet()) {
+ UUID component0 = entry.getKey();
+
+ // start at first column who's single component == component0
+ DynamicComposite start = new DynamicComposite();
+ start.addComponent(component0, us);
+
+ // up to and including any column whose first component == component0 regardless of remaining component values
+ DynamicComposite end = new DynamicComposite();
+ end.addComponent(component0, us, us.getComparatorType().getTypeName(), ComponentEquality.GREATER_THAN_EQUAL);
+
+ ColumnSliceIterator<String, DynamicComposite, String> iterator = getIterator(ks, cf, key, start, end);
+ while(iterator.hasNext()) {
+ HColumn<DynamicComposite, String> column = iterator.next();
+ DynamicComposite composite = column.getName();
+
+ assertEquals(component0, composite.get(0, us));
+ assertTrue(ids.get(component0).contains(composite.get(1, us)));
+ }
+ }
+
+ clear(ks, key, cf);
}
+ @Test
+ public void testStringGetSlice() {
+ Cluster c = getOrCreateCluster("MyCluster", "localhost:9170");
+ Keyspace ks = createKeyspace("Keyspace1", c);
+ String key = "rowKey";
+ String cf = "DynamicComposite1";
+ Mutator<String> mutator = createMutator(ks, ss);
+
+ DynamicComposite composite = (DynamicComposite) new DynamicComposite().
+ addComponent("a", ss).
+ addComponent("ba", ss).
+ addComponent("ca", ss).
+ addComponent("da", ss);
+ mutator.addInsertion(key, cf, HFactory.createColumn(composite, composite.toString(), ds, ss));
+
+ composite = (DynamicComposite) new DynamicComposite().
+ addComponent("a", ss).
+ addComponent("bb", ss).
+ addComponent("cb", ss).
+ addComponent("db", ss);
+ mutator.addInsertion(key, cf, HFactory.createColumn(composite, composite.toString(), ds, ss));
+
+ composite = (DynamicComposite) new DynamicComposite().
+ addComponent("b", ss).
+ addComponent("ba", ss).
+ addComponent("ca", ss).
+ addComponent("da", ss);
+ mutator.addInsertion(key, cf, HFactory.createColumn(composite, composite.toString(), ds, ss));
+
+ composite = (DynamicComposite) new DynamicComposite().
+ addComponent("b", ss).
+ addComponent("bb", ss).
+ addComponent("cb", ss).
+ addComponent("db", ss);
+ mutator.addInsertion(key, cf, HFactory.createColumn(composite, composite.toString(), ds, ss));
+
+ mutator.execute();
+
+ String compType = ss.getComparatorType().getTypeName();
+
+ System.out.println("LESS_THAN_EQUAL");
+ DynamicComposite end = (DynamicComposite) new DynamicComposite().
+ addComponent("b", ss, compType).
+ addComponent("ba", ss).
+ addComponent("ca", ss).
+ addComponent("da", ss, compType, ComponentEquality.LESS_THAN_EQUAL); // s@a:s@ba:s@ca:s@da thru s@a:s@bb:s@cb:s@db
+
+ ColumnSliceIterator<String, DynamicComposite, String> iterator = getIterator(ks, cf, key, null, end);
+ while(iterator.hasNext()) {
+ System.out.println(iterator.next().getName());
+ }
+
+ System.out.println("EQUAL");
+ end = (DynamicComposite) new DynamicComposite().
+ addComponent("b", ss, compType).
+ addComponent("ba", ss).
+ addComponent("ca", ss).
+ addComponent("da", ss, compType, ComponentEquality.EQUAL); // s@a:s@ba:s@ca:s@da thru s@b:s@ba:s@ca:s@da
+
+ iterator = getIterator(ks, cf, key, null, end);
+ while(iterator.hasNext()) {
+ System.out.println(iterator.next().getName());
+ }
+
+ System.out.println("GREATER_THAN_EQUAL");
+ end = (DynamicComposite) new DynamicComposite().
+ addComponent("b", ss, compType).
+ addComponent("bb", ss, compType, ComponentEquality.GREATER_THAN_EQUAL); // s@a:s@ba:s@ca:s@da thru s@b:s@bb:s@cb:s@db
+
+ iterator = getIterator(ks, cf, key, null, end);
+ while(iterator.hasNext()) {
+ System.out.println(iterator.next().getName());
+ }
+ }
+
+ private ColumnSliceIterator<String, DynamicComposite, String> getIterator(Keyspace ks, String cf, String key, DynamicComposite start, DynamicComposite end) {
+ SliceQuery<String, DynamicComposite, String> query = HFactory.createSliceQuery(ks, ss, ds, ss).
+ setColumnFamily(cf).
+ setKey(key);
+ return new ColumnSliceIterator<String, DynamicComposite, String>(query, start, end, false);
+ }
+
+ /**
+ * Initializes a row whose DynamicComposite column name components are two UUIDs.
+ * Sample row:
+ *
+ * RowKey: ROW_KEY
+ * => (column=u@77df3aa8-f8b2-4658-be4d-ad9401f4388a:u@222c532f-e310-4803-8119-3a96f770b763, value=[77df3aa8-f8b2-4658-be4d-ad9401f4388a, 222c532f-e310-4803-8119-3a96f770b763], timestamp=1353028069149000)
+ * => (column=u@77df3aa8-f8b2-4658-be4d-ad9401f4388a:u@acf45bbe-4b2d-4f90-80d3-3b2288ccb13a, value=[77df3aa8-f8b2-4658-be4d-ad9401f4388a, acf45bbe-4b2d-4f90-80d3-3b2288ccb13a], timestamp=1353028069149002)
+ * => (column=u@77df3aa8-f8b2-4658-be4d-ad9401f4388a:u@b1015157-e030-45dd-b5a3-67a11f7e6350, value=[77df3aa8-f8b2-4658-be4d-ad9401f4388a, b1015157-e030-45dd-b5a3-67a11f7e6350], timestamp=1353028069138000)
+ * => (column=u@77df3aa8-f8b2-4658-be4d-ad9401f4388a:u@f42dc238-7fab-48ec-b831-632bd1adaad9, value=[77df3aa8-f8b2-4658-be4d-ad9401f4388a, f42dc238-7fab-48ec-b831-632bd1adaad9], timestamp=1353028069149001)
+ * => (column=u@def2ce2c-a77d-48de-8072-1b5c06fb0e07:u@20624858-77fb-495b-9886-12b7ff230da9, value=[def2ce2c-a77d-48de-8072-1b5c06fb0e07, 20624858-77fb-495b-9886-12b7ff230da9], timestamp=1353028069150002)
+ * => (column=u@def2ce2c-a77d-48de-8072-1b5c06fb0e07:u@bff9acb8-2b61-420a-b6ad-4095bc87f32c, value=[def2ce2c-a77d-48de-8072-1b5c06fb0e07, bff9acb8-2b61-420a-b6ad-4095bc87f32c], timestamp=1353028069150001)
+ * => (column=u@def2ce2c-a77d-48de-8072-1b5c06fb0e07:u@c9b0bfc4-b756-43f8-bcd9-1ec6680b4bde, value=[def2ce2c-a77d-48de-8072-1b5c06fb0e07, c9b0bfc4-b756-43f8-bcd9-1ec6680b4bde], timestamp=1353028069150003)
+ * => (column=u@def2ce2c-a77d-48de-8072-1b5c06fb0e07:u@decaf265-1213-42e8-a489-a991d4d00d97, value=[def2ce2c-a77d-48de-8072-1b5c06fb0e07, decaf265-1213-42e8-a489-a991d4d00d97], timestamp=1353028069150000)
+ *
+ * @return Map of first component to a set of the corresponding second components
+ */
+ private Map<UUID, Set<UUID>> init(Keyspace ks, String key, String cf) {
+ Mutator<String> mutator = createMutator(ks, ss);
+ Map<UUID, Set<UUID>> ids = new HashMap<UUID, Set<UUID>>();
+ ids.put(UUID.randomUUID(), new HashSet<UUID>());
+ ids.put(UUID.randomUUID(), new HashSet<UUID>());
+
+ for(Entry<UUID, Set<UUID>> entry : ids.entrySet()) {
+ for(int i = 0; i < 4; i++) {
+ UUID uuid = UUID.randomUUID();
+
+ DynamicComposite composite = (DynamicComposite) new DynamicComposite().addComponent(entry.getKey(), uss).addComponent(uuid, uss);
+ mutator.addInsertion(key, cf, HFactory.createColumn(composite, composite.toString(), ds, ss));
+
+ entry.getValue().add(uuid);
+ }
+ }
+
+ mutator.execute();
+
+ return ids;
+ }
+
+ /**
+ * Helper function to remove a row after the test has completed.
+ */
+ private void clear(Keyspace ks, String key, String cf) {
+ Mutator<String> mutator = createMutator(ks, ss);
+ mutator.addDeletion(key, cf);
+ mutator.execute();
+ }
}
View
35 test/src/main/java/me/prettyprint/hector/testutils/EmbeddedSchemaLoader.java
@@ -28,8 +28,20 @@
import org.apache.cassandra.thrift.IndexType;
import com.google.common.base.Charsets;
+import org.apache.cassandra.db.marshal.*;
public class EmbeddedSchemaLoader {
+ private static final Map<Byte, AbstractType<?>> alias;
+ static {
+ alias = new HashMap<Byte, AbstractType<?>>();
+ alias.put((byte) 'a', AsciiType.instance);
+ alias.put((byte) 'i', IntegerType.instance);
+ alias.put((byte) 'x', LexicalUUIDType.instance);
+ alias.put((byte) 'l', LongType.instance);
+ alias.put((byte) 't', TimeUUIDType.instance);
+ alias.put((byte) 's', UTF8Type.instance);
+ alias.put((byte) 'u', UUIDType.instance);
+ }
public static void loadSchema() {
try
{
@@ -51,16 +63,16 @@ public static void loadSchema() {
Class<? extends AbstractReplicationStrategy> simple = SimpleStrategy.class;
Map<String, String> opts = new HashMap<String, String>();
opts.put("replication_factor", Integer.toString(1));
-
+
ColumnFamilyType st = ColumnFamilyType.Standard;
ColumnFamilyType su = ColumnFamilyType.Super;
AbstractType bytes = BytesType.instance;
-
+
List<AbstractType> subComparators = new ArrayList<AbstractType>();
subComparators.add(BytesType.instance);
subComparators.add(TimeUUIDType.instance);
subComparators.add(IntegerType.instance);
-
+
// Keyspace 1
schema.add(KSMetaData.testMetadata(
ks1,
@@ -70,7 +82,8 @@ public static void loadSchema() {
// Column Families
standardCFMD(ks1, "Standard1"), standardCFMD(ks1, "Standard2"),
standardCFMD(ks1, "Standard3"), standardCFMD(ks1, "Standard4"),
- cqlTestCf(ks1, "StandardLong1",UTF8Type.instance),
+ dynamicCompositeCFMD(ks1, "DynamicComposite1"),
+ cqlTestCf(ks1, "StandardLong1",UTF8Type.instance),
standardCFMD(ks1, "StandardLong2").keyValidator(UTF8Type.instance),
superCFMD(ks1, "Super1", BytesType.instance),
superCFMD(ks1, "Super2", LongType.instance),
@@ -90,14 +103,18 @@ public static void loadSchema() {
jdbcCFMD(ks1, "JdbcAscii", AsciiType.instance)));
// Keyspace 2
-
+
return schema;
}
private static CFMetaData compositeCFMD(String ksName, String cfName, AbstractType<?>... types) {
- return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, CompositeType.getInstance(Arrays.asList(types)), null);
+ return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, CompositeType.getInstance(Arrays.asList(types)), null);
}
-
+
+ private static CFMetaData dynamicCompositeCFMD(String ksName, String cfName) {
+ return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, DynamicCompositeType.getInstance(alias), null);
+ }
+
private static CFMetaData standardCFMD(String ksName, String cfName) {
return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard,
BytesType.instance, null);
@@ -128,11 +145,11 @@ private static CFMetaData jdbcCFMD(String ksName, String cfName,
return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, null)
.defaultValidator(comp);
}
-
+
private static CFMetaData cqlTestCf(String ksName, String cfName,
AbstractType comp)
throws ConfigurationException
- {
+ {
return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, null)
.keyValidator(UTF8Type.instance).columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>()
{{

0 comments on commit 402505c

Please sign in to comment.