Skip to content

Commit

Permalink
use threeten methods in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomarquezp committed Dec 11, 2024
1 parent 540b19d commit ce6a279
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import com.google.api.gax.rpc.StatusCode.Code;
import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStubSettings;
import java.io.IOException;
import java.time.Duration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;
import org.threeten.bp.Duration;

@RunWith(JUnit4.class)
public class BigtableInstanceAdminSettingsTest {
Expand Down Expand Up @@ -139,7 +139,7 @@ public void testToString() throws IOException {
stubSettings
.getInstanceSettings()
.setRetrySettings(
RetrySettings.newBuilder().setTotalTimeoutDuration(Duration.ofMinutes(812)).build());
RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(812)).build());

BigtableInstanceAdminSettings settings = builder.build();
checkToString(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void testToString() throws IOException {
.getBackupSettings()
.setRetrySettings(
RetrySettings.newBuilder()
.setTotalTimeoutDuration(java.time.Duration.ofMinutes(812))
.setTotalTimeout(org.threeten.bp.Duration.ofMinutes(812))
.build());

BigtableTableAdminSettings settings = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.bigtable.admin.v2.TableName;
import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest;
import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext;
import java.time.Duration;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
Expand All @@ -48,6 +47,7 @@
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import org.threeten.bp.Duration;

@RunWith(JUnit4.class)
public class AwaitConsistencyCallableTest {
Expand Down Expand Up @@ -80,14 +80,14 @@ public void setUp() {

RetrySettings retrySettings =
RetrySettings.newBuilder()
.setTotalTimeoutDuration(Duration.ofMillis(100))
.setTotalTimeout(Duration.ofMillis(100))
// Delay settings: 1 ms const
.setInitialRetryDelayDuration(Duration.ofMillis(1))
.setMaxRetryDelayDuration(Duration.ofMillis(1))
.setInitialRetryDelay(Duration.ofMillis(1))
.setMaxRetryDelay(Duration.ofMillis(1))
.setRetryDelayMultiplier(1.0)
// RPC timeout: ignored const 1 s
.setInitialRpcTimeoutDuration(Duration.ofSeconds(1))
.setMaxRpcTimeoutDuration(Duration.ofSeconds(1))
.setInitialRpcTimeout(Duration.ofSeconds(1))
.setMaxRpcTimeout(Duration.ofSeconds(1))
.setRpcTimeoutMultiplier(1.0)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv;
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
import java.io.IOException;
import java.time.Duration;
import java.util.Objects;
import java.util.UUID;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.threeten.bp.Duration;

@RunWith(JUnit4.class)
public class BulkMutateIT {
Expand Down Expand Up @@ -158,7 +158,7 @@ public void testManyMutations() throws IOException, InterruptedException {
.stubSettings()
.bulkMutateRowsSettings()
.setBatchingSettings(
batchingSettings.toBuilder().setDelayThresholdDuration(Duration.ofHours(1)).build());
batchingSettings.toBuilder().setDelayThreshold(Duration.ofHours(1)).build());
try (BigtableDataClient client = BigtableDataClient.create(settings);
BatcherImpl<RowMutationEntry, Void, BulkMutation, Void> batcher =
(BatcherImpl<RowMutationEntry, Void, BulkMutation, Void>)
Expand Down Expand Up @@ -207,7 +207,7 @@ public void testManyMutationsOnAuthorizedView() throws IOException, InterruptedE
.stubSettings()
.bulkMutateRowsSettings()
.setBatchingSettings(
batchingSettings.toBuilder().setDelayThresholdDuration(Duration.ofHours(1)).build());
batchingSettings.toBuilder().setDelayThreshold(Duration.ofHours(1)).build());
try (BigtableDataClient client = BigtableDataClient.create(settings);
Batcher<RowMutationEntry, Void> batcher =
client.newBulkMutationBatcher(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.cloud.bigtable.data.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant;
import static com.google.common.truth.Truth.assertThat;

import com.google.bigtable.v2.MutateRowRequest;
Expand Down Expand Up @@ -45,6 +46,10 @@ public class ChangeStreamMutationTest {
RequestContext.create(PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID);
private static final Instant FAKE_COMMIT_TIMESTAMP = Instant.ofEpochSecond(0, 1000L);
private static final Instant FAKE_LOW_WATERMARK = Instant.ofEpochSecond(0, 2000L);
private static final org.threeten.bp.Instant FAKE_COMMIT_TIMESTAMP_THREETEN =
toThreetenInstant(FAKE_COMMIT_TIMESTAMP);
private static final org.threeten.bp.Instant FAKE_LOW_WATERMARK_THREETEN =
toThreetenInstant(FAKE_LOW_WATERMARK);

@Test
public void userInitiatedMutationTest() throws IOException, ClassNotFoundException {
Expand Down Expand Up @@ -81,9 +86,12 @@ public void userInitiatedMutationTest() throws IOException, ClassNotFoundExcepti
assertThat(changeStreamMutation.getType()).isEqualTo(ChangeStreamMutation.MutationType.USER);
assertThat(changeStreamMutation.getSourceClusterId()).isEqualTo("fake-source-cluster-id");
assertThat(changeStreamMutation.getCommitTime()).isEqualTo(FAKE_COMMIT_TIMESTAMP);
assertThat(changeStreamMutation.getCommitTimestamp()).isEqualTo(FAKE_COMMIT_TIMESTAMP_THREETEN);
assertThat(changeStreamMutation.getTieBreaker()).isEqualTo(0);
assertThat(changeStreamMutation.getToken()).isEqualTo("fake-token");
assertThat(changeStreamMutation.getEstimatedLowWatermarkTime()).isEqualTo(FAKE_LOW_WATERMARK);
assertThat(changeStreamMutation.getEstimatedLowWatermark())
.isEqualTo(FAKE_LOW_WATERMARK_THREETEN);

// Test serialization.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down Expand Up @@ -112,7 +120,7 @@ public void gcMutationTest() throws IOException, ClassNotFoundException {
ByteString.copyFromUtf8("fake-qualifier"),
Range.TimestampRange.create(1000L, 2000L))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

// Test the getters.
Expand All @@ -121,9 +129,12 @@ public void gcMutationTest() throws IOException, ClassNotFoundException {
.isEqualTo(ChangeStreamMutation.MutationType.GARBAGE_COLLECTION);
Assert.assertTrue(changeStreamMutation.getSourceClusterId().isEmpty());
assertThat(changeStreamMutation.getCommitTime()).isEqualTo(FAKE_COMMIT_TIMESTAMP);
assertThat(changeStreamMutation.getCommitTimestamp()).isEqualTo(FAKE_COMMIT_TIMESTAMP_THREETEN);
assertThat(changeStreamMutation.getTieBreaker()).isEqualTo(0);
assertThat(changeStreamMutation.getToken()).isEqualTo("fake-token");
assertThat(changeStreamMutation.getEstimatedLowWatermarkTime()).isEqualTo(FAKE_LOW_WATERMARK);
assertThat(changeStreamMutation.getEstimatedLowWatermark())
.isEqualTo(FAKE_LOW_WATERMARK_THREETEN);

// Test serialization.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down Expand Up @@ -161,7 +172,7 @@ public void toRowMutationTest() {
Value.rawTimestamp(1000),
Value.rawValue(ByteString.copyFrom(Longs.toByteArray(1234L))))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

// Convert it to a rowMutation and construct a MutateRowRequest.
Expand Down Expand Up @@ -204,7 +215,7 @@ public void toRowMutationWithoutTokenShouldFailTest() {
ChangeStreamMutation.createUserMutation(
ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0)
.deleteFamily("fake-family")
.setLowWatermarkTime(FAKE_LOW_WATERMARK);
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN);
Assert.assertThrows(IllegalStateException.class, builder::build);
}

Expand Down Expand Up @@ -244,7 +255,7 @@ public void toRowMutationEntryTest() {
Value.rawTimestamp(1000),
Value.rawValue(ByteString.copyFrom(Longs.toByteArray(1234L))))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

// Convert it to a rowMutationEntry and construct a MutateRowRequest.
Expand Down Expand Up @@ -284,7 +295,7 @@ public void toRowMutationEntryWithoutTokenShouldFailTest() {
ChangeStreamMutation.createUserMutation(
ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0)
.deleteFamily("fake-family")
.setLowWatermarkTime(FAKE_LOW_WATERMARK);
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN);
Assert.assertThrows(IllegalStateException.class, builder::build);
}

Expand All @@ -309,7 +320,7 @@ public void testWithLongValue() {
1000L,
ByteString.copyFrom(Longs.toByteArray(1L)))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

RowMutation rowMutation = changeStreamMutation.toRowMutation(TABLE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.cloud.bigtable.data.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant;
import static com.google.common.truth.Truth.assertThat;

import com.google.bigtable.v2.Mutation;
Expand All @@ -41,6 +42,8 @@ public class DefaultChangeStreamRecordAdapterTest {
private ChangeStreamRecordBuilder<ChangeStreamRecord> changeStreamRecordBuilder;
private static final Instant FAKE_COMMIT_TIMESTAMP = Instant.ofEpochSecond(0L, 1000L);
private static final Instant FAKE_LOW_WATERMARK = Instant.ofEpochSecond(0L, 2000L);
private static final org.threeten.bp.Instant FAKE_LOW_WATERMARK_THREETEN =
toThreetenInstant(FAKE_LOW_WATERMARK);

@Rule public ExpectedException expect = ExpectedException.none();

Expand All @@ -59,7 +62,7 @@ public void isHeartbeatTest() {
ChangeStreamMutation.createGcMutation(
ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0)
.setToken("token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();
Assert.assertTrue(adapter.isHeartbeat(heartbeatRecord));
Assert.assertFalse(adapter.isHeartbeat(closeStreamRecord));
Expand All @@ -73,8 +76,8 @@ public void getTokenFromHeartbeatTest() {
ReadChangeStreamResponse.Heartbeat.newBuilder()
.setEstimatedLowWatermark(
Timestamp.newBuilder()
.setSeconds(FAKE_LOW_WATERMARK.getEpochSecond())
.setNanos(FAKE_LOW_WATERMARK.getNano()))
.setSeconds(FAKE_LOW_WATERMARK_THREETEN.getEpochSecond())
.setNanos(FAKE_LOW_WATERMARK_THREETEN.getNano()))
.setContinuationToken(
StreamContinuationToken.newBuilder().setToken("heartbeat-token").build())
.build());
Expand All @@ -99,7 +102,7 @@ public void isChangeStreamMutationTest() {
ChangeStreamMutation.createGcMutation(
ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0)
.setToken("token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();
Assert.assertFalse(adapter.isChangeStreamMutation(heartbeatRecord));
Assert.assertFalse(adapter.isChangeStreamMutation(closeStreamRecord));
Expand All @@ -112,7 +115,7 @@ public void getTokenFromChangeStreamMutationTest() {
ChangeStreamMutation.createGcMutation(
ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0)
.setToken("change-stream-mutation-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();
Assert.assertEquals(
adapter.getTokenFromChangeStreamMutation(changeStreamMutationRecord),
Expand All @@ -133,8 +136,8 @@ public void heartbeatTest() {
ReadChangeStreamResponse.Heartbeat.newBuilder()
.setEstimatedLowWatermark(
Timestamp.newBuilder()
.setSeconds(FAKE_LOW_WATERMARK.getEpochSecond())
.setNanos(FAKE_LOW_WATERMARK.getNano())
.setSeconds(FAKE_LOW_WATERMARK_THREETEN.getEpochSecond())
.setNanos(FAKE_LOW_WATERMARK_THREETEN.getNano())
.build())
.setContinuationToken(
StreamContinuationToken.newBuilder().setToken("random-token").build())
Expand Down Expand Up @@ -186,7 +189,7 @@ public void singleDeleteFamilyTest() {
ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0)
.deleteFamily("fake-family")
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

// Create the ChangeStreamMutation through the ChangeStreamRecordBuilder.
Expand Down Expand Up @@ -225,7 +228,7 @@ public void singleDeleteCellTest() {
ByteString.copyFromUtf8("fake-qualifier"),
Range.TimestampRange.create(1000L, 2000L))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

// Create the ChangeStreamMutation through the ChangeStreamRecordBuilder.
Expand Down Expand Up @@ -258,7 +261,7 @@ public void singleNonChunkedCellTest() {
100L,
ByteString.copyFromUtf8("fake-value"))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

// Create the ChangeStreamMutation through the ChangeStreamRecordBuilder.
Expand Down Expand Up @@ -290,7 +293,7 @@ public void singleChunkedCellTest() {
100L,
ByteString.copyFromUtf8("fake-value1-value2"))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

// Create the ChangeStreamMutation through the ChangeStreamRecordBuilder.
Expand Down Expand Up @@ -327,7 +330,7 @@ public void multipleChunkedCellsTest() {
}
expectedChangeStreamMutationBuilder
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK);
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN);

// Create the ChangeStreamMutation through the ChangeStreamRecordBuilder.
changeStreamRecordBuilder.startUserMutation(
Expand Down Expand Up @@ -369,7 +372,7 @@ public void multipleDifferentModsTest() {
100L,
ByteString.copyFromUtf8("chunked-value"))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK);
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN);

// Create the ChangeStreamMutation through the ChangeStreamRecordBuilder.
changeStreamRecordBuilder.startUserMutation(
Expand Down Expand Up @@ -418,7 +421,7 @@ public void resetTest() {
ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0)
.deleteFamily("fake-family")
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();
changeStreamRecordBuilder.startUserMutation(
ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0);
Expand All @@ -438,7 +441,7 @@ public void resetTest() {
100L,
ByteString.copyFromUtf8("fake-value1-value2"))
.setToken("fake-token")
.setLowWatermarkTime(FAKE_LOW_WATERMARK)
.setEstimatedLowWatermark(FAKE_LOW_WATERMARK_THREETEN)
.build();

changeStreamRecordBuilder.startUserMutation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import com.google.api.gax.rpc.StatusCode;
import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor;
import com.google.common.collect.ImmutableSet;
import java.time.Duration;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.threeten.bp.Duration;

@RunWith(JUnit4.class)
public class BigtableBatchingCallSettingsTest {
Expand All @@ -38,7 +38,7 @@ public class BigtableBatchingCallSettingsTest {
BatchingSettings.newBuilder()
.setElementCountThreshold(10L)
.setRequestByteThreshold(20L)
.setDelayThresholdDuration(Duration.ofMillis(5))
.setDelayThreshold(Duration.ofMillis(5))
.setFlowControlSettings(
FlowControlSettings.newBuilder()
.setMaxOutstandingElementCount(100L)
Expand Down Expand Up @@ -111,7 +111,7 @@ public void testBuilderFromSettings() {
BigtableBatchingCallSettings.Builder builder =
BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor());
RetrySettings retrySettings =
RetrySettings.newBuilder().setTotalTimeoutDuration(Duration.ofMinutes(1)).build();
RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build();
builder
.setBatchingSettings(BATCHING_SETTINGS)
.setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import com.google.api.gax.rpc.StatusCode;
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor;
import com.google.common.collect.ImmutableSet;
import java.time.Duration;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.threeten.bp.Duration;

@RunWith(JUnit4.class)
public class BigtableBulkReadRowsCallSettingsTest {
Expand All @@ -37,7 +37,7 @@ public class BigtableBulkReadRowsCallSettingsTest {
BatchingSettings.newBuilder()
.setElementCountThreshold(10L)
.setRequestByteThreshold(20L)
.setDelayThresholdDuration(Duration.ofMillis(5))
.setDelayThreshold(Duration.ofMillis(5))
.setFlowControlSettings(
FlowControlSettings.newBuilder()
.setMaxOutstandingElementCount(100L)
Expand Down Expand Up @@ -78,7 +78,7 @@ public void testBuilderFromSettings() {
BigtableBulkReadRowsCallSettings.Builder builder =
BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor());
RetrySettings retrySettings =
RetrySettings.newBuilder().setTotalTimeoutDuration(Duration.ofMinutes(1)).build();
RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build();
builder
.setBatchingSettings(BATCHING_SETTINGS)
.setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED)
Expand Down
Loading

0 comments on commit ce6a279

Please sign in to comment.