Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ public boolean start() {

@Override
public boolean advance() {
if (current >= numMessagesPerShard) {
if (current >= numMessagesPerShard - 1) {
return false;
}
Copy link
Contributor

@dhalperi dhalperi Apr 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be reordered below the if below it? Probably little harm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this order - if done early exit, if want to repeat repeat, otherwise advance to valid position.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. just confirming it's okay that you can't repeat the last element.

// If testing dedup, occasionally insert a duplicate value;
if (current >= 0 && dedup && ThreadLocalRandom.current().nextInt(5) == 0) {
return true;
}
current++;
return current < numMessagesPerShard;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,22 @@ public void testRespectsCheckpointContract() throws IOException {
assertEquals(2L, (long) reader.getCurrent().getValue());
assertFalse(reader.advance());
}

@Test
public void testCanResumeWithExpandedCount() throws IOException {
TestCountingSource source = new TestCountingSource(1);
PipelineOptions options = PipelineOptionsFactory.create();
TestCountingSource.CountingSourceReader reader =
source.createReader(options, null /* no checkpoint */);
assertTrue(reader.start());
assertEquals(0L, (long) reader.getCurrent().getValue());
assertFalse(reader.advance());
TestCountingSource.CounterMark checkpoint = reader.getCheckpointMark();
checkpoint.finalizeCheckpoint();
source = new TestCountingSource(2);
reader = source.createReader(options, checkpoint);
assertTrue(reader.start());
assertEquals(1L, (long) reader.getCurrent().getValue());
assertFalse(reader.advance());
}
}