|
49 | 49 | import org.apache.polaris.core.entity.PrincipalRoleEntity; |
50 | 50 | import org.apache.polaris.core.persistence.MetaStoreManagerFactory; |
51 | 51 | import org.apache.polaris.core.persistence.PolarisMetaStoreManager; |
| 52 | +import org.apache.polaris.core.persistence.dao.entity.BaseResult; |
52 | 53 | import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult; |
53 | 54 | import org.apache.polaris.core.persistence.dao.entity.EntityResult; |
54 | 55 | import org.apache.polaris.core.secrets.UnsafeInMemorySecretsManager; |
55 | 56 | import org.apache.polaris.service.TestServices; |
56 | 57 | import org.apache.polaris.service.config.ReservedProperties; |
| 58 | +import org.assertj.core.api.Assertions; |
57 | 59 | import org.junit.jupiter.api.BeforeEach; |
58 | 60 | import org.junit.jupiter.api.Test; |
| 61 | +import org.mockito.Mockito; |
59 | 62 |
|
60 | 63 | public class ManagementServiceTest { |
61 | 64 | private TestServices services; |
@@ -285,4 +288,44 @@ public void testCanListCatalogs() { |
285 | 288 | .extracting(Catalog::getName) |
286 | 289 | .containsExactlyInAnyOrder("my-catalog-1", "my-catalog-2"); |
287 | 290 | } |
| 291 | + |
| 292 | + @Test |
| 293 | + public void testCreateCatalogReturnErrorOnFailure() { |
| 294 | + PolarisMetaStoreManager metaStoreManager = Mockito.spy(setupMetaStoreManager()); |
| 295 | + PolarisCallContext callContext = services.newCallContext(); |
| 296 | + PolarisAdminService polarisAdminService = |
| 297 | + setupPolarisAdminService(metaStoreManager, callContext); |
| 298 | + |
| 299 | + AwsStorageConfigInfo awsConfigModel = |
| 300 | + AwsStorageConfigInfo.builder() |
| 301 | + .setRoleArn("arn:aws:iam::123456789012:role/my-role") |
| 302 | + .setExternalId("externalId") |
| 303 | + .setUserArn("userArn") |
| 304 | + .setStorageType(StorageConfigInfo.StorageTypeEnum.S3) |
| 305 | + .setAllowedLocations(List.of("s3://my-old-bucket/path/to/data")) |
| 306 | + .build(); |
| 307 | + String catalogName = "mycatalog"; |
| 308 | + Catalog catalog = |
| 309 | + PolarisCatalog.builder() |
| 310 | + .setType(Catalog.TypeEnum.INTERNAL) |
| 311 | + .setName(catalogName) |
| 312 | + .setProperties(new CatalogProperties("s3://bucket/path/to/data")) |
| 313 | + .setStorageConfigInfo(awsConfigModel) |
| 314 | + .build(); |
| 315 | + CreateCatalogResult resultWithError = |
| 316 | + new CreateCatalogResult( |
| 317 | + BaseResult.ReturnStatus.UNEXPECTED_ERROR_SIGNALED, "Unexpected Error Occurred"); |
| 318 | + Mockito.doAnswer(invocation -> resultWithError) |
| 319 | + .when(metaStoreManager) |
| 320 | + .createCatalog(Mockito.any(), Mockito.any(), Mockito.any()); |
| 321 | + Assertions.assertThatThrownBy( |
| 322 | + () -> polarisAdminService.createCatalog(new CreateCatalogRequest(catalog))) |
| 323 | + .isInstanceOf(IllegalStateException.class) |
| 324 | + .hasMessage( |
| 325 | + String.format( |
| 326 | + "Cannot create Catalog %s: %s with extraInfo %s", |
| 327 | + catalogName, |
| 328 | + resultWithError.getReturnStatus(), |
| 329 | + resultWithError.getExtraInformation())); |
| 330 | + } |
288 | 331 | } |
0 commit comments