From 7c7f370a8ae31ab0f4611d775ae19e766f7d7085 Mon Sep 17 00:00:00 2001 From: suni72 Date: Tue, 14 Jul 2026 09:33:58 +0000 Subject: [PATCH 1/4] Refactor telemetry tests to follow AAA pattern --- .../telemetry/LoggingOpenTelemetryProviderTest.java | 6 +++--- .../telemetry/LoggingTelemetryOptionsTest.java | 8 ++++---- .../telemetry/LoggingTelemetryReporterTest.java | 10 +++++----- .../common/telemetry/OpenTelemetryOptionsTest.java | 12 ++++++------ .../common/telemetry/OpenTelemetryReporterTest.java | 2 +- .../common/telemetry/TelemetryOptionsTest.java | 12 ++++++------ 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingOpenTelemetryProviderTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingOpenTelemetryProviderTest.java index 6ceba672f..f51f5c577 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingOpenTelemetryProviderTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingOpenTelemetryProviderTest.java @@ -23,7 +23,7 @@ class LoggingOpenTelemetryProviderTest { @Test - void testGet_returnsNonNullInstance() { + void get_returnsNonNullInstance() { try (LoggingOpenTelemetryProvider provider = new LoggingOpenTelemetryProvider(OpenTelemetryOptions.builder().build())) { OpenTelemetry openTelemetry = provider.getOpenTelemetry(); @@ -33,7 +33,7 @@ void testGet_returnsNonNullInstance() { } @Test - void testGet_returnsSameInstanceOnMultipleCalls() { + void get_returnsSameInstanceOnMultipleCalls() { try (LoggingOpenTelemetryProvider provider = new LoggingOpenTelemetryProvider(OpenTelemetryOptions.builder().build())) { OpenTelemetry firstCall = provider.getOpenTelemetry(); @@ -44,7 +44,7 @@ void testGet_returnsSameInstanceOnMultipleCalls() { } @Test - void testConstructor_withDuration_createsSuccessfully() { + void constructor_withDuration_createsSuccessfully() { try (LoggingOpenTelemetryProvider provider = new LoggingOpenTelemetryProvider( OpenTelemetryOptions.builder().setExportIntervalSeconds(30).build())) { diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java index bb1fc4244..1de6e317b 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java @@ -25,7 +25,7 @@ class LoggingTelemetryOptionsTest { @Test - void testLoggingTelemetryOptionsDefaultValues() { + void loggingTelemetryOptionsDefaultValues() { LoggingTelemetryOptions options = LoggingTelemetryOptions.builder().build(); assertThat(options.isEnabled()).isFalse(); @@ -33,7 +33,7 @@ void testLoggingTelemetryOptionsDefaultValues() { } @Test - void testCreateFromOptions_NoOptions() { + void createFromOptions_NoOptions() { Map options = new HashMap<>(); Optional telemetryOptions = LoggingTelemetryOptions.createFromOptions(options, "prefix."); @@ -42,7 +42,7 @@ void testCreateFromOptions_NoOptions() { } @Test - void testCreateFromOptions_WithAllOptions() { + void createFromOptions_WithAllOptions() { Map options = new HashMap<>(); options.put("prefix.telemetry.logging.enabled", "true"); options.put("prefix.telemetry.logging.level", "ERROR"); @@ -57,7 +57,7 @@ void testCreateFromOptions_WithAllOptions() { } @Test - void testCreateFromOptions_WithInvalidLevel_fallsbackToDefaults() { + void createFromOptions_WithInvalidLevel_fallsbackToDefaults() { Map options = new HashMap<>(); options.put("prefix.telemetry.logging.enabled", "true"); options.put("prefix.telemetry.logging.level", "INVALID_LEVEL"); diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryReporterTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryReporterTest.java index 3f60eef8f..b8f6a01dd 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryReporterTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryReporterTest.java @@ -26,7 +26,7 @@ class LoggingTelemetryReporterTest { @Test - public void testLoggingOptionsDefaultValues() { + void loggingOptionsDefaultValues() { LoggingTelemetryOptions options = LoggingTelemetryOptions.builder().build(); assertThat(options.isEnabled()).isFalse(); @@ -34,7 +34,7 @@ public void testLoggingOptionsDefaultValues() { } @Test - public void testLoggingOptionsCustomValues() { + void loggingOptionsCustomValues() { LoggingTelemetryOptions options = LoggingTelemetryOptions.builder() .setEnabled(true) @@ -46,7 +46,7 @@ public void testLoggingOptionsCustomValues() { } @Test - public void testFormatMetrics_singleMetricWithoutAttributes() { + void formatMetrics_singleMetricWithoutAttributes() { try (LoggingTelemetryReporter reporter = new LoggingTelemetryReporter(LoggingTelemetryOptions.builder().build())) { Map metrics = @@ -63,7 +63,7 @@ public void testFormatMetrics_singleMetricWithoutAttributes() { } @Test - public void testFormatMetrics_singleMetricWithAttributes() { + void formatMetrics_singleMetricWithAttributes() { try (LoggingTelemetryReporter reporter = new LoggingTelemetryReporter(LoggingTelemetryOptions.builder().build())) { Map metrics = @@ -84,7 +84,7 @@ public void testFormatMetrics_singleMetricWithAttributes() { } @Test - public void testFormatMetrics_multipleMetrics() { + void formatMetrics_multipleMetrics() { try (LoggingTelemetryReporter reporter = new LoggingTelemetryReporter(LoggingTelemetryOptions.builder().build())) { Map metrics = diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java index 546d9c50a..451869810 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java @@ -27,14 +27,14 @@ class OpenTelemetryOptionsTest { @Test - void testOpenTelemetryOptionsDefaultValues() { + void openTelemetryOptionsDefaultValues() { OpenTelemetryOptions options = OpenTelemetryOptions.builder().build(); assertThat(options.isEnabled()).isFalse(); assertThat(options.getProviderType()).isEqualTo(OpenTelemetryOptions.ProviderType.GLOBAL); } @Test - void testOpenTelemetryOptionsCustomValues() { + void openTelemetryOptionsCustomValues() { OpenTelemetry customTelemetry = GlobalOpenTelemetry.get(); OpenTelemetryOptions options = OpenTelemetryOptions.builder() @@ -52,7 +52,7 @@ void testOpenTelemetryOptionsCustomValues() { } @Test - void testOpenTelemetryOptionsLoggingProvider() { + void openTelemetryOptionsLoggingProvider() { OpenTelemetryOptions options = OpenTelemetryOptions.builder() .setEnabled(true) @@ -64,7 +64,7 @@ void testOpenTelemetryOptionsLoggingProvider() { } @Test - void testCreateFromOptions_NoOptions() { + void createFromOptions_NoOptions() { Map options = new HashMap<>(); Optional telemetryOptions = OpenTelemetryOptions.createFromOptions(options, "prefix."); @@ -73,7 +73,7 @@ void testCreateFromOptions_NoOptions() { } @Test - void testCreateFromOptions_WithAllOptions() { + void createFromOptions_WithAllOptions() { Map options = new HashMap<>(); options.put("prefix.telemetry.opentelemetry.enabled", "true"); options.put("prefix.telemetry.opentelemetry.provider-type", "PRE_CONFIGURED"); @@ -90,7 +90,7 @@ void testCreateFromOptions_WithAllOptions() { } @Test - void testCreateFromOptions_WithInvalidValues_fallsbackToDefaults() { + void createFromOptions_WithInvalidValues_fallsbackToDefaults() { Map options = new HashMap<>(); options.put("prefix.telemetry.opentelemetry.enabled", "true"); options.put("prefix.telemetry.opentelemetry.provider-type", "INVALID_PROVIDER"); diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryReporterTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryReporterTest.java index e652c41d6..b0cdcd23d 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryReporterTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryReporterTest.java @@ -67,7 +67,7 @@ void setUp() { } @Test - void testOperationEnd_recordsMetrics() { + void operationEnd_recordsMetrics() { OpenTelemetryOptions options = OpenTelemetryOptions.builder() .setEnabled(true) diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/TelemetryOptionsTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/TelemetryOptionsTest.java index 60c4d32e5..0b2b8b2a6 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/TelemetryOptionsTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/TelemetryOptionsTest.java @@ -22,10 +22,10 @@ import java.util.Map; import org.junit.jupiter.api.Test; -public class TelemetryOptionsTest { +class TelemetryOptionsTest { @Test - public void testBuilderWithCustomTelemetryOptions() { + void builderWithCustomTelemetryOptions() { OperationListener listener = new OperationListener() { @Override @@ -44,7 +44,7 @@ public void onOperationEnd(Operation operation, java.util.Map m } @Test - public void testCreateFromOptions_Empty() { + void createFromOptions_Empty() { Map optionsMap = new HashMap<>(); TelemetryOptions options = TelemetryOptions.createFromOptions(optionsMap, "prefix."); @@ -53,7 +53,7 @@ public void testCreateFromOptions_Empty() { } @Test - public void testCreateFromOptions_WithLogging() { + void createFromOptions_WithLogging() { Map optionsMap = new HashMap<>(); optionsMap.put("prefix.telemetry.logging.enabled", "true"); optionsMap.put("prefix.telemetry.logging.level", "INFO"); @@ -68,7 +68,7 @@ public void testCreateFromOptions_WithLogging() { } @Test - public void testCreateFromOptions_WithOpenTelemetry() { + void createFromOptions_WithOpenTelemetry() { Map optionsMap = new HashMap<>(); optionsMap.put("prefix.telemetry.opentelemetry.enabled", "true"); optionsMap.put("prefix.telemetry.opentelemetry.provider-type", "LOGGING"); @@ -83,7 +83,7 @@ public void testCreateFromOptions_WithOpenTelemetry() { } @Test - public void testCreateFromOptions_WithAll() { + void createFromOptions_WithAll() { Map optionsMap = new HashMap<>(); optionsMap.put("prefix.telemetry.logging.enabled", "true"); optionsMap.put("prefix.telemetry.opentelemetry.enabled", "false"); From 5a62c896292c684cd1837884212a9fa5ae44ac1b Mon Sep 17 00:00:00 2001 From: suni72 Date: Tue, 14 Jul 2026 10:12:02 +0000 Subject: [PATCH 2/4] chore: clean up telemetry unit tests --- .../LoggingTelemetryOptionsTest.java | 2 +- .../LoggingTelemetryReporterTest.java | 20 ------------------- .../telemetry/OpenTelemetryOptionsTest.java | 2 +- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java index 1de6e317b..9d0b1e9a9 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java @@ -57,7 +57,7 @@ void createFromOptions_WithAllOptions() { } @Test - void createFromOptions_WithInvalidLevel_fallsbackToDefaults() { + void createFromOptions_WithInvalidLevel_fallsBackToDefaults() { Map options = new HashMap<>(); options.put("prefix.telemetry.logging.enabled", "true"); options.put("prefix.telemetry.logging.level", "INVALID_LEVEL"); diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryReporterTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryReporterTest.java index b8f6a01dd..9d474c275 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryReporterTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryReporterTest.java @@ -25,26 +25,6 @@ @ExtendWith(MockitoExtension.class) class LoggingTelemetryReporterTest { - @Test - void loggingOptionsDefaultValues() { - LoggingTelemetryOptions options = LoggingTelemetryOptions.builder().build(); - - assertThat(options.isEnabled()).isFalse(); - assertThat(options.getLogLevel()).isEqualTo(LoggingTelemetryOptions.LogLevel.DEBUG); - } - - @Test - void loggingOptionsCustomValues() { - LoggingTelemetryOptions options = - LoggingTelemetryOptions.builder() - .setEnabled(true) - .setLogLevel(LoggingTelemetryOptions.LogLevel.INFO) - .build(); - - assertThat(options.isEnabled()).isTrue(); - assertThat(options.getLogLevel()).isEqualTo(LoggingTelemetryOptions.LogLevel.INFO); - } - @Test void formatMetrics_singleMetricWithoutAttributes() { try (LoggingTelemetryReporter reporter = diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java index 451869810..9585a4dc7 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java @@ -90,7 +90,7 @@ void createFromOptions_WithAllOptions() { } @Test - void createFromOptions_WithInvalidValues_fallsbackToDefaults() { + void createFromOptions_WithInvalidValues_fallsBackToDefaults() { Map options = new HashMap<>(); options.put("prefix.telemetry.opentelemetry.enabled", "true"); options.put("prefix.telemetry.opentelemetry.provider-type", "INVALID_PROVIDER"); From 3ec99922dbc87b01a06ddf69fbd39cb09060dc6c Mon Sep 17 00:00:00 2001 From: suni72 Date: Tue, 14 Jul 2026 10:56:32 +0000 Subject: [PATCH 3/4] refactor: consolidate test constants in GcsClientImplTest and remove redundant test --- .../client/GcsClientImplTest.java | 64 ++++++------------- 1 file changed, 20 insertions(+), 44 deletions(-) diff --git a/client/src/test/java/com/google/cloud/gcs/analyticscore/client/GcsClientImplTest.java b/client/src/test/java/com/google/cloud/gcs/analyticscore/client/GcsClientImplTest.java index a67e72d44..fc0598d97 100644 --- a/client/src/test/java/com/google/cloud/gcs/analyticscore/client/GcsClientImplTest.java +++ b/client/src/test/java/com/google/cloud/gcs/analyticscore/client/GcsClientImplTest.java @@ -84,6 +84,7 @@ class GcsClientImplTest { private static final String TEST_WRITE_OBJECT = "test-write-object"; private static final String TEST_NULL_OPTIONS_OBJECT = "test-null-options"; private static final String TEST_NON_EXISTENT_OBJECT = "non-existent"; + private static final String NON_EXISTENT_BUCKET = "non-existent-bucket"; private static final String TEST_OBJECT_NAME = "test-object-name"; private static final String BLOB_WRITE_SESSION_CONFIG_FIELD = "blobWriteSessionConfig"; private static final int MB = 1024 * 1024; @@ -168,7 +169,7 @@ void getGcsItemInfo_nonExistentBlob_throwsIOException() { void openReadChannel_gcsObjectExists_returnsChannelWithCorrectSizeAndContent() throws IOException { String objectData = "hello world"; - GcsReadOptions readOptions = GcsReadOptions.builder().setUserProjectId("test-project").build(); + GcsReadOptions readOptions = GcsReadOptions.builder().setUserProjectId(TEST_PROJECT).build(); GcsItemId itemId = GcsItemId.builder().setBucketName(TEST_BUCKET_NAME).setObjectName(TEST_OBJECT_NAME).build(); GcsItemInfo itemInfo = @@ -193,7 +194,7 @@ void openReadChannel_gcsObjectExists_returnsChannelWithCorrectSizeAndContent() void openReadChannel_itemId_gcsObjectExists_returnsChannelWithCorrectSizeAndContent() throws IOException { String objectData = "hello world"; - GcsReadOptions readOptions = GcsReadOptions.builder().setUserProjectId("test-project").build(); + GcsReadOptions readOptions = GcsReadOptions.builder().setUserProjectId(TEST_PROJECT).build(); GcsItemId itemId = GcsItemId.builder().setBucketName(TEST_BUCKET_NAME).setObjectName(TEST_OBJECT_NAME).build(); StorageTestUtils.createBlobInStorage( @@ -212,8 +213,7 @@ void openReadChannel_itemId_gcsObjectExists_returnsChannelWithCorrectSizeAndCont @Test void openReadChannel_nullItemId_throwsNullPointerException() { - GcsReadOptions readOptions = - GcsReadOptions.builder().setUserProjectId("test-project-id").build(); + GcsReadOptions readOptions = GcsReadOptions.builder().setUserProjectId(TEST_PROJECT).build(); NullPointerException e = assertThrows( @@ -224,8 +224,7 @@ void openReadChannel_nullItemId_throwsNullPointerException() { @Test void openReadChannel_nullItemInfo_throwsNullPointerException() { - GcsReadOptions readOptions = - GcsReadOptions.builder().setUserProjectId("test-project-id").build(); + GcsReadOptions readOptions = GcsReadOptions.builder().setUserProjectId(TEST_PROJECT).build(); NullPointerException e = assertThrows( @@ -255,8 +254,7 @@ void openReadChannel_itemInfoPointsToDirectory_throwsIllegalArgumentException() .setSize(0L) .setContentGeneration(-1L) .build(); - GcsReadOptions readOptions = - GcsReadOptions.builder().setUserProjectId("test-project-id").build(); + GcsReadOptions readOptions = GcsReadOptions.builder().setUserProjectId(TEST_PROJECT).build(); IllegalArgumentException e = assertThrows( @@ -282,7 +280,7 @@ void getUserAgent_noOptionalUserAgent() throws Exception { void getUserAgent_withOptionalUserAgent() throws Exception { GcsClientOptions options = GcsClientOptions.builder() - .setProjectId("test-project") + .setProjectId(TEST_PROJECT) .setUserAgent("custom-app/1.0") .build(); GcsClientImpl client = new GcsClientImpl(options, executorServiceSupplier, telemetry); @@ -353,9 +351,9 @@ void getBucketProperties_hnsNull_returnsFalse() throws IOException { void getBucketProperties_bucketNotFound_returnsDisabledHns() throws Exception { Storage mockStorage = mock(Storage.class); GcsClientImpl localGcsClient = createClientWithMockStorage(mockStorage); - doReturn(null).when(mockStorage).get(eq("non-existent-bucket"), any(BucketGetOption.class)); + doReturn(null).when(mockStorage).get(eq(NON_EXISTENT_BUCKET), any(BucketGetOption.class)); - BucketProperties properties = localGcsClient.getBucketProperties("non-existent-bucket"); + BucketProperties properties = localGcsClient.getBucketProperties(NON_EXISTENT_BUCKET); assertThat(properties.isHnsEnabled()).isFalse(); } @@ -507,12 +505,9 @@ void create_whenBucketOrObjectNotFound_throwsFileNotFoundException() throws Exce Storage mockStorage = mock(Storage.class); GcsClientImpl clientWithMock = createClientWithMockStorage(mockStorage); GcsItemId itemId = - GcsItemId.builder() - .setBucketName("non-existent-bucket") - .setObjectName("test-object") - .build(); + GcsItemId.builder().setBucketName(NON_EXISTENT_BUCKET).setObjectName(TEST_OBJECT).build(); BlobInfo blobInfo = - BlobInfo.newBuilder(BlobId.of("non-existent-bucket", "test-object")) + BlobInfo.newBuilder(BlobId.of(NON_EXISTENT_BUCKET, TEST_OBJECT)) .setContentType("application/octet-stream") .build(); StorageException e404 = new StorageException(404, "Not Found"); @@ -795,19 +790,6 @@ void create_whenOpenThrowsIOException_propagatesIOException() throws Exception { assertThat(thrown).isSameInstanceAs(ioException); } - @Test - void getBlob_whenBucketNameIsNull_throwsNullPointerException() throws Exception { - GcsItemId itemId = mock(GcsItemId.class); - when(itemId.getBucketName()).thenReturn(null); - when(itemId.getObjectName()).thenReturn(Optional.of(TEST_OBJECT)); - when(itemId.isGcsObject()).thenReturn(true); - - GcsClientImpl client = - new GcsClientImpl(TEST_GCS_CLIENT_OPTIONS, executorServiceSupplier, telemetry); - - assertThrows(NullPointerException.class, () -> client.getGcsItemInfo(itemId)); - } - @Test void getGcsItemInfo_whenBucketItemIdProvided_throwsUnsupportedOperationException() throws Exception { @@ -1000,30 +982,27 @@ void createStorage_bidiDisabled_usesHttpTransport() throws IOException { void createStorage_bidiEnabled_usesGrpcTransport() throws IOException { GcsClientOptions options = GcsClientOptions.builder() - .setProjectId("test-project") + .setProjectId(TEST_PROJECT) .setGcsReadOptions(GcsReadOptions.builder().setBidiReadEnabled(true).build()) .build(); + GcsClientImpl client = new GcsClientImpl(NoCredentials.getInstance(), options, executorServiceSupplier, telemetry); + assertThat(client.storage.getOptions()).isInstanceOf(GrpcStorageOptions.class); } @Test void openReadChannel_bidiEnabled_returnsGcsBidiReadChannel() throws IOException { GcsReadOptions readOptions = - GcsReadOptions.builder().setUserProjectId("test-project").setBidiReadEnabled(true).build(); + GcsReadOptions.builder().setUserProjectId(TEST_PROJECT).setBidiReadEnabled(true).build(); GcsItemId itemId = - GcsItemId.builder() - .setBucketName("test-bucket-name") - .setObjectName("test-object-name") - .build(); + GcsItemId.builder().setBucketName(TEST_BUCKET_NAME).setObjectName(TEST_OBJECT_NAME).build(); GcsItemInfo itemInfo = GcsItemInfo.builder().setItemId(itemId).setSize(100L).setContentGeneration(0L).build(); - Storage mockStorage = mock(Storage.class); ApiFuture mockSessionFuture = mock(ApiFuture.class); when(mockStorage.blobReadSession(any(BlobId.class))).thenReturn(mockSessionFuture); - GcsClient bidiClient = new GcsClientImpl(TEST_GCS_CLIENT_OPTIONS, executorServiceSupplier, telemetry) { @Override @@ -1033,23 +1012,19 @@ protected Storage createStorage(Optional credentials) { }; VectoredSeekableByteChannel channel = bidiClient.openReadChannel(itemInfo, readOptions); + assertThat(channel).isInstanceOf(GcsBidiReadChannel.class); } @Test void openReadChannel_itemId_bidiEnabled_returnsGcsBidiReadChannel() throws IOException { GcsReadOptions readOptions = - GcsReadOptions.builder().setUserProjectId("test-project").setBidiReadEnabled(true).build(); + GcsReadOptions.builder().setUserProjectId(TEST_PROJECT).setBidiReadEnabled(true).build(); GcsItemId itemId = - GcsItemId.builder() - .setBucketName("test-bucket-name") - .setObjectName("test-object-name") - .build(); - + GcsItemId.builder().setBucketName(TEST_BUCKET_NAME).setObjectName(TEST_OBJECT_NAME).build(); Storage mockStorage = mock(Storage.class); ApiFuture mockSessionFuture = mock(ApiFuture.class); when(mockStorage.blobReadSession(any(BlobId.class))).thenReturn(mockSessionFuture); - GcsClient bidiClient = new GcsClientImpl(TEST_GCS_CLIENT_OPTIONS, executorServiceSupplier, telemetry) { @Override @@ -1059,6 +1034,7 @@ protected Storage createStorage(Optional credentials) { }; VectoredSeekableByteChannel channel = bidiClient.openReadChannel(itemId, readOptions); + assertThat(channel).isInstanceOf(GcsBidiReadChannel.class); } } From b0a94d503278b70fbab7a02a616e89a3ac1a7490 Mon Sep 17 00:00:00 2001 From: suni72 Date: Mon, 3 Aug 2026 12:23:29 +0000 Subject: [PATCH 4/4] refactor: rename telemetry test methods to follow standard naming convention --- .../telemetry/LoggingTelemetryOptionsTest.java | 8 ++++---- .../common/telemetry/OpenTelemetryOptionsTest.java | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java index 9d0b1e9a9..0401e8336 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/LoggingTelemetryOptionsTest.java @@ -25,7 +25,7 @@ class LoggingTelemetryOptionsTest { @Test - void loggingTelemetryOptionsDefaultValues() { + void loggingTelemetryOptions_defaultValues_returnsDefaultOptions() { LoggingTelemetryOptions options = LoggingTelemetryOptions.builder().build(); assertThat(options.isEnabled()).isFalse(); @@ -33,7 +33,7 @@ void loggingTelemetryOptionsDefaultValues() { } @Test - void createFromOptions_NoOptions() { + void createFromOptions_noOptions_returnsEmpty() { Map options = new HashMap<>(); Optional telemetryOptions = LoggingTelemetryOptions.createFromOptions(options, "prefix."); @@ -42,7 +42,7 @@ void createFromOptions_NoOptions() { } @Test - void createFromOptions_WithAllOptions() { + void createFromOptions_withAllOptions_returnsPresentOptions() { Map options = new HashMap<>(); options.put("prefix.telemetry.logging.enabled", "true"); options.put("prefix.telemetry.logging.level", "ERROR"); @@ -57,7 +57,7 @@ void createFromOptions_WithAllOptions() { } @Test - void createFromOptions_WithInvalidLevel_fallsBackToDefaults() { + void createFromOptions_withInvalidLevel_fallsBackToDefaults() { Map options = new HashMap<>(); options.put("prefix.telemetry.logging.enabled", "true"); options.put("prefix.telemetry.logging.level", "INVALID_LEVEL"); diff --git a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java index 9585a4dc7..e3384b60a 100644 --- a/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java +++ b/common/src/test/java/com/google/cloud/gcs/analyticscore/common/telemetry/OpenTelemetryOptionsTest.java @@ -27,14 +27,14 @@ class OpenTelemetryOptionsTest { @Test - void openTelemetryOptionsDefaultValues() { + void openTelemetryOptions_defaultValues_returnsDefaultOptions() { OpenTelemetryOptions options = OpenTelemetryOptions.builder().build(); assertThat(options.isEnabled()).isFalse(); assertThat(options.getProviderType()).isEqualTo(OpenTelemetryOptions.ProviderType.GLOBAL); } @Test - void openTelemetryOptionsCustomValues() { + void openTelemetryOptions_customValues_returnsCustomOptions() { OpenTelemetry customTelemetry = GlobalOpenTelemetry.get(); OpenTelemetryOptions options = OpenTelemetryOptions.builder() @@ -52,7 +52,7 @@ void openTelemetryOptionsCustomValues() { } @Test - void openTelemetryOptionsLoggingProvider() { + void openTelemetryOptions_loggingProvider_returnsLoggingOptions() { OpenTelemetryOptions options = OpenTelemetryOptions.builder() .setEnabled(true) @@ -64,7 +64,7 @@ void openTelemetryOptionsLoggingProvider() { } @Test - void createFromOptions_NoOptions() { + void createFromOptions_noOptions_returnsEmpty() { Map options = new HashMap<>(); Optional telemetryOptions = OpenTelemetryOptions.createFromOptions(options, "prefix."); @@ -73,7 +73,7 @@ void createFromOptions_NoOptions() { } @Test - void createFromOptions_WithAllOptions() { + void createFromOptions_withAllOptions_returnsPresentOptions() { Map options = new HashMap<>(); options.put("prefix.telemetry.opentelemetry.enabled", "true"); options.put("prefix.telemetry.opentelemetry.provider-type", "PRE_CONFIGURED"); @@ -90,7 +90,7 @@ void createFromOptions_WithAllOptions() { } @Test - void createFromOptions_WithInvalidValues_fallsBackToDefaults() { + void createFromOptions_withInvalidValues_fallsBackToDefaults() { Map options = new HashMap<>(); options.put("prefix.telemetry.opentelemetry.enabled", "true"); options.put("prefix.telemetry.opentelemetry.provider-type", "INVALID_PROVIDER");