-
-
Save tnine/3ce70eab8102d2555626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Test ordering composites | |
* | |
* @param size | |
*/ | |
@Test | |
public void testCompositeOrdering() { | |
Mutator<byte[]> mutator = HFactory.createMutator( | |
CassandraTestBase.keyspace, BytesArraySerializer.get()); | |
byte[] rowKey = generateRowKey(); | |
System.out.println("Insertion values"); | |
DynamicComposite composite = new DynamicComposite(); | |
// make all values the same first column | |
composite.addComponent("jeans", StringSerializer.get(), StringSerializer.get().getComparatorType().getTypeName()); | |
// now increment the second value | |
composite.addComponent(1293840000000l, LongSerializer.get(), "BytesType(reversed=true)"); | |
mutator.addInsertion( | |
rowKey, | |
AbstractIndexOperation.CF_NAME, | |
HFactory.createColumn(composite, holder, | |
DynamicCompositeSerializer.get(), BytesArraySerializer.get())); | |
System.out.println(ByteBufferUtil.bytesToHex(composite.serialize())); | |
composite = new DynamicComposite(); | |
// make all values the same first column | |
composite.addComponent("jeans", StringSerializer.get(), StringSerializer | |
.get().getComparatorType().getTypeName()); | |
// now increment the second value | |
composite.addComponent(1294099200000l, LongSerializer.get(), "BytesType(reversed=true)"); | |
mutator.addInsertion( | |
rowKey, | |
AbstractIndexOperation.CF_NAME, | |
HFactory.createColumn(composite, holder, | |
DynamicCompositeSerializer.get(), BytesArraySerializer.get())); | |
System.out.println(ByteBufferUtil.bytesToHex(composite.serialize())); | |
mutator.execute(); | |
// now query them with a scan and ensure they're returned correctly. | |
SliceQuery<byte[], DynamicComposite, ByteBuffer> sliceQuery = HFactory | |
.createSliceQuery(keyspace, BytesArraySerializer.get(), | |
DynamicCompositeSerializer.get(), ByteBufferSerializer.get()); | |
sliceQuery.setColumnFamily(AbstractIndexOperation.CF_NAME); | |
sliceQuery.setKey(rowKey); | |
DynamicComposite start = new DynamicComposite(); | |
start.addComponent("jeans", StringSerializer.get(), StringSerializer.get() | |
.getComparatorType().getTypeName(), ComponentEquality.EQUAL); | |
DynamicComposite end = new DynamicComposite(); | |
end.addComponent("jeans", StringSerializer.get(), StringSerializer.get() | |
.getComparatorType().getTypeName(), | |
ComponentEquality.GREATER_THAN_EQUAL); | |
sliceQuery.setRange(start, end, false, 1000); | |
System.out.println("Range values"); | |
System.out.println(ByteBufferUtil.bytesToHex(start.serialize())); | |
System.out.println(ByteBufferUtil.bytesToHex(end.serialize())); | |
List<HColumn<DynamicComposite, ByteBuffer>> cols = sliceQuery.execute() | |
.get().getColumns(); | |
System.out.println("Returned values"); | |
System.out.println(ByteBufferUtil.bytesToHex(cols.get(0).getNameBytes())); | |
composite = cols.get(0).getName(); | |
// make all values the same first column | |
assertEquals("jeans", composite.get(0, StringSerializer.get())); | |
assertEquals(1294099200000l, (long) composite.get(1, LongSerializer.get())); | |
composite = cols.get(1).getName(); | |
// make all values the same first column | |
assertEquals("jeans", composite.get(0, StringSerializer.get())); | |
assertEquals(1293840000000l, (long) composite.get(1, LongSerializer.get())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment