private void testReadMultipleRowKeysAllColumnsWithColumnCount(boolean rowDeleted) throws Exception { Map<Integer, Integer> result = keyspace.prepareQuery(CF_POPULATION) .getKeySlice(2001, 2002, 2003, 2004, 2005) .getColumnCounts() .execute().getResult(); Map<Integer, Integer> expected = new HashMap<Integer, Integer>(); if (!rowDeleted) { for (int year = 2001; year<= 2005; year++) { expected.put(year, 4); } } Assert.assertEquals(expected, result); }
private void testReadRowRangeAllColumnsWithColumnCount(boolean rowDeleted) throws Exception { List<TestRange> testRanges = getTestRanges(); TestRange range = testRanges.get(0); Map<Integer, Integer> result = keyspace.prepareQuery(CF_POPULATION) .getKeyRange(null, null, range.start, range.end, 100) .getColumnCounts() .execute().getResult(); Map<Integer, Integer> expected = new HashMap<Integer, Integer>(); if (!rowDeleted) { for (Integer year : range.expectedRowKeys) { expected.put(year, 4); } } Assert.assertEquals(expected, result); }
private void testColumnCountRowRangeAndAllColumns(boolean rowDeleted) throws Exception { List<TestTokenRange> testRanges = TestUtils.getTestTokenRanges(); Map<String, Integer> expectedRowCounts = rowDeleted ? new HashMap<String, Integer>() : getExpectedRowCountsForTokenRanges(testRanges, 26); Map<String, Integer> resultRowCounts = new HashMap<String, Integer>(); for (TestTokenRange testRange : testRanges) { Map<String, Integer> rowCounts = keyspace.prepareQuery(CF_COLUMN_RANGE_TEST) .getRowRange(null, null, testRange.startToken, testRange.endToken, -1) .getColumnCounts() .execute().getResult(); resultRowCounts.putAll(rowCounts); } Assert.assertEquals(expectedRowCounts, resultRowCounts); }
private void testColumnCountRowRangeAndColumnRange(boolean rowDeleted) throws Exception { // Get the random start column int rand = new Random().nextInt(26); char randCH = (char) ('a' + rand); String startColumn = String.valueOf(randCH); int expectedColCount = 'z' - startColumn.charAt(0) + 1; List<TestTokenRange> testRanges = TestUtils.getTestTokenRanges(); Map<String, Integer> expectedRowCounts = rowDeleted ? new HashMap<String, Integer>() : getExpectedRowCountsForTokenRanges(testRanges, expectedColCount); Map<String, Integer> resultRowCounts = new HashMap<String, Integer>(); for (TestTokenRange testRange : testRanges) { Map<String, Integer> rowCounts = keyspace.prepareQuery(CF_COLUMN_RANGE_TEST) .getRowRange(null, null, testRange.startToken, testRange.endToken, -1) .withColumnRange(startColumn, "z", false, -1) .getColumnCounts() .execute().getResult(); resultRowCounts.putAll(rowCounts); } Assert.assertEquals(expectedRowCounts, resultRowCounts); }
private void testColumnCountRowRangeAndColumnSet(boolean rowDeleted) throws Exception { Collection<String> columns = getRandomColumns(new Random().nextInt(26) + 1); List<TestTokenRange> testRanges = TestUtils.getTestTokenRanges(); Map<String, Integer> expectedRowCounts = rowDeleted ? new HashMap<String, Integer>() : getExpectedRowCountsForTokenRanges(testRanges, columns.size()); Map<String, Integer> resultRowCounts = new HashMap<String, Integer>(); for (TestTokenRange testRange : testRanges) { Map<String, Integer> rowCounts = keyspace.prepareQuery(CF_COLUMN_RANGE_TEST) .getRowRange(null, null, testRange.startToken, testRange.endToken, -1) .withColumnSlice(columns) .getColumnCounts() .execute().getResult(); resultRowCounts.putAll(rowCounts); } Assert.assertEquals(expectedRowCounts, resultRowCounts); }
private void testColumnCountMultipleRowKeysAndAllColumns(boolean rowDeleted) throws Exception { Collection<String> rowKeys = getRandomRowKeys(); Map<String, Integer> columnCountsPerRowKey = keyspace .prepareQuery(CF_COLUMN_RANGE_TEST) .getRowSlice(rowKeys) .getColumnCounts() .execute().getResult(); Map<String, Integer> expected = new HashMap<String, Integer>(); if (!rowDeleted) { for (String key : rowKeys) { expected.put(key, 26); } } Assert.assertEquals("expected: " + expected + " colCount: " + columnCountsPerRowKey, expected, columnCountsPerRowKey); }
private void testColumnCountMultipleRowKeysAndColumnRange(boolean rowDeleted) throws Exception { Collection<String> rowKeys = getRandomRowKeys(); // Get a random start column int rand = new Random().nextInt(26); char randCH = (char) ('a' + rand); String startCol = String.valueOf(randCH); Map<String, Integer> columnCountsPerRowKey = keyspace .prepareQuery(CF_COLUMN_RANGE_TEST) .getRowSlice(rowKeys) .withColumnRange(startCol, "z", false, -1) .getColumnCounts() .execute().getResult(); int charOffset = startCol.charAt(0) - 'a' + 1; int expectedColCount = 26 - charOffset + 1; Map<String, Integer> expected = new HashMap<String, Integer>(); if (!rowDeleted) { for (String key : rowKeys) { expected.put(key, expectedColCount); } } Assert.assertEquals("expected: " + expected + " colCount: " + columnCountsPerRowKey, expected, columnCountsPerRowKey); }
private void testColumnCountMultipleRowKeysAndColumnSet(boolean rowDeleted) throws Exception { Collection<String> rowKeys = getRandomRowKeys(); Collection<String> columns = getRandomColumns(new Random().nextInt(26) + 1); Map<String, Integer> columnCountsPerRowKey = keyspace .prepareQuery(CF_COLUMN_RANGE_TEST) .getRowSlice(rowKeys) .withColumnSlice(columns) .getColumnCounts() .execute().getResult(); Map<String, Integer> expected = new HashMap<String, Integer>(); if (!rowDeleted) { for (String key : rowKeys) { expected.put(key, columns.size()); } } Assert.assertEquals("expected: " + expected + " colCount: " + columnCountsPerRowKey, expected, columnCountsPerRowKey); }
@Test public void testGetAllKeysPath() throws ConnectionException { LOG.info("Starting testGetAllKeysPath..."); List<String> keys = new ArrayList<String>(); for (char key = 'A'; key <= 'Z'; key++) { String keyName = Character.toString(key); keys.add(keyName); } OperationResult<Rows<String, String>> result = keyspace .prepareQuery(CF_STANDARD1) .getKeySlice(keys.toArray(new String[keys.size()])) .execute(); for (Row<String, String> row : result.getResult()) { System.out.println(row.getColumns().size()); } OperationResult<Map<String, Integer>> counts = keyspace .prepareQuery(CF_STANDARD1) .getKeySlice(keys.toArray(new String[keys.size()])) .getColumnCounts() .execute(); Assert.assertEquals(26, counts.getResult().size()); for (Entry<String, Integer> count : counts.getResult().entrySet()) { Assert.assertEquals(new Integer(26), count.getValue()); } LOG.info("Starting testGetAllKeysPath..."); }
@Override public Map<String, Integer> getShardCounts() throws MessageQueueException { try { List<String> keys = Lists.newArrayList(); for (int i = 0; i < metadata.getPartitionCount(); i++) { for (int j = 0; j < metadata.getShardCount(); j++) { keys.add(getName() + ":" + i + ":" + j); } } Map<String, Integer> result = Maps.newTreeMap(); result.putAll(keyspace.prepareQuery(queueColumnFamily) .getKeySlice(keys) .getColumnCounts() .execute() .getResult()); return result; } catch (ConnectionException e) { throw new MessageQueueException("Failed to get counts", e); } }