private void testSingleRowAllColumnsColumnCountQuery(boolean rowDeleted) throws Exception { int expected = rowDeleted ? 0 : columnNames.size(); for (int i=0; i<TestRowCount; i++) { int count = keyspace.prepareQuery(CF_USER_INFO).getRow("acct_" + i).getCount().execute().getResult().intValue(); Assert.assertEquals(expected, count); } }
/** ALL COLUMN COUNT QUERIES */ private void testReadSingleRowAllColumnsWithColumnCount(boolean rowDeleted) throws Exception { for (int year = 2001; year <= 2014; year++) { Integer result = keyspace.prepareQuery(CF_POPULATION) .getRow(year) .getCount() .execute().getResult(); int expected = rowDeleted ? 0 : 4; Assert.assertTrue(expected == result.intValue()); } }
private void testSingleRowColumnSliceCollectionColumnCountQuery(boolean rowDeleted) throws Exception { int expected = rowDeleted ? 0 : columnNames.size(); for (int i=0; i<TestRowCount; i++) { int count = keyspace.prepareQuery(CF_USER_INFO).getRow("acct_" + i).withColumnSlice(columnNames).getCount().execute().getResult(); Assert.assertEquals(expected, count); } }
private void testSingleRowColumnSliceVarArgsColumnCountQuery(boolean rowDeleted) throws Exception { int expected = rowDeleted ? 0 : columnNames.size(); for (int i=0; i<TestRowCount; i++) { int count = keyspace.prepareQuery(CF_USER_INFO).getRow("acct_" + i) .withColumnSlice("firstname", "lastname", "address","age","ageShort", "ageLong","percentile", "married","single", "birthdate", "bytes", "uuid", "empty") .getCount().execute().getResult(); Assert.assertEquals(expected, count); } }
private void verifyPresent(Keyspace ks, int rowKey) throws ConnectionException { ColumnList<Long> result = ks.prepareQuery(CF_DUAL_WRITES).getRow(rowKey).execute().getResult(); if (result.isEmpty()) { throw new RuntimeException("Row: " + rowKey + " missing from keysapce: " + ks.getKeyspaceName()); } else { System.out.println("Verified Row: " + rowKey + " present in ks: " + ks.getKeyspaceName()); } }
private void verifyNotPresent(Keyspace ks, int rowKey) throws ConnectionException { ColumnList<Long> result = ks.prepareQuery(CF_DUAL_WRITES).getRow(rowKey).execute().getResult(); if (!result.isEmpty()) { throw new RuntimeException("Row: " + rowKey + " present in keysapce: " + ks.getKeyspaceName()); } else { System.out.println("Verified Row: " + rowKey + " NOT present in ks: " + ks.getKeyspaceName()); } }
private void performSimpleRowSingleColumnQueryForRow(String rowKey, boolean rowDeleted, String expectedChar) throws Exception { Column<String> col = keyspace.prepareQuery(CF_ACCOUNTS).getRow(rowKey).getColumn("user").execute().getResult(); if (rowDeleted) { Assert.assertNull(col); } else { Assert.assertTrue(col.hasValue()); Assert.assertEquals("user" + expectedChar, col.getStringValue()); } col = keyspace.prepareQuery(CF_ACCOUNTS).getRow(rowKey).getColumn("pswd").execute().getResult(); if (rowDeleted) { Assert.assertNull(col); } else { Assert.assertTrue(col.hasValue()); Assert.assertEquals("pswd" + expectedChar, col.getStringValue()); } }
@Test public void testGetSingleColumnNotExists() throws ConnectionException { Column<String> column = keyspace.prepareQuery(CF_STANDARD1).getRow("A").getColumn("DoesNotExist").execute().getResult(); Assert.assertNull(column); }
private void performSimpleRowQueryForRow(String rowKey, boolean rowDeleted, String expectedChar) throws Exception { ColumnList<String> result = keyspace.prepareQuery(CF_ACCOUNTS).getRow(rowKey).execute().getResult(); if (rowDeleted) { Assert.assertTrue(result.isEmpty()); } else { Assert.assertFalse(result.isEmpty()); Column<String> col = result.getColumnByName("user"); Assert.assertEquals("user" + expectedChar, col.getStringValue()); col = result.getColumnByName("pswd"); Assert.assertEquals("pswd" + expectedChar, col.getStringValue()); } }
@Test public void testGetSingleKeyNotExists() throws Exception { Column<String> column = keyspace.prepareQuery(CF_STANDARD1).getRow("AA").getColumn("ab").execute().getResult(); Assert.assertNull(column); }
private void testReadSingleRowSingleColumn(boolean rowDeleted) throws Exception { for (int year = 2001; year <= 2014; year++) { Column<Population> result = keyspace.prepareQuery(CF_POPULATION) .getRow(year) .getColumn(SanFrancisco.clone()) .execute().getResult(); if (rowDeleted) { Assert.assertNull(result); continue; } else { Assert.assertTrue(result.hasValue()); } Assert.assertEquals(SanFrancisco, result.getName()); } }
private void testReadSingleRowAllColumns(boolean rowDeleted) throws Exception { for (int year = 2001; year <= 2014; year++) { ColumnList<Population> result = keyspace.prepareQuery(CF_POPULATION) .getRow(year) .execute().getResult(); if (rowDeleted) { Assert.assertTrue(result.isEmpty()); continue; } else { checkResult(result, SanDiego, SanFrancisco, NewYork, Seattle); } } }
@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()); } }
@Override public FeatureState getFeatureState(Feature feature) { try { final ColumnList<String> state = keyspace .prepareQuery(columnFamily) .getRow(feature.name()) .execute() .getResult(); return state.isEmpty() ? null : toFeatureState(feature, state); } catch (ConnectionException e) { throw new RuntimeException(e); } }
@Test public void testGetSingleColumn() throws Exception { keyspace.prepareColumnMutation(CF_STANDARD1, "A", "a").putValue(1, null).execute(); Column<String> column = keyspace.prepareQuery(CF_STANDARD1).getRow("A").getColumn("a").execute().getResult(); Assert.assertNotNull(column); Assert.assertEquals(1, column.getIntegerValue()); }
@Test public void testUniquenessWithCustomMutation() throws Exception { ColumnList<String> result = keyspace.prepareQuery(CF_UNIQUE_CONSTRAINT).getRow(10L).execute().getResult(); Assert.assertTrue(result.isEmpty()); ColumnPrefixUniquenessConstraint<Long> unique = new ColumnPrefixUniquenessConstraint<Long>(keyspace, CF_UNIQUE_CONSTRAINT, 3L) .withConsistencyLevel(ConsistencyLevel.CL_ONE); unique.acquireAndApplyMutation(new Function<MutationBatch, Boolean>() { public Boolean apply(MutationBatch input) { input.withRow(CF_UNIQUE_CONSTRAINT, 10L).putEmptyColumn("MyCustomColumn", null); return true; } }); result = keyspace.prepareQuery(CF_UNIQUE_CONSTRAINT).getRow(10L).execute().getResult(); Assert.assertFalse(result.isEmpty()); } }
@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 testDelete() throws Exception { LOG.info("Starting testDelete..."); String rowKey = "DeleteMe_testDelete"; MutationBatch m = keyspace.prepareMutationBatch(); m.withRow(CF_STANDARD1, rowKey).putColumn("Column1", "X", null).putColumn("Column2", "X", null); m.execute(); Column<String> column = keyspace.prepareQuery(CF_STANDARD1).getRow(rowKey).getColumn("Column1").execute().getResult(); Assert.assertEquals("X", column.getStringValue()); m = keyspace.prepareMutationBatch(); m.withRow(CF_STANDARD1, rowKey).deleteColumn("Column1"); m.execute(); column = keyspace.prepareQuery(CF_STANDARD1).getRow(rowKey).getColumn("Column1").execute().getResult(); Assert.assertNull(column); LOG.info("... testDelete"); }
@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 testTtlValues() throws Exception { MutationBatch mb = keyspace.prepareMutationBatch(); mb.withRow(CF_TTL, "row") .putColumn("TTL0", "TTL0", 0) .putColumn("TTLNULL", "TTLNULL", null) .putColumn("TTL1", "TTL1", 1); mb.execute(); Thread.sleep(2000); ColumnList<String> result = keyspace.prepareQuery(CF_TTL) .getRow("row") .execute().getResult(); Assert.assertEquals(2, result.size()); Assert.assertNotNull(result.getColumnByName("TTL0")); Assert.assertNotNull(result.getColumnByName("TTLNULL")); } }