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); } } 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..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 testLoggingTelemetryOptionsDefaultValues() { + void loggingTelemetryOptions_defaultValues_returnsDefaultOptions() { LoggingTelemetryOptions options = LoggingTelemetryOptions.builder().build(); assertThat(options.isEnabled()).isFalse(); @@ -33,7 +33,7 @@ void testLoggingTelemetryOptionsDefaultValues() { } @Test - void testCreateFromOptions_NoOptions() { + void createFromOptions_noOptions_returnsEmpty() { Map options = new HashMap<>(); Optional telemetryOptions = LoggingTelemetryOptions.createFromOptions(options, "prefix."); @@ -42,7 +42,7 @@ void testCreateFromOptions_NoOptions() { } @Test - void testCreateFromOptions_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 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..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 @@ -26,27 +26,7 @@ class LoggingTelemetryReporterTest { @Test - public void testLoggingOptionsDefaultValues() { - LoggingTelemetryOptions options = LoggingTelemetryOptions.builder().build(); - - assertThat(options.isEnabled()).isFalse(); - assertThat(options.getLogLevel()).isEqualTo(LoggingTelemetryOptions.LogLevel.DEBUG); - } - - @Test - public void testLoggingOptionsCustomValues() { - LoggingTelemetryOptions options = - LoggingTelemetryOptions.builder() - .setEnabled(true) - .setLogLevel(LoggingTelemetryOptions.LogLevel.INFO) - .build(); - - assertThat(options.isEnabled()).isTrue(); - assertThat(options.getLogLevel()).isEqualTo(LoggingTelemetryOptions.LogLevel.INFO); - } - - @Test - public void testFormatMetrics_singleMetricWithoutAttributes() { + void formatMetrics_singleMetricWithoutAttributes() { try (LoggingTelemetryReporter reporter = new LoggingTelemetryReporter(LoggingTelemetryOptions.builder().build())) { Map metrics = @@ -63,7 +43,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 +64,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..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 testOpenTelemetryOptionsDefaultValues() { + void openTelemetryOptions_defaultValues_returnsDefaultOptions() { OpenTelemetryOptions options = OpenTelemetryOptions.builder().build(); assertThat(options.isEnabled()).isFalse(); assertThat(options.getProviderType()).isEqualTo(OpenTelemetryOptions.ProviderType.GLOBAL); } @Test - void testOpenTelemetryOptionsCustomValues() { + void openTelemetryOptions_customValues_returnsCustomOptions() { OpenTelemetry customTelemetry = GlobalOpenTelemetry.get(); OpenTelemetryOptions options = OpenTelemetryOptions.builder() @@ -52,7 +52,7 @@ void testOpenTelemetryOptionsCustomValues() { } @Test - void testOpenTelemetryOptionsLoggingProvider() { + void openTelemetryOptions_loggingProvider_returnsLoggingOptions() { OpenTelemetryOptions options = OpenTelemetryOptions.builder() .setEnabled(true) @@ -64,7 +64,7 @@ void testOpenTelemetryOptionsLoggingProvider() { } @Test - void testCreateFromOptions_NoOptions() { + void createFromOptions_noOptions_returnsEmpty() { Map options = new HashMap<>(); Optional telemetryOptions = OpenTelemetryOptions.createFromOptions(options, "prefix."); @@ -73,7 +73,7 @@ void testCreateFromOptions_NoOptions() { } @Test - void testCreateFromOptions_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 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");