Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: if new_partitions is size 0, do not enforce size check #1673

Merged
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 @@ -48,7 +48,8 @@ private static CloseStream create(
!changeStreamContinuationTokens.isEmpty(),
"A non-OK CloseStream should have continuation token(s).");
Preconditions.checkState(
changeStreamContinuationTokens.size() == newPartitions.size(),
newPartitions.size() == 0
|| changeStreamContinuationTokens.size() == newPartitions.size(),
"Number of continuation tokens does not match number of new partitions.");
}
return new AutoValue_CloseStream(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,45 @@ public void closeStreamTokenAndNewPartitionCountMismatchedTest() {
StreamContinuationToken.newBuilder()
.setPartition(StreamPartition.newBuilder().setRowRange(rowRange))
.setToken(token))
.addNewPartitions(StreamPartition.newBuilder().setRowRange(rowRange))
.addNewPartitions(StreamPartition.newBuilder().setRowRange(rowRange))
.setStatus(status)
.build();
Assert.assertThrows(
IllegalStateException.class, (ThrowingRunnable) CloseStream.fromProto(closeStreamProto));
}

// Tests that number of continuation tokens and new partitions don't need to match if new
// partitions is empty.
@Test
public void closeStreamTokenAndZeroNewPartitionMismatchNoExceptionTest()
throws IOException, ClassNotFoundException {
Status status = Status.newBuilder().setCode(11).build();
RowRange rowRange =
RowRange.newBuilder()
.setStartKeyClosed(ByteString.copyFromUtf8(""))
.setEndKeyOpen(ByteString.copyFromUtf8("apple"))
.build();
String token = "close-stream-token-1";
ReadChangeStreamResponse.CloseStream closeStreamProto =
ReadChangeStreamResponse.CloseStream.newBuilder()
.addContinuationTokens(
StreamContinuationToken.newBuilder()
.setPartition(StreamPartition.newBuilder().setRowRange(rowRange))
.setToken(token))
.setStatus(status)
.build();
CloseStream closeStream = CloseStream.fromProto(closeStreamProto);

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(closeStream);
oos.close();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
CloseStream actual = (CloseStream) ois.readObject();
assertThat(actual.getChangeStreamContinuationTokens())
.isEqualTo(closeStream.getChangeStreamContinuationTokens());
assertThat(actual.getStatus()).isEqualTo(closeStream.getStatus());
assertThat(actual.getNewPartitions()).isEqualTo(closeStream.getNewPartitions());
}
}