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
@@ -41,9 +42,10 @@ void testDefaults()
41
42
.setWriteBlockSize (DataSize .of (16 , MEGABYTE ))
42
43
.setPageSize (100 )
43
44
.setBatchSize (100 )
45
+ .setUseGcsAccessToken (false )
44
46
.setProjectId (null )
45
47
.setEndpoint (Optional .empty ())
46
- .setUseGcsAccessToken ( false )
48
+ .setAuthType ( AuthType . DEFAULT )
47
49
.setJsonKey (null )
48
50
.setJsonKeyFilePath (null )
49
51
.setMaxRetries (20 )
@@ -56,6 +58,43 @@ void testDefaults()
56
58
57
59
@ Test
58
60
void testExplicitPropertyMappings ()
61
+ {
62
+ Map <String , String > properties = ImmutableMap .<String , String >builder ()
63
+ .put ("gcs.read-block-size" , "51MB" )
64
+ .put ("gcs.write-block-size" , "52MB" )
65
+ .put ("gcs.page-size" , "10" )
66
+ .put ("gcs.batch-size" , "11" )
67
+ .put ("gcs.project-id" , "project" )
68
+ .put ("gcs.endpoint" , "http://custom.dns.org:8000" )
69
+ .put ("gcs.auth-type" , "access_token" )
70
+ .put ("gcs.client.max-retries" , "10" )
71
+ .put ("gcs.client.backoff-scale-factor" , "4.0" )
72
+ .put ("gcs.client.max-retry-time" , "10s" )
73
+ .put ("gcs.client.min-backoff-delay" , "20ms" )
74
+ .put ("gcs.client.max-backoff-delay" , "20ms" )
75
+ .put ("gcs.application-id" , "application id" )
76
+ .buildOrThrow ();
77
+
78
+ GcsFileSystemConfig expected = new GcsFileSystemConfig ()
79
+ .setReadBlockSize (DataSize .of (51 , MEGABYTE ))
80
+ .setWriteBlockSize (DataSize .of (52 , MEGABYTE ))
81
+ .setPageSize (10 )
82
+ .setBatchSize (11 )
83
+ .setProjectId ("project" )
84
+ .setEndpoint (Optional .of ("http://custom.dns.org:8000" ))
85
+ .setAuthType (AuthType .ACCESS_TOKEN )
86
+ .setMaxRetries (10 )
87
+ .setBackoffScaleFactor (4.0 )
88
+ .setMaxRetryTime (new Duration (10 , SECONDS ))
89
+ .setMinBackoffDelay (new Duration (20 , MILLISECONDS ))
90
+ .setMaxBackoffDelay (new Duration (20 , MILLISECONDS ))
91
+ .setApplicationId ("application id" );
92
+ assertFullMapping (properties , expected , Set .of ("gcs.json-key" , "gcs.json-key-file-path" , "gcs.use-access-token" ));
93
+ }
94
+
95
+ // backwards compatibility test, remove if use-access-token is removed
96
+ @ Test
97
+ void testExplicitPropertyMappingsWithDeprecatedUseAccessToken ()
59
98
{
60
99
Map <String , String > properties = ImmutableMap .<String , String >builder ()
61
100
.put ("gcs.read-block-size" , "51MB" )
@@ -87,34 +126,34 @@ void testExplicitPropertyMappings()
87
126
.setMinBackoffDelay (new Duration (20 , MILLISECONDS ))
88
127
.setMaxBackoffDelay (new Duration (20 , MILLISECONDS ))
89
128
.setApplicationId ("application id" );
90
- assertFullMapping (properties , expected , Set .of ("gcs.json-key" , "gcs.json-key-file-path" ));
129
+ assertFullMapping (properties , expected , Set .of ("gcs.json-key" , "gcs.json-key-file-path" , "gcs.auth-type" ));
91
130
}
92
131
93
132
@ Test
94
133
public void testValidation ()
95
134
{
96
135
assertFailsValidation (
97
136
new GcsFileSystemConfig ()
98
- .setUseGcsAccessToken ( true )
137
+ .setAuthType ( AuthType . ACCESS_TOKEN )
99
138
.setJsonKey ("{}}" ),
100
139
"authMethodValid" ,
101
- "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set" ,
140
+ "Either gcs.auth-type or gcs.json-key or gcs.json-key-file-path must be set" ,
102
141
AssertTrue .class );
103
142
104
143
assertFailsValidation (
105
144
new GcsFileSystemConfig ()
106
- .setUseGcsAccessToken ( true )
145
+ .setAuthType ( AuthType . ACCESS_TOKEN )
107
146
.setJsonKeyFilePath ("/dev/null" ),
108
147
"authMethodValid" ,
109
- "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set" ,
148
+ "Either gcs.auth-type or gcs.json-key or gcs.json-key-file-path must be set" ,
110
149
AssertTrue .class );
111
150
112
151
assertFailsValidation (
113
152
new GcsFileSystemConfig ()
114
153
.setJsonKey ("{}" )
115
154
.setJsonKeyFilePath ("/dev/null" ),
116
155
"authMethodValid" ,
117
- "Either gcs.use-access-token or gcs.json-key or gcs.json-key-file-path must be set" ,
156
+ "Either gcs.auth-type or gcs.json-key or gcs.json-key-file-path must be set" ,
118
157
AssertTrue .class );
119
158
120
159
assertFailsValidation (
@@ -125,5 +164,37 @@ public void testValidation()
125
164
"retryDelayValid" ,
126
165
"gcs.client.min-backoff-delay must be less than or equal to gcs.client.max-backoff-delay" ,
127
166
AssertTrue .class );
167
+
168
+ assertFailsValidation (
169
+ new GcsFileSystemConfig ()
170
+ .setAuthType (AuthType .ACCESS_TOKEN )
171
+ .setUseGcsAccessToken (true ),
172
+ "authTypeAndUseGcsAccessTokenMutuallyExclusive" ,
173
+ "Cannot set both gcs.use-access-token and gcs.auth-type" ,
174
+ AssertTrue .class );
175
+
176
+ assertFailsValidation (
177
+ new GcsFileSystemConfig ()
178
+ .setAuthType (AuthType .ACCESS_TOKEN )
179
+ .setUseGcsAccessToken (false ),
180
+ "authTypeAndUseGcsAccessTokenMutuallyExclusive" ,
181
+ "Cannot set both gcs.use-access-token and gcs.auth-type" ,
182
+ AssertTrue .class );
183
+
184
+ assertFailsValidation (
185
+ new GcsFileSystemConfig ()
186
+ .setUseGcsAccessToken (true )
187
+ .setAuthType (AuthType .DEFAULT ),
188
+ "authTypeAndUseGcsAccessTokenMutuallyExclusive" ,
189
+ "Cannot set both gcs.use-access-token and gcs.auth-type" ,
190
+ AssertTrue .class );
191
+
192
+ assertFailsValidation (
193
+ new GcsFileSystemConfig ()
194
+ .setUseGcsAccessToken (false )
195
+ .setAuthType (AuthType .DEFAULT ),
196
+ "authTypeAndUseGcsAccessTokenMutuallyExclusive" ,
197
+ "Cannot set both gcs.use-access-token and gcs.auth-type" ,
198
+ AssertTrue .class );
128
199
}
129
200
}
0 commit comments