Skip to content

Commit

Permalink
fix: Use org.threeten.bp.Duration for ReadChangeStreamQuery::heartbea…
Browse files Browse the repository at this point in the history
…tDura… (#1652)

…tion

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).
  • Loading branch information
tengzhonger committed Feb 28, 2023
1 parent 5ba3d61 commit 87261a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Expand Up @@ -182,7 +182,7 @@ public ReadChangeStreamQuery continuationTokens(
}

/** Sets the heartbeat duration for the change stream. */
public ReadChangeStreamQuery heartbeatDuration(java.time.Duration duration) {
public ReadChangeStreamQuery heartbeatDuration(org.threeten.bp.Duration duration) {
builder.setHeartbeatDuration(
Duration.newBuilder()
.setSeconds(duration.getSeconds())
Expand Down
Expand Up @@ -152,11 +152,11 @@ public void endTimeTest() {
@Test
public void heartbeatDurationTest() {
ReadChangeStreamQuery query =
ReadChangeStreamQuery.create(TABLE_ID).heartbeatDuration(java.time.Duration.ofSeconds(5));
ReadChangeStreamQuery.create(TABLE_ID)
.heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5));

Builder expectedProto =
expectedProtoBuilder()
.setHeartbeatDuration(com.google.protobuf.Duration.newBuilder().setSeconds(5).build());
expectedProtoBuilder().setHeartbeatDuration(Duration.newBuilder().setSeconds(5).build());

ReadChangeStreamRequest actualProto = query.toProto(requestContext);
assertThat(actualProto).isEqualTo(expectedProto.build());
Expand Down Expand Up @@ -232,7 +232,7 @@ public void serializationTest() throws IOException, ClassNotFoundException {
.streamPartition("simple-begin", "simple-end")
.continuationTokens(Collections.singletonList(token))
.endTime(FAKE_END_TIME)
.heartbeatDuration(java.time.Duration.ofSeconds(5));
.heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5));

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
Expand Down Expand Up @@ -302,7 +302,7 @@ public void testEquality() {
.streamPartition("simple-begin", "simple-end")
.startTime(FAKE_START_TIME)
.endTime(FAKE_END_TIME)
.heartbeatDuration(java.time.Duration.ofSeconds(5));
.heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5));

// ReadChangeStreamQuery#toProto should not change the ReadChangeStreamQuery instance state
request.toProto(requestContext);
Expand All @@ -312,7 +312,7 @@ public void testEquality() {
.streamPartition("simple-begin", "simple-end")
.startTime(FAKE_START_TIME)
.endTime(FAKE_END_TIME)
.heartbeatDuration(java.time.Duration.ofSeconds(5)));
.heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5)));

assertThat(ReadChangeStreamQuery.create(TABLE_ID).streamPartition("begin-1", "end-1"))
.isNotEqualTo(ReadChangeStreamQuery.create(TABLE_ID).streamPartition("begin-2", "end-1"));
Expand All @@ -324,10 +324,10 @@ public void testEquality() {
ReadChangeStreamQuery.create(TABLE_ID).endTime(Instant.ofEpochSecond(1L, 1001L)));
assertThat(
ReadChangeStreamQuery.create(TABLE_ID)
.heartbeatDuration(java.time.Duration.ofSeconds(5)))
.heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5)))
.isNotEqualTo(
ReadChangeStreamQuery.create(TABLE_ID)
.heartbeatDuration(java.time.Duration.ofSeconds(6)));
.heartbeatDuration(org.threeten.bp.Duration.ofSeconds(6)));
}

@Test
Expand All @@ -350,7 +350,7 @@ public void testClone() {
.streamPartition("begin", "end")
.continuationTokens(Collections.singletonList(token))
.endTime(FAKE_END_TIME)
.heartbeatDuration(java.time.Duration.ofSeconds(5));
.heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5));
ReadChangeStreamRequest request =
ReadChangeStreamRequest.newBuilder()
.setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID))
Expand Down
Expand Up @@ -21,10 +21,10 @@
import com.google.cloud.bigtable.data.v2.models.ReadChangeStreamQuery;
import com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable;
import com.google.common.truth.Truth;
import java.time.Duration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.threeten.bp.Duration;
import org.threeten.bp.Instant;

@RunWith(JUnit4.class)
Expand Down

0 comments on commit 87261a9

Please sign in to comment.