private static TableReference tableRef(TableClearsRow row) { return TableReference.fromString(row.getTable()); } }
private SortedMap<Long, Multimap<TableReference, Cell>> transformRows(List<RowResult<Value>> input) { SortedMap<Long, Multimap<TableReference, Cell>> scrubTimestampToTableNameToCell = Maps.newTreeMap(); for (RowResult<Value> rowResult : input) { byte[] row = rowResult.getRowName(); for (Entry<byte[], Value> entry : rowResult.getColumns().entrySet()) { byte[] fullCol = entry.getKey(); String table = EncodingUtils.decodeVarString(fullCol); byte[] col = Arrays.copyOfRange(fullCol, EncodingUtils.sizeOfVarString(table), fullCol.length); TableReference tableRef = TableReference.fromString(table); Cell cell = Cell.create(row, col); long timestamp = entry.getValue().getTimestamp(); Multimap<TableReference, Cell> cells = scrubTimestampToTableNameToCell.get(timestamp); if (cells == null) { cells = ArrayListMultimap.create(); scrubTimestampToTableNameToCell.put(timestamp, cells); } cells.put(tableRef, cell); } } return scrubTimestampToTableNameToCell; }
@Test public void cfDefWithDifferingGcGraceSecondsValuesShouldNotMatch() { CfDef clientSideTable = ColumnFamilyDefinitions.getCfDef( "test_keyspace", TableReference.fromString("test_table"), CassandraConstants.DEFAULT_GC_GRACE_SECONDS, AtlasDbConstants.GENERIC_TABLE_METADATA); CfDef clusterSideTable = ColumnFamilyDefinitions.getCfDef( "test_keyspace", TableReference.fromString("test_table"), FOUR_DAYS_IN_SECONDS, AtlasDbConstants.GENERIC_TABLE_METADATA); assertFalse("ColumnDefinitions with different gc_grace_seconds should not match", ColumnFamilyDefinitions.isMatchingCf(clientSideTable, clusterSideTable)); }
@Test public void nonDefaultFeaturesCorrectlyCompared() { CfDef cf1 = ColumnFamilyDefinitions.getCfDef( "test_keyspace", TableReference.fromString("test_table"), FOUR_DAYS_IN_SECONDS, TABLE_METADATA_WITH_MANY_NON_DEFAULT_FEATURES); CfDef cf2 = ColumnFamilyDefinitions.getCfDef( "test_keyspace", TableReference.fromString("test_table"), FOUR_DAYS_IN_SECONDS, TABLE_METADATA_WITH_MANY_NON_DEFAULT_FEATURES); assertTrue("identical CFs should equal each other", ColumnFamilyDefinitions.isMatchingCf(cf1, cf2)); }
@Test public void identicalCfsAreEqual() { CfDef cf1 = ColumnFamilyDefinitions.getCfDef( "test_keyspace", TableReference.fromString("test_table"), FOUR_DAYS_IN_SECONDS, AtlasDbConstants.GENERIC_TABLE_METADATA); CfDef cf2 = ColumnFamilyDefinitions.getCfDef( "test_keyspace", TableReference.fromString("test_table"), FOUR_DAYS_IN_SECONDS, AtlasDbConstants.GENERIC_TABLE_METADATA); assertTrue("identical CFs should equal each other", ColumnFamilyDefinitions.isMatchingCf(cf1, cf2)); } }
@Test public void testSingleEntryStore() { Cell cell = Cell.create(new byte[] {1, 2, 3}, new byte[] {4, 5, 6}); TableReference ref = TableReference.fromString("foo.bar"); long timestamp = 10; scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell, ref), timestamp, 1000); Assert.assertEquals( ImmutableList.of(ImmutableSortedMap.of(timestamp, ImmutableMultimap.of(ref, cell))), getScrubQueue()); scrubStore.markCellsAsScrubbed(ImmutableMap.of(ref, ImmutableMultimap.of(cell, timestamp)), 1000); Assert.assertEquals(ImmutableList.of(), getScrubQueue()); }
@Test public void testMultipleEntryStore() { Cell cell1 = Cell.create(new byte[] {1, 2, 3}, new byte[] {4, 5, 6}); Cell cell2 = Cell.create(new byte[] {7, 8, 9}, new byte[] {4, 5, 6}); Cell cell3 = Cell.create(new byte[] {1, 2, 3}, new byte[] {7, 8, 9}); TableReference ref1 = TableReference.fromString("foo.bar"); TableReference ref2 = TableReference.fromString("foo.baz"); long timestamp1 = 10; long timestamp2 = 20; scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell1, ref1, cell2, ref1), timestamp1, 1000); scrubStore.queueCellsForScrubbing(ImmutableMultimap.of(cell1, ref1, cell3, ref2), timestamp2, 1000); Assert.assertEquals( ImmutableList.of(ImmutableSortedMap.of( timestamp1, ImmutableMultimap.of(ref1, cell2), timestamp2, ImmutableMultimap.of(ref2, cell3, ref1, cell1))), getScrubQueue()); scrubStore.markCellsAsScrubbed(ImmutableMap.of( ref2, ImmutableMultimap.of(cell3, timestamp2), ref1, ImmutableMultimap.of(cell1, timestamp1, cell1, timestamp2)), 1000); Assert.assertEquals( ImmutableList.of(ImmutableSortedMap.of( timestamp1, ImmutableMultimap.of(ref1, cell2))), getScrubQueue()); }
@Test public void compactionStrategiesShouldMatchWithOrWithoutPackageName() { CfDef standard = ColumnFamilyDefinitions.getCfDef( "test_keyspace", TableReference.fromString("test_table"), CassandraConstants.DEFAULT_GC_GRACE_SECONDS, new byte[0]); CfDef fullyQualified = standard.setCompaction_strategy("com.palantir.AwesomeCompactionStrategy"); CfDef onlyClassName = standard.deepCopy().setCompaction_strategy("AwesomeCompactionStrategy"); assertTrue( String.format("Compaction strategies %s and %s should match", fullyQualified.compaction_strategy, onlyClassName.compaction_strategy), ColumnFamilyDefinitions.isMatchingCf(fullyQualified, onlyClassName)); }
private static TableReference tableRef(TableClearsRow row) { return TableReference.fromString(row.getTable()); } }
private SortedMap<Long, Multimap<TableReference, Cell>> transformRows(List<RowResult<Value>> input) { SortedMap<Long, Multimap<TableReference, Cell>> scrubTimestampToTableNameToCell = Maps.newTreeMap(); for (RowResult<Value> rowResult : input) { byte[] row = rowResult.getRowName(); for (Entry<byte[], Value> entry : rowResult.getColumns().entrySet()) { byte[] fullCol = entry.getKey(); String table = EncodingUtils.decodeVarString(fullCol); byte[] col = Arrays.copyOfRange(fullCol, EncodingUtils.sizeOfVarString(table), fullCol.length); TableReference tableRef = TableReference.fromString(table); Cell cell = Cell.create(row, col); long timestamp = entry.getValue().getTimestamp(); Multimap<TableReference, Cell> cells = scrubTimestampToTableNameToCell.get(timestamp); if (cells == null) { cells = ArrayListMultimap.create(); scrubTimestampToTableNameToCell.put(timestamp, cells); } cells.put(tableRef, cell); } } return scrubTimestampToTableNameToCell; }