@Test public void testRowKeysAllColumnsQuery() throws Exception { keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRowSlice("acct_0", "acct_1", "acct_2", "acct_3") .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRowSlice("acct_4", "acct_5", "acct_6", "acct_7") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(4 == result.size()); for (Row<String, String> row : result) { int rowNo = Integer.parseInt(row.getKey().substring("acct_".length())); Assert.assertTrue(rowNo >= 4); Assert.assertTrue(rowNo <= 7); Assert.assertTrue(13 == row.getColumns().size()); } }
@Test public void testRowKeysColumnSetQuery() throws Exception { keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRowSlice("acct_0", "acct_1", "acct_2", "acct_3") .withColumnSlice("firstname", "lastname", "age") .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRowSlice("acct_4", "acct_5", "acct_6", "acct_7") .withColumnSlice("firstname", "lastname", "age") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(4 == result.size()); for (Row<String, String> row : result) { int rowNo = Integer.parseInt(row.getKey().substring("acct_".length())); Assert.assertTrue(rowNo >= 4); Assert.assertTrue(rowNo <= 7); Assert.assertTrue(3 == row.getColumns().size()); } }
@Test public void testSingleRowSingleColumnQuery() throws Exception { for (int i=0; i<TestRowCount; i++) { Column<String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRow("acct_" + i) .getColumn("address") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertEquals("address", result.getName()); Assert.assertNotNull(result.getStringValue()); Assert.assertEquals("john smith address " + i, result.getStringValue()); } }
@Test public void testSingleRowColumnSliceQueryWithCollection() throws Exception { for (int i=0; i<TestRowCount; i++) { ColumnList<String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRow("acct_" + i) .withColumnSlice("firstname", "lastname", "address", "age") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(4 == result.size()); Assert.assertEquals("john_" + i, result.getColumnByName("firstname").getStringValue()); Assert.assertEquals("smith_" + i, result.getColumnByName("lastname").getStringValue()); Assert.assertEquals("john smith address " + i, result.getColumnByName("address").getStringValue()); Assert.assertTrue(30 + i == result.getColumnByName("age").getIntegerValue()); } }
@Test public void testSingleRowAllColumnsQuery() throws Exception { for (int i=0; i<TestRowCount; i++) { ColumnList<String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRow("acct_" + i) .execute() .getResult(); super.testAllColumnsForRow(result, i); } }
@Test public void testRowRangeColumnSetQuery() throws Exception { String startToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("A")); String endToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("G")); keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .withColumnSlice("a", "s", "d", "f") .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .withColumnSlice("a", "s", "d", "f") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(3 == result.size()); for (Row<String, String> row : result) { Assert.assertTrue(4 == row.getColumns().size()); } }
@Test public void testRowRangeAllColumnsQuery() throws Exception { String startToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("A")); String endToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("G")); keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(3 == result.size()); for (Row<String, String> row : result) { Assert.assertTrue(26 == row.getColumns().size()); } }
@Test public void testRowKeysColumnRangeQuery() throws Exception { keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowSlice("A", "B", "C", "D") .withColumnRange(new CqlRangeBuilder<String>() .setStart("a") .setEnd("c") .build()) .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowSlice("E", "F", "G", "H") .withColumnRange(new CqlRangeBuilder<String>() .setStart("d") .setEnd("h") .build()) .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(4 == result.size()); for (Row<String, String> row : result) { int rowNo = row.getKey().charAt(0) - 'A'; Assert.assertTrue(rowNo >= 4); Assert.assertTrue(rowNo <= 7); Assert.assertTrue(5 == row.getColumns().size()); } }
@Test public void testRowRangeColumnRangeQuery() throws Exception { String startToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("A")); String endToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("G")); keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .withColumnRange(new CqlRangeBuilder<String>() .setStart("d") .setEnd("h") .build()) .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .withColumnRange(new CqlRangeBuilder<String>() .setStart("d") .setEnd("h") .build()) .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(3 == result.size()); for (Row<String, String> row : result) { Assert.assertTrue(5 == row.getColumns().size()); } }