1616import com .google .common .collect .ImmutableMap ;
1717import io .airlift .units .DataSize ;
1818import io .airlift .units .Duration ;
19+ import io .trino .filesystem .gcs .GcsFileSystemConfig .AuthType ;
1920import jakarta .validation .constraints .AssertTrue ;
2021import org .junit .jupiter .api .Test ;
2122
@@ -41,9 +42,10 @@ void testDefaults()
4142 .setWriteBlockSize (DataSize .of (16 , MEGABYTE ))
4243 .setPageSize (100 )
4344 .setBatchSize (100 )
45+ .setUseGcsAccessToken (false )
4446 .setProjectId (null )
4547 .setEndpoint (Optional .empty ())
46- .setUseGcsAccessToken ( false )
48+ .setAuthType ( AuthType . DEFAULT )
4749 .setJsonKey (null )
4850 .setJsonKeyFilePath (null )
4951 .setMaxRetries (20 )
@@ -56,6 +58,43 @@ void testDefaults()
5658
5759 @ Test
5860 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 ()
5998 {
6099 Map <String , String > properties = ImmutableMap .<String , String >builder ()
61100 .put ("gcs.read-block-size" , "51MB" )
@@ -87,34 +126,34 @@ void testExplicitPropertyMappings()
87126 .setMinBackoffDelay (new Duration (20 , MILLISECONDS ))
88127 .setMaxBackoffDelay (new Duration (20 , MILLISECONDS ))
89128 .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" ));
91130 }
92131
93132 @ Test
94133 public void testValidation ()
95134 {
96135 assertFailsValidation (
97136 new GcsFileSystemConfig ()
98- .setUseGcsAccessToken ( true )
137+ .setAuthType ( AuthType . ACCESS_TOKEN )
99138 .setJsonKey ("{}}" ),
100139 "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" ,
102141 AssertTrue .class );
103142
104143 assertFailsValidation (
105144 new GcsFileSystemConfig ()
106- .setUseGcsAccessToken ( true )
145+ .setAuthType ( AuthType . ACCESS_TOKEN )
107146 .setJsonKeyFilePath ("/dev/null" ),
108147 "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" ,
110149 AssertTrue .class );
111150
112151 assertFailsValidation (
113152 new GcsFileSystemConfig ()
114153 .setJsonKey ("{}" )
115154 .setJsonKeyFilePath ("/dev/null" ),
116155 "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" ,
118157 AssertTrue .class );
119158
120159 assertFailsValidation (
@@ -125,5 +164,37 @@ public void testValidation()
125164 "retryDelayValid" ,
126165 "gcs.client.min-backoff-delay must be less than or equal to gcs.client.max-backoff-delay" ,
127166 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 );
128199 }
129200}
0 commit comments