CassandraTimestampUtils { public static void verifyCompatible(CqlResult casResult, Map<String, Pair<byte[], byte[]>> casMap) { if (!isSuccessfullyApplied(casResult)) { Set<Incongruency> incongruencies = getIncongruencies(casResult, casMap); if (!incongruencies.isEmpty()) { throw new IllegalStateException("[BACKUP/RESTORE] Observed incongruent state of the world; the" + " following incongruencies were observed: " + incongruencies); } log.debug("[BACKUP/RESTORE] CAS failed, but the DB state is as desired - continuing."); } } private  CassandraTimestampUtils(); static CqlQuery constructCheckAndSetMultipleQuery(Map<String, Pair<byte[], byte[]>> checkAndSetRequest); static boolean isValidTimestampData(byte[] data); static CqlQuery constructSelectFromTimestampTableQuery(); static Map<String, byte[]> getValuesFromSelectionResult(CqlResult result); static void verifyCompatible(CqlResult casResult, Map<String, Pair<byte[], byte[]>> casMap); static final String ROW_AND_COLUMN_NAME; static final String BACKUP_COLUMN_NAME; static final ByteString INVALIDATED_VALUE; static final long INITIAL_VALUE; }
@Test public void appliedResultIsCompatible() { CqlResult mockResult = createMockCqlResult( ImmutableList.of(createMockCqlRow(buildAppliedColumnList()))); CassandraTimestampUtils.verifyCompatible(mockResult, CAS_MAP_TWO_COLUMNS); }
@Test public void unappliedResultIsCompatibleIfTheStateOfTheWorldMatchesTargets() { CqlResult mockResult = createMockCqlResult( ImmutableList.of( createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_1, VALUE_1)), createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_2, VALUE_2)))); CassandraTimestampUtils.verifyCompatible(mockResult, CAS_MAP_TWO_COLUMNS); }
@Test public void unappliedResultIsCompatibleIfWeHaveExtraRows() { CqlResult mockResult = createMockCqlResult( ImmutableList.of( createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_1, VALUE_1)), createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_2, VALUE_2)), createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_3, VALUE_3)))); CassandraTimestampUtils.verifyCompatible(mockResult, CAS_MAP_TWO_COLUMNS); }
@Test public void unappliedResultIsIncompatibleIfTheStateOfTheWorldMatchesExpecteds() { CqlResult mockResult = createMockCqlResult( ImmutableList.of( createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_1, EMPTY_BYTE_ARRAY)), createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_2, EMPTY_BYTE_ARRAY)))); assertThatThrownBy(() -> CassandraTimestampUtils.verifyCompatible(mockResult, CAS_MAP_TWO_COLUMNS)) .isInstanceOf(IllegalStateException.class); }
@Test public void unappliedResultIsIncompatibleIfTheStateOfTheWorldIsIncorrect() { CqlResult mockResult = createMockCqlResult( ImmutableList.of( createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_1, VALUE_2)), createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_2, VALUE_1)))); assertThatThrownBy(() -> CassandraTimestampUtils.verifyCompatible(mockResult, CAS_MAP_TWO_COLUMNS)) .isInstanceOf(IllegalStateException.class); }
@Test public void unappliedResultIsIncompatibleIfWeHaveMissingRows() { CqlResult mockResult = createMockCqlResult( ImmutableList.of( createMockCqlRow(buildUnappliedColumnList(COLUMN_BYTES_1, VALUE_1)))); assertThatThrownBy(() -> CassandraTimestampUtils.verifyCompatible(mockResult, CAS_MAP_TWO_COLUMNS)) .isInstanceOf(IllegalStateException.class); }