- // No exceptions will be thrown when invalid chunk is added with the right sequence
- // If the lastChunkHashCode is missing
- SnapshotTracker tracker5 = new SnapshotTracker(logger, 2, "leader");
-
- tracker5.addChunk(LeaderInstallSnapshotState.FIRST_CHUNK_INDEX, chunk1, Optional.<Integer>absent());
- // Look I can add the same chunk again
- tracker5.addChunk(LeaderInstallSnapshotState.FIRST_CHUNK_INDEX + 1, chunk1, Optional.<Integer>absent());
-
- // An exception will be thrown when an invalid chunk is addedd with the right sequence
- // when the lastChunkHashCode is present
- SnapshotTracker tracker6 = new SnapshotTracker(logger, 2, "leader");
-
- tracker6.addChunk(LeaderInstallSnapshotState.FIRST_CHUNK_INDEX, chunk1, Optional.of(-1));
-
- try {
- // Here we add a second chunk and tell addChunk that the previous chunk had a hash code 777
- tracker6.addChunk(LeaderInstallSnapshotState.FIRST_CHUNK_INDEX + 1, chunk2, Optional.of(777));
- Assert.fail();
- } catch (SnapshotTracker.InvalidChunkException e) {
- // expected
+ @Test(expected = SnapshotTracker.InvalidChunkException.class)
+ public void testOutOfSequenceChunk() throws IOException {
+ try (SnapshotTracker tracker = new SnapshotTracker(LOG, 2, "leader", mockContext)) {
+ tracker.addChunk(1, chunk1, OptionalInt.empty());
+ tracker.addChunk(3, chunk3, OptionalInt.empty());