Skip to content

Commit

Permalink
Do not enforce new_partitions and change_stream_continuation_tokens t…
Browse files Browse the repository at this point in the history
…o be the same size if new_partitions has size of 0 because Cloud Bigtable backend may not be updated to serve new_partitions field yet

Change-Id: I4e9b6507ff63df9f9ec9d57a0fc34e68e16f6e30
  • Loading branch information
tonytanger committed Mar 20, 2023
1 parent 74cebf3 commit d905e4f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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());
}
}

0 comments on commit d905e4f

Please sign in to comment.