|
16 | 16 | import com.google.common.collect.ImmutableMap;
|
17 | 17 | import io.airlift.units.DataSize;
|
18 | 18 | import io.airlift.units.Duration;
|
| 19 | +import io.trino.filesystem.gcs.GcsFileSystemConfig.AuthType; |
19 | 20 | import jakarta.validation.constraints.AssertTrue;
|
20 | 21 | import org.junit.jupiter.api.Test;
|
21 | 22 |
|
|
30 | 31 | import static io.airlift.units.DataSize.Unit.MEGABYTE;
|
31 | 32 | import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
32 | 33 | import static java.util.concurrent.TimeUnit.SECONDS;
|
| 34 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
33 | 35 |
|
34 | 36 | public class TestGcsFileSystemConfig
|
35 | 37 | {
|
36 | 38 | @Test
|
37 | 39 | void testDefaults()
|
38 | 40 | {
|
39 |
| - assertRecordedDefaults(recordDefaults(GcsFileSystemConfig.class) |
40 |
| - .setReadBlockSize(DataSize.of(2, MEGABYTE)) |
41 |
| - .setWriteBlockSize(DataSize.of(16, MEGABYTE)) |
42 |
| - .setPageSize(100) |
43 |
| - .setBatchSize(100) |
44 |
| - .setProjectId(null) |
45 |
| - .setEndpoint(Optional.empty()) |
46 |
| - .setUseGcsAccessToken(false) |
47 |
| - .setJsonKey(null) |
48 |
| - .setJsonKeyFilePath(null) |
49 |
| - .setMaxRetries(20) |
50 |
| - .setBackoffScaleFactor(3.0) |
51 |
| - .setMaxRetryTime(new Duration(25, SECONDS)) |
52 |
| - .setMinBackoffDelay(new Duration(10, MILLISECONDS)) |
53 |
| - .setMaxBackoffDelay(new Duration(2000, MILLISECONDS)) |
54 |
| - .setApplicationId("Trino")); |
| 41 | + assertThatThrownBy( |
| 42 | + () -> assertRecordedDefaults(recordDefaults(GcsFileSystemConfig.class) |
| 43 | + .setReadBlockSize(DataSize.of(2, MEGABYTE)) |
| 44 | + .setWriteBlockSize(DataSize.of(16, MEGABYTE)) |
| 45 | + .setPageSize(100) |
| 46 | + .setBatchSize(100) |
| 47 | + .setProjectId(null) |
| 48 | + .setEndpoint(Optional.empty()) |
| 49 | + .setAuthType(null) |
| 50 | + .setJsonKey(null) |
| 51 | + .setJsonKeyFilePath(null) |
| 52 | + .setMaxRetries(20) |
| 53 | + .setBackoffScaleFactor(3.0) |
| 54 | + .setMaxRetryTime(new Duration(25, SECONDS)) |
| 55 | + .setMinBackoffDelay(new Duration(10, MILLISECONDS)) |
| 56 | + .setMaxBackoffDelay(new Duration(2000, MILLISECONDS)) |
| 57 | + .setApplicationId("Trino"))) |
| 58 | + .isInstanceOf(AssertionError.class) |
| 59 | + // use-access-token is not deprecated and isn't allowed to be set with auth-type |
| 60 | + .hasMessage("Untested attributes: [UseGcsAccessToken]"); |
55 | 61 | }
|
56 | 62 |
|
57 | 63 | @Test
|
58 | 64 | void testExplicitPropertyMappings()
|
| 65 | + { |
| 66 | + Map<String, String> properties = ImmutableMap.<String, String>builder() |
| 67 | + .put("gcs.read-block-size", "51MB") |
| 68 | + .put("gcs.write-block-size", "52MB") |
| 69 | + .put("gcs.page-size", "10") |
| 70 | + .put("gcs.batch-size", "11") |
| 71 | + .put("gcs.project-id", "project") |
| 72 | + .put("gcs.endpoint", "http://custom.dns.org:8000") |
| 73 | + .put("gcs.auth-type", "access_token") |
| 74 | + .put("gcs.client.max-retries", "10") |
| 75 | + .put("gcs.client.backoff-scale-factor", "4.0") |
| 76 | + .put("gcs.client.max-retry-time", "10s") |
| 77 | + .put("gcs.client.min-backoff-delay", "20ms") |
| 78 | + .put("gcs.client.max-backoff-delay", "20ms") |
| 79 | + .put("gcs.application-id", "application id") |
| 80 | + .buildOrThrow(); |
| 81 | + |
| 82 | + GcsFileSystemConfig expected = new GcsFileSystemConfig() |
| 83 | + .setReadBlockSize(DataSize.of(51, MEGABYTE)) |
| 84 | + .setWriteBlockSize(DataSize.of(52, MEGABYTE)) |
| 85 | + .setPageSize(10) |
| 86 | + .setBatchSize(11) |
| 87 | + .setProjectId("project") |
| 88 | + .setEndpoint(Optional.of("http://custom.dns.org:8000")) |
| 89 | + .setAuthType(AuthType.ACCESS_TOKEN) |
| 90 | + .setMaxRetries(10) |
| 91 | + .setBackoffScaleFactor(4.0) |
| 92 | + .setMaxRetryTime(new Duration(10, SECONDS)) |
| 93 | + .setMinBackoffDelay(new Duration(20, MILLISECONDS)) |
| 94 | + .setMaxBackoffDelay(new Duration(20, MILLISECONDS)) |
| 95 | + .setApplicationId("application id"); |
| 96 | + assertFullMapping(properties, expected, Set.of("gcs.json-key", "gcs.json-key-file-path", "gcs.use-access-token")); |
| 97 | + } |
| 98 | + |
| 99 | + // backwards compatibility test, remove if use-access-token is removed |
| 100 | + @Test |
| 101 | + void testExplicitPropertyMappingsWithDeprecatedUseAccessToken() |
59 | 102 | {
|
60 | 103 | Map<String, String> properties = ImmutableMap.<String, String>builder()
|
61 | 104 | .put("gcs.read-block-size", "51MB")
|
@@ -87,34 +130,51 @@ void testExplicitPropertyMappings()
|
87 | 130 | .setMinBackoffDelay(new Duration(20, MILLISECONDS))
|
88 | 131 | .setMaxBackoffDelay(new Duration(20, MILLISECONDS))
|
89 | 132 | .setApplicationId("application id");
|
90 |
| - assertFullMapping(properties, expected, Set.of("gcs.json-key", "gcs.json-key-file-path")); |
| 133 | + assertFullMapping(properties, expected, Set.of("gcs.json-key", "gcs.json-key-file-path", "gcs.auth-type")); |
| 134 | + } |
| 135 | + |
| 136 | + @Test |
| 137 | + void testSetUseGcsAccessTokenWithAuthType() |
| 138 | + { |
| 139 | + assertThatThrownBy(() -> new GcsFileSystemConfig().setAuthType(AuthType.ACCESS_TOKEN).setUseGcsAccessToken(true)) |
| 140 | + .isInstanceOf(IllegalArgumentException.class) |
| 141 | + .hasMessage("Cannot set both gcs.use-access-token and gcs.auth-type"); |
| 142 | + assertThatThrownBy(() -> new GcsFileSystemConfig().setAuthType(AuthType.DEFAULT).setUseGcsAccessToken(false)) |
| 143 | + .isInstanceOf(IllegalArgumentException.class) |
| 144 | + .hasMessage("Cannot set both gcs.use-access-token and gcs.auth-type"); |
| 145 | + assertThatThrownBy(() -> new GcsFileSystemConfig().setUseGcsAccessToken(true).setAuthType(AuthType.ACCESS_TOKEN)) |
| 146 | + .isInstanceOf(IllegalArgumentException.class) |
| 147 | + .hasMessage("Cannot set both gcs.use-access-token and gcs.auth-type"); |
| 148 | + assertThatThrownBy(() -> new GcsFileSystemConfig().setUseGcsAccessToken(true).setAuthType(AuthType.DEFAULT)) |
| 149 | + .isInstanceOf(IllegalArgumentException.class) |
| 150 | + .hasMessage("Cannot set both gcs.use-access-token and gcs.auth-type"); |
91 | 151 | }
|
92 | 152 |
|
93 | 153 | @Test
|
94 | 154 | public void testValidation()
|
95 | 155 | {
|
96 | 156 | assertFailsValidation(
|
97 | 157 | new GcsFileSystemConfig()
|
98 |
| - .setUseGcsAccessToken(true) |
| 158 | + .setAuthType(AuthType.ACCESS_TOKEN) |
99 | 159 | .setJsonKey("{}}"),
|
100 | 160 | "authMethodValid",
|
101 |
| - "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set", |
| 161 | + "Either gcs.auth-type or gcs.json-key or gcs.json-key-file-path must be set", |
102 | 162 | AssertTrue.class);
|
103 | 163 |
|
104 | 164 | assertFailsValidation(
|
105 | 165 | new GcsFileSystemConfig()
|
106 |
| - .setUseGcsAccessToken(true) |
| 166 | + .setAuthType(AuthType.ACCESS_TOKEN) |
107 | 167 | .setJsonKeyFilePath("/dev/null"),
|
108 | 168 | "authMethodValid",
|
109 |
| - "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set", |
| 169 | + "Either gcs.auth-type or gcs.json-key or gcs.json-key-file-path must be set", |
110 | 170 | AssertTrue.class);
|
111 | 171 |
|
112 | 172 | assertFailsValidation(
|
113 | 173 | new GcsFileSystemConfig()
|
114 | 174 | .setJsonKey("{}")
|
115 | 175 | .setJsonKeyFilePath("/dev/null"),
|
116 | 176 | "authMethodValid",
|
117 |
| - "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set", |
| 177 | + "Either gcs.auth-type or gcs.json-key or gcs.json-key-file-path must be set", |
118 | 178 | AssertTrue.class);
|
119 | 179 |
|
120 | 180 | assertFailsValidation(
|
|
0 commit comments