@Test public void attemptingToDecreaseSweptTimestampIsNoop() { progress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 1024L); progress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 512L); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TEN)).isEqualTo(1024L); }
private void progressTo(ShardAndStrategy shardStrategy, long newProgress) { if (newProgress < 0) { log.warn("Wasn't able to progress targeted sweep for {} since last swept timestamp {} is negative.", SafeArg.of("shardStrategy", shardStrategy.toText()), SafeArg.of("timestamp", newProgress)); return; } progress.updateLastSweptTimestamp(shardStrategy, newProgress); log.debug("Progressed last swept timestamp for {} to {}.", SafeArg.of("shardStrategy", shardStrategy.toText()), SafeArg.of("timestamp", newProgress)); }
@Test public void updatingTimestampForOneShardDoesNotAffectOthers() { assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TEN)).isEqualTo(INITIAL_TIMESTAMP); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TWENTY)).isEqualTo(INITIAL_TIMESTAMP); progress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 1024L); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TWENTY)).isEqualTo(INITIAL_TIMESTAMP); progress.updateLastSweptTimestamp(CONSERVATIVE_TWENTY, 512L); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TWENTY)).isEqualTo(512L); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TEN)).isEqualTo(1024L); }
@Test public void canUpdateSweptTimestamp() { progress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 1024L); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TEN)).isEqualTo(1024L); }
@Test public void updatingTimestampForOneConsistencyDoesNotAffectOther() { assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TEN)).isEqualTo(INITIAL_TIMESTAMP); assertThat(progress.getLastSweptTimestamp(THOROUGH_TEN)).isEqualTo(INITIAL_TIMESTAMP); progress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 128L); assertThat(progress.getLastSweptTimestamp(THOROUGH_TEN)).isEqualTo(INITIAL_TIMESTAMP); progress.updateLastSweptTimestamp(THOROUGH_TEN, 32L); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TEN)).isEqualTo(128L); assertThat(progress.getLastSweptTimestamp(THOROUGH_TEN)).isEqualTo(32L); }
@Test public void updatingTimestampsDoesNotAffectShardsAndViceVersa() { assertThat(progress.getNumberOfShards()).isEqualTo(AtlasDbConstants.DEFAULT_SWEEP_QUEUE_SHARDS); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TEN)).isEqualTo(INITIAL_TIMESTAMP); assertThat(progress.getLastSweptTimestamp(THOROUGH_TEN)).isEqualTo(INITIAL_TIMESTAMP); progress.updateNumberOfShards(64); progress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 32L); progress.updateLastSweptTimestamp(THOROUGH_TEN, 128L); assertThat(progress.getNumberOfShards()).isEqualTo(64); assertThat(progress.getLastSweptTimestamp(CONSERVATIVE_TEN)).isEqualTo(32L); assertThat(progress.getLastSweptTimestamp(THOROUGH_TEN)).isEqualTo(128L); }
@Test public void repeatedlyFailingCasThrows() { KeyValueService mockKvs = mock(KeyValueService.class); when(mockKvs.get(any(), anyMap())) .thenReturn(ImmutableMap.of()) .thenReturn(ImmutableMap.of(DUMMY, createValue(5L))) .thenReturn(ImmutableMap.of(DUMMY, createValue(10L))) .thenReturn(ImmutableMap.of(DUMMY, createValue(10L))); doThrow(new CheckAndSetException("sadness")).when(mockKvs).checkAndSet(any()); ShardProgress instrumentedProgress = new ShardProgress(mockKvs); assertThatThrownBy(() -> instrumentedProgress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 12L)) .isInstanceOf(CheckAndSetException.class); }
@Test public void progressivelyFailingCasEventuallySucceeds() { KeyValueService mockKvs = mock(KeyValueService.class); when(mockKvs.get(any(), anyMap())) .thenReturn(ImmutableMap.of()) .thenReturn(ImmutableMap.of(DUMMY, createValue(5L))) .thenReturn(ImmutableMap.of(DUMMY, createValue(10L))) .thenReturn(ImmutableMap.of(DUMMY, createValue(15L))); doThrow(new CheckAndSetException("sadness")).when(mockKvs).checkAndSet(any()); ShardProgress instrumentedProgress = new ShardProgress(mockKvs); assertThat(instrumentedProgress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 12L)) .isEqualTo(15L); }
@Test public void canReadNextWhenOtherShardsAndStrategiesProgressToEndOfPartitionForThorough() { progress.updateLastSweptTimestamp(thorough(shardCons), maxTsForFinePartition(TS2_FINE_PARTITION)); progress.updateLastSweptTimestamp(conservative(shardThor), maxTsForFinePartition(TS2_FINE_PARTITION)); progress.updateLastSweptTimestamp(conservative(shardCons), maxTsForFinePartition(TS2_FINE_PARTITION)); assertThat(readThorough(shardThor)).contains(TS2_FINE_PARTITION); }
@Test public void canReadNextWhenOtherShardsAndStrategiesProgressToEndOfPartitionForConservative() { progress.updateLastSweptTimestamp(thorough(shardCons), maxTsForFinePartition(TS_FINE_PARTITION)); progress.updateLastSweptTimestamp(conservative(shardThor), maxTsForFinePartition(TS_FINE_PARTITION)); progress.updateLastSweptTimestamp(thorough(shardThor), maxTsForFinePartition(TS_FINE_PARTITION)); assertThat(readConservative(shardCons)).contains(TS_FINE_PARTITION); }
@Test public void canReadNextIfNotProgressedBeyondForConservative() { progress.updateLastSweptTimestamp(conservative(shardCons), TS - 1); assertThat(readConservative(shardCons)).contains(TS_FINE_PARTITION); }
@Test public void canReadNextIfNotProgressedBeyondForThorough() { progress.updateLastSweptTimestamp(thorough(shardThor), TS2 - 1); assertThat(readThorough(shardThor)).contains(TS2_FINE_PARTITION); }
@Test public void canReadNextTimestampIfProgressedBeyondButInSamePartitionForConservative() { progress.updateLastSweptTimestamp(conservative(shardCons), maxTsForFinePartition(TS_FINE_PARTITION) - 1); assertThat(readConservative(shardCons)).contains(TS_FINE_PARTITION); }
@Test public void noNextTimestampIfProgressedToEndOfPartitionForConservative() { progress.updateLastSweptTimestamp(conservative(shardCons), maxTsForFinePartition(TS_FINE_PARTITION)); assertThat(readConservative(shardCons)).isEmpty(); }
@Test public void canReadNextTimestampIfProgressedBeyondButInSamePartitionForForThorough() { progress.updateLastSweptTimestamp(thorough(shardThor), maxTsForFinePartition(TS2_FINE_PARTITION) - 1); assertThat(readThorough(shardThor)).contains(TS2_FINE_PARTITION); }
@Test public void noNextTimestampIfProgressedToEndOfPartitionForThorough() { progress.updateLastSweptTimestamp(thorough(shardThor), maxTsForFinePartition(TS2_FINE_PARTITION)); assertThat(readThorough(shardThor)).isEmpty(); }
@Test public void getCorrectNextTimestampWhenMultipleCandidates() { for (long timestamp = 1000L; tsPartitionFine(timestamp) < 10L; timestamp += TS_FINE_GRANULARITY / 5) { writeToDefaultCellCommitted(sweepableTimestamps, timestamp, TABLE_CONS); } assertThat(readConservative(shardCons)).contains(tsPartitionFine(1000L)); progress.updateLastSweptTimestamp(conservative(shardCons), 2L * TS_FINE_GRANULARITY); assertThat(readConservative(shardCons)).contains(tsPartitionFine(2L * TS_FINE_GRANULARITY + 1000L)); setSweepTimestampAndGet(4 * TS_FINE_GRANULARITY); assertThat(readConservative(shardCons)).contains(tsPartitionFine(2L * TS_FINE_GRANULARITY + 1000L)); }
private void progressTo(ShardAndStrategy shardStrategy, long newProgress) { if (newProgress < 0) { log.warn("Wasn't able to progress targeted sweep for {} since last swept timestamp {} is negative.", SafeArg.of("shardStrategy", shardStrategy.toText()), SafeArg.of("timestamp", newProgress)); return; } progress.updateLastSweptTimestamp(shardStrategy, newProgress); log.debug("Progressed last swept timestamp for {} to {}.", SafeArg.of("shardStrategy", shardStrategy.toText()), SafeArg.of("timestamp", newProgress)); }