Skip to content

Commit 07bcfd9

Browse files
authored
fix: if new_partitions is size 0, do not enforce size check (#1673)
Do not enforce new_partitions and change_stream_continuation_tokens to 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. `new_partitions` is a new field and the backend may not be serving this field. Change-Id: Id21c293b92c304f05b905ca8e8b3988b9241866e Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent b1f669d commit 07bcfd9

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/CloseStream.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ private static CloseStream create(
4848
!changeStreamContinuationTokens.isEmpty(),
4949
"A non-OK CloseStream should have continuation token(s).");
5050
Preconditions.checkState(
51-
changeStreamContinuationTokens.size() == newPartitions.size(),
51+
newPartitions.size() == 0
52+
|| changeStreamContinuationTokens.size() == newPartitions.size(),
5253
"Number of continuation tokens does not match number of new partitions.");
5354
}
5455
return new AutoValue_CloseStream(

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,45 @@ public void closeStreamTokenAndNewPartitionCountMismatchedTest() {
236236
StreamContinuationToken.newBuilder()
237237
.setPartition(StreamPartition.newBuilder().setRowRange(rowRange))
238238
.setToken(token))
239+
.addNewPartitions(StreamPartition.newBuilder().setRowRange(rowRange))
240+
.addNewPartitions(StreamPartition.newBuilder().setRowRange(rowRange))
239241
.setStatus(status)
240242
.build();
241243
Assert.assertThrows(
242244
IllegalStateException.class, (ThrowingRunnable) CloseStream.fromProto(closeStreamProto));
243245
}
246+
247+
// Tests that number of continuation tokens and new partitions don't need to match if new
248+
// partitions is empty.
249+
@Test
250+
public void closeStreamTokenAndZeroNewPartitionMismatchNoExceptionTest()
251+
throws IOException, ClassNotFoundException {
252+
Status status = Status.newBuilder().setCode(11).build();
253+
RowRange rowRange =
254+
RowRange.newBuilder()
255+
.setStartKeyClosed(ByteString.copyFromUtf8(""))
256+
.setEndKeyOpen(ByteString.copyFromUtf8("apple"))
257+
.build();
258+
String token = "close-stream-token-1";
259+
ReadChangeStreamResponse.CloseStream closeStreamProto =
260+
ReadChangeStreamResponse.CloseStream.newBuilder()
261+
.addContinuationTokens(
262+
StreamContinuationToken.newBuilder()
263+
.setPartition(StreamPartition.newBuilder().setRowRange(rowRange))
264+
.setToken(token))
265+
.setStatus(status)
266+
.build();
267+
CloseStream closeStream = CloseStream.fromProto(closeStreamProto);
268+
269+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
270+
ObjectOutputStream oos = new ObjectOutputStream(bos);
271+
oos.writeObject(closeStream);
272+
oos.close();
273+
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
274+
CloseStream actual = (CloseStream) ois.readObject();
275+
assertThat(actual.getChangeStreamContinuationTokens())
276+
.isEqualTo(closeStream.getChangeStreamContinuationTokens());
277+
assertThat(actual.getStatus()).isEqualTo(closeStream.getStatus());
278+
assertThat(actual.getNewPartitions()).isEqualTo(closeStream.getNewPartitions());
279+
}
244280
}

0 commit comments

Comments
 (0)