22
22
import static org .apache .polaris .service .it .env .PolarisClient .polarisClient ;
23
23
import static org .assertj .core .api .Assertions .assertThat ;
24
24
25
- import com .google .common .collect .ImmutableMap ;
26
25
import jakarta .ws .rs .client .Entity ;
27
26
import jakarta .ws .rs .core .Response ;
28
- import java .lang .annotation .Retention ;
29
- import java .lang .annotation .RetentionPolicy ;
27
+ import java .io .IOException ;
30
28
import java .lang .reflect .Method ;
31
29
import java .net .URI ;
32
30
import java .nio .file .Path ;
64
62
import org .apache .polaris .core .entity .CatalogEntity ;
65
63
import org .apache .polaris .core .policy .PredefinedPolicyTypes ;
66
64
import org .apache .polaris .core .policy .exceptions .PolicyInUseException ;
65
+ import org .apache .polaris .service .it .env .CatalogConfig ;
67
66
import org .apache .polaris .service .it .env .ClientCredentials ;
68
67
import org .apache .polaris .service .it .env .IcebergHelper ;
69
68
import org .apache .polaris .service .it .env .IntegrationTestsHelper ;
70
69
import org .apache .polaris .service .it .env .ManagementApi ;
71
70
import org .apache .polaris .service .it .env .PolarisApiEndpoints ;
72
71
import org .apache .polaris .service .it .env .PolarisClient ;
73
72
import org .apache .polaris .service .it .env .PolicyApi ;
73
+ import org .apache .polaris .service .it .env .RestCatalogConfig ;
74
74
import org .apache .polaris .service .it .ext .PolarisIntegrationTestExtension ;
75
75
import org .apache .polaris .service .types .ApplicablePolicy ;
76
76
import org .apache .polaris .service .types .AttachPolicyRequest ;
@@ -131,25 +131,10 @@ public class PolarisPolicyServiceIntegrationTest {
131
131
private final String catalogBaseLocation =
132
132
s3BucketBase + "/" + System .getenv ("USER" ) + "/path/to/data" ;
133
133
134
- private static final String [] DEFAULT_CATALOG_PROPERTIES = {
135
- "polaris.config.allow.unstructured.table.location" , "true" ,
136
- "polaris.config.allow.external.table.location" , "true"
137
- };
138
-
139
- @ Retention (RetentionPolicy .RUNTIME )
140
- private @interface CatalogConfig {
141
- Catalog .TypeEnum value () default Catalog .TypeEnum .INTERNAL ;
142
-
143
- String [] properties () default {
144
- "polaris.config.allow.unstructured.table.location" , "true" ,
145
- "polaris.config.allow.external.table.location" , "true"
146
- };
147
- }
148
-
149
- @ Retention (RetentionPolicy .RUNTIME )
150
- private @interface RestCatalogConfig {
151
- String [] value () default {};
152
- }
134
+ private static final Map <String , String > DEFAULT_CATALOG_PROPERTIES =
135
+ Map .of (
136
+ "polaris.config.allow.unstructured.table.location" , "true" ,
137
+ "polaris.config.allow.external.table.location" , "true" );
153
138
154
139
@ BeforeAll
155
140
public static void setup (
@@ -188,28 +173,26 @@ public void before(TestInfo testInfo) {
188
173
.setStorageType (StorageConfigInfo .StorageTypeEnum .S3 )
189
174
.setAllowedLocations (List .of ("s3://my-old-bucket/path/to/data" ))
190
175
.build ();
191
- Optional <PolarisPolicyServiceIntegrationTest .CatalogConfig > catalogConfig =
192
- Optional .ofNullable (
193
- method .getAnnotation (PolarisPolicyServiceIntegrationTest .CatalogConfig .class ));
194
176
195
177
CatalogProperties .Builder catalogPropsBuilder = CatalogProperties .builder (catalogBaseLocation );
196
- String [] properties =
197
- catalogConfig
198
- .map (PolarisPolicyServiceIntegrationTest .CatalogConfig ::properties )
199
- .orElse (DEFAULT_CATALOG_PROPERTIES );
200
- for (int i = 0 ; i < properties .length ; i += 2 ) {
201
- catalogPropsBuilder .addProperty (properties [i ], properties [i + 1 ]);
202
- }
178
+
179
+ Map <String , String > catalogProperties =
180
+ IntegrationTestsHelper .mergeFromAnnotatedElements (
181
+ testInfo , CatalogConfig .class , CatalogConfig ::properties , DEFAULT_CATALOG_PROPERTIES );
182
+ catalogPropsBuilder .putAll (catalogProperties );
183
+
203
184
if (!s3BucketBase .getScheme ().equals ("file" )) {
204
185
catalogPropsBuilder .addProperty (
205
186
CatalogEntity .REPLACE_NEW_LOCATION_PREFIX_WITH_CATALOG_DEFAULT_KEY , "file:" );
206
187
}
188
+
189
+ Catalog .TypeEnum catalogType =
190
+ IntegrationTestsHelper .extractFromAnnotatedElements (
191
+ testInfo , CatalogConfig .class , CatalogConfig ::value , Catalog .TypeEnum .INTERNAL );
192
+
207
193
Catalog catalog =
208
194
PolarisCatalog .builder ()
209
- .setType (
210
- catalogConfig
211
- .map (PolarisPolicyServiceIntegrationTest .CatalogConfig ::value )
212
- .orElse (Catalog .TypeEnum .INTERNAL ))
195
+ .setType (catalogType )
213
196
.setName (currentCatalogName )
214
197
.setProperties (catalogPropsBuilder .build ())
215
198
.setStorageConfigInfo (
@@ -221,26 +204,14 @@ public void before(TestInfo testInfo) {
221
204
222
205
managementApi .createCatalog (principalRoleName , catalog );
223
206
224
- Optional <PolarisPolicyServiceIntegrationTest .RestCatalogConfig > restCatalogConfig =
225
- testInfo
226
- .getTestMethod ()
227
- .flatMap (
228
- m ->
229
- Optional .ofNullable (
230
- m .getAnnotation (
231
- PolarisPolicyServiceIntegrationTest .RestCatalogConfig .class )));
232
- ImmutableMap .Builder <String , String > extraPropertiesBuilder = ImmutableMap .builder ();
233
- restCatalogConfig .ifPresent (
234
- config -> {
235
- for (int i = 0 ; i < config .value ().length ; i += 2 ) {
236
- extraPropertiesBuilder .put (config .value ()[i ], config .value ()[i + 1 ]);
237
- }
238
- });
207
+ Map <String , String > restCatalogProperties =
208
+ IntegrationTestsHelper .mergeFromAnnotatedElements (
209
+ testInfo , RestCatalogConfig .class , RestCatalogConfig ::value , Map .of ());
239
210
240
211
String principalToken = client .obtainToken (principalCredentials );
241
212
restCatalog =
242
213
IcebergHelper .restCatalog (
243
- endpoints , currentCatalogName , extraPropertiesBuilder . build () , principalToken );
214
+ endpoints , currentCatalogName , restCatalogProperties , principalToken );
244
215
CatalogGrant catalogGrant =
245
216
new CatalogGrant (CatalogPrivilege .CATALOG_MANAGE_CONTENT , GrantResource .TypeEnum .CATALOG );
246
217
managementApi .createCatalogRole (currentCatalogName , CATALOG_ROLE_1 );
@@ -253,8 +224,14 @@ public void before(TestInfo testInfo) {
253
224
}
254
225
255
226
@ AfterEach
256
- public void cleanUp () {
257
- client .cleanUp (adminToken );
227
+ public void cleanUp () throws IOException {
228
+ try {
229
+ if (restCatalog != null ) {
230
+ restCatalog .close ();
231
+ }
232
+ } finally {
233
+ client .cleanUp (adminToken );
234
+ }
258
235
}
259
236
260
237
@ Test
0 commit comments