Skip to content
Merged
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 @@ -95,7 +95,7 @@ public Void apply(Iterable<KV<Integer, Integer>> input) {
Collections.sort(values);
for (int i = 0; i < values.size(); i++) {
assertEquals(i, (int) values.get(i));
}
}
if (finalizeTracker != null) {
assertThat(finalizeTracker, containsInAnyOrder(values.size() - 1));
}
Expand All @@ -110,7 +110,7 @@ private void test(boolean dedup, boolean timeBound) throws Exception {
finalizeTracker = new ArrayList<>();
TestCountingSource.setFinalizeTracker(finalizeTracker);
}
TestCountingSource source = new TestCountingSource(Integer.MAX_VALUE);
TestCountingSource source = new TestCountingSource(Integer.MAX_VALUE).withoutSplitting();
if (dedup) {
source = source.withDedup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class TestCountingSource
private final int shardNumber;
private final boolean dedup;
private final boolean throwOnFirstSnapshot;
private final boolean allowSplitting;

/**
* We only allow an exception to be thrown from getCheckpointMark
Expand All @@ -69,27 +70,36 @@ public static void setFinalizeTracker(List<Integer> finalizeTracker) {
}

public TestCountingSource(int numMessagesPerShard) {
this(numMessagesPerShard, 0, false, false);
this(numMessagesPerShard, 0, false, false, true);
}

public TestCountingSource withDedup() {
return new TestCountingSource(numMessagesPerShard, shardNumber, true, throwOnFirstSnapshot);
return new TestCountingSource(
numMessagesPerShard, shardNumber, true, throwOnFirstSnapshot, true);
}

private TestCountingSource withShardNumber(int shardNumber) {
return new TestCountingSource(numMessagesPerShard, shardNumber, dedup, throwOnFirstSnapshot);
return new TestCountingSource(
numMessagesPerShard, shardNumber, dedup, throwOnFirstSnapshot, true);
}

public TestCountingSource withThrowOnFirstSnapshot(boolean throwOnFirstSnapshot) {
return new TestCountingSource(numMessagesPerShard, shardNumber, dedup, throwOnFirstSnapshot);
return new TestCountingSource(
numMessagesPerShard, shardNumber, dedup, throwOnFirstSnapshot, true);
}

private TestCountingSource(
int numMessagesPerShard, int shardNumber, boolean dedup, boolean throwOnFirstSnapshot) {
public TestCountingSource withoutSplitting() {
return new TestCountingSource(
numMessagesPerShard, shardNumber, dedup, throwOnFirstSnapshot, false);
}

private TestCountingSource(int numMessagesPerShard, int shardNumber, boolean dedup,
boolean throwOnFirstSnapshot, boolean allowSplitting) {
this.numMessagesPerShard = numMessagesPerShard;
this.shardNumber = shardNumber;
this.dedup = dedup;
this.throwOnFirstSnapshot = throwOnFirstSnapshot;
this.allowSplitting = allowSplitting;
}

public int getShardNumber() {
Expand All @@ -100,7 +110,8 @@ public int getShardNumber() {
public List<TestCountingSource> generateInitialSplits(
int desiredNumSplits, PipelineOptions options) {
List<TestCountingSource> splits = new ArrayList<>();
for (int i = 0; i < desiredNumSplits; i++) {
int numSplits = allowSplitting ? desiredNumSplits : 1;
for (int i = 0; i < numSplits; i++) {
splits.add(withShardNumber(i));
}
return splits;
Expand Down