|
Expand Up
|
@@ -31,47 +31,88 @@ |
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
import static org.junit.jupiter.api.Assertions.assertSame; |
|
|
import static org.junit.jupiter.api.Assertions.assertThrows; |
|
|
|
|
|
import java.time.Duration; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
public class ResumableUploadCallSettingsTest { |
|
|
|
|
|
@Test |
|
|
public void testDefaultChunkSizeInBuilder() { |
|
|
ResumableUploadCallSettings settings = ResumableUploadCallSettings.newBuilder().build(); |
|
|
public void testCustomSettingsAndToBuilder() { |
|
|
ResumableUploadCallSettings settings = |
|
|
ResumableUploadCallSettings.newBuilder() |
|
|
.setChunkSize(16 * 1024 * 1024) |
|
|
.setGlobalTimeout(Duration.ofMinutes(15)) |
|
|
.build(); |
|
|
|
|
|
assertEquals(16 * 1024 * 1024, settings.getChunkSize()); |
|
|
assertEquals(Duration.ofMinutes(15), settings.getGlobalTimeout()); |
|
|
assertEquals(settings, settings.toBuilder().build()); |
|
|
} |
|
|
|
|
|
assertEquals(8 * 1024 * 1024, settings.getChunkSize()); |
|
|
@Test |
|
|
public void testInvalidChunkSize_throwsIllegalArgumentException() { |
|
|
assertThrows( |
Check warning
on line 56
in sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/rpc/ResumableUploadCallSettingsTest.java
View check run for this annotation
SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis
Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.
See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AaBumadI4VFARgn-a4gc&open=AaBumadI4VFARgn-a4gc&pullRequest=14253
|
|
|
IllegalArgumentException.class, |
|
|
() -> ResumableUploadCallSettings.newBuilder().setChunkSize(0).build()); |
|
|
assertThrows( |
Check warning
on line 59
in sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/rpc/ResumableUploadCallSettingsTest.java
View check run for this annotation
SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis
Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.
See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AaBumadI4VFARgn-a4gd&open=AaBumadI4VFARgn-a4gd&pullRequest=14253
|
|
|
IllegalArgumentException.class, |
|
|
() -> ResumableUploadCallSettings.newBuilder().setChunkSize(-1).build()); |
|
|
} |
|
|
|
|
|
@Test |
|
|
public void testInvalidGlobalTimeout_throwsIllegalArgumentException() { |
|
|
assertThrows( |
Check warning
on line 66
in sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/rpc/ResumableUploadCallSettingsTest.java
View check run for this annotation
SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis
Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.
See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AaBumadI4VFARgn-a4ge&open=AaBumadI4VFARgn-a4ge&pullRequest=14253
|
|
|
IllegalArgumentException.class, |
|
|
() -> ResumableUploadCallSettings.newBuilder().setGlobalTimeout(Duration.ZERO).build()); |
|
|
assertThrows( |
Check warning
on line 69
in sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/rpc/ResumableUploadCallSettingsTest.java
View check run for this annotation
SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis
Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception.
See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AaBumadI4VFARgn-a4gf&open=AaBumadI4VFARgn-a4gf&pullRequest=14253
|
|
|
IllegalArgumentException.class, |
|
|
() -> |
|
|
ResumableUploadCallSettings.newBuilder() |
|
|
.setGlobalTimeout(Duration.ofSeconds(-5)) |
|
|
.build()); |
|
|
} |
|
|
|
|
|
@Test |
|
|
public void testCustomInitialization() { |
|
|
public void testMerge_nullSettings_returnsSameInstance() { |
|
|
ResumableUploadCallSettings settings = |
|
|
ResumableUploadCallSettings.newBuilder().setChunkSize(16 * 1024 * 1024).build(); |
|
|
ResumableUploadCallSettings.newBuilder().setChunkSize(4 * 1024 * 1024).build(); |
|
|
|
|
|
assertEquals(16 * 1024 * 1024, settings.getChunkSize()); |
|
|
assertSame(settings, settings.merge(null)); |
|
|
} |
|
|
|
|
|
@Test |
|
|
public void testMerge_NullSettings() { |
|
|
public void testMerge_overridesChunkSizeAndGlobalTimeout() { |
|
|
ResumableUploadCallSettings stubSettings = |
|
|
ResumableUploadCallSettings.newBuilder().setChunkSize(4 * 1024 * 1024).build(); |
|
|
ResumableUploadCallSettings.newBuilder() |
|
|
.setChunkSize(4 * 1024 * 1024) |
|
|
.setGlobalTimeout(Duration.ofMinutes(10)) |
|
|
.build(); |
|
|
|
|
|
ResumableUploadCallSettings perRequestSettings = |
|
|
ResumableUploadCallSettings.newBuilder() |
|
|
.setChunkSize(32 * 1024 * 1024) |
|
|
.setGlobalTimeout(Duration.ofMinutes(30)) |
|
|
.build(); |
|
|
|
|
|
ResumableUploadCallSettings merged = stubSettings.merge(null); |
|
|
ResumableUploadCallSettings merged = stubSettings.merge(perRequestSettings); |
|
|
|
|
|
assertSame(stubSettings, merged); |
|
|
assertEquals(32 * 1024 * 1024, merged.getChunkSize()); |
|
|
assertEquals(Duration.ofMinutes(30), merged.getGlobalTimeout()); |
|
|
} |
|
|
|
|
|
@Test |
|
|
public void testMerge_SettingsOverrides() { |
|
|
public void testMerge_nullGlobalTimeoutDoesNotOverride() { |
|
|
ResumableUploadCallSettings stubSettings = |
|
|
ResumableUploadCallSettings.newBuilder().setChunkSize(4 * 1024 * 1024).build(); |
|
|
ResumableUploadCallSettings.newBuilder().setGlobalTimeout(Duration.ofMinutes(10)).build(); |
|
|
|
|
|
ResumableUploadCallSettings perRequestSettings = |
|
|
ResumableUploadCallSettings.newBuilder().setChunkSize(32 * 1024 * 1024).build(); |
|
|
|
|
|
ResumableUploadCallSettings merged = stubSettings.merge(perRequestSettings); |
|
|
|
|
|
// Chunk size overridden by Tier-1 per-request settings |
|
|
assertEquals(32 * 1024 * 1024, merged.getChunkSize()); |
|
|
assertEquals(Duration.ofMinutes(10), merged.getGlobalTimeout()); |
|
|
} |
|
|
} |