rdblue commented on a change in pull request #1633: URL: https://github.com/apache/iceberg/pull/1633#discussion_r513637554
########## File path: aws/src/test/java/org/apache/iceberg/aws/glue/TestGlueCatalogInteg.java ########## @@ -0,0 +1,375 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iceberg.aws.glue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; +import org.apache.hadoop.conf.Configuration; +import org.apache.iceberg.AssertHelpers; +import org.apache.iceberg.BaseMetastoreTableOperations; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.DataFiles; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.Table; +import org.apache.iceberg.TableMetadata; +import org.apache.iceberg.TableOperations; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.exceptions.NoSuchNamespaceException; +import org.apache.iceberg.exceptions.NoSuchTableException; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.apache.iceberg.types.Types; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.services.glue.GlueClient; +import software.amazon.awssdk.services.glue.model.Database; +import software.amazon.awssdk.services.glue.model.DeleteDatabaseRequest; +import software.amazon.awssdk.services.glue.model.EntityNotFoundException; +import software.amazon.awssdk.services.glue.model.GetDatabaseRequest; +import software.amazon.awssdk.services.glue.model.GetTableRequest; +import software.amazon.awssdk.services.glue.model.GetTableResponse; +import software.amazon.awssdk.services.glue.model.GetTableVersionsRequest; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.Delete; +import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest; +import software.amazon.awssdk.services.s3.model.HeadObjectRequest; +import software.amazon.awssdk.services.s3.model.ListObjectsV2Request; +import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; +import software.amazon.awssdk.services.s3.model.ObjectIdentifier; +import software.amazon.awssdk.services.s3.model.S3Object; + +@Ignore +public class TestGlueCatalogInteg { + + private static final Logger LOG = LoggerFactory.getLogger(TestGlueCatalogInteg.class); + + private static final List<String> NAMESPACES = new ArrayList<>(); + private static final GlueClient GLUE = GlueClient.create(); + private static final S3Client S3 = S3Client.create(); + private static final String PREFIX = getRandomName(); + + // the integration test requires the following env variables + private static final String AWS_ACCESS_KEY_ID = System.getenv("AWS_ACCESS_KEY_ID"); + private static final String AWS_SECRET_ACCESS_KEY = System.getenv("AWS_SECRET_ACCESS_KEY"); + private static final String BUCKET = System.getenv("GLUE_BUCKET"); + + private static GlueCatalog glueCatalog; + private static GlueCatalog glueCatalogWithSkip; + + @BeforeClass + public static void beforeClass() { + Configuration configuration = new Configuration(); + // Iceberg uses Hadoop 2.7.3, and the hadoop-aws module does not support reading environment variable yet + configuration.set("fs.s3a.access.key", AWS_ACCESS_KEY_ID); + configuration.set("fs.s3a.secret.key", AWS_SECRET_ACCESS_KEY); + String testBucketPath = "s3a://" + BUCKET + "/" + PREFIX; + glueCatalog = new GlueCatalog(configuration, GLUE, null, testBucketPath, false); + glueCatalogWithSkip = new GlueCatalog(configuration, GLUE, null, testBucketPath, true); + } + + @AfterClass + public static void afterClass() { + for (String namespace : NAMESPACES) { + try { + // delete db also delete tables + GLUE.deleteDatabase(DeleteDatabaseRequest.builder().name(namespace).build()); + } catch (Exception e) { + // pass + } + } + boolean hasContent = true; + while (hasContent) { + ListObjectsV2Response response = S3.listObjectsV2(ListObjectsV2Request.builder() + .bucket(BUCKET).prefix(PREFIX).build()); + hasContent = response.hasContents(); + if (hasContent) { + S3.deleteObjects(DeleteObjectsRequest.builder().bucket(BUCKET).delete(Delete.builder().objects( + response.contents().stream() + .map(obj -> ObjectIdentifier.builder().key(obj.key()).build()) + .collect(Collectors.toList()) + ).build()).build()); + } + } + } + + @Test + public void testNamespace() { + // create ns + String namespace = getRandomName(); + NAMESPACES.add(namespace); + glueCatalog.createNamespace(Namespace.of(namespace)); + Database database = GLUE.getDatabase(GetDatabaseRequest.builder().name(namespace).build()).database(); + Assert.assertEquals(namespace, database.name()); + // list all Review comment: Can you separate the different calls into test methods? Combining a lot of cases together makes it harder to see what's wrong because failures prevent other test cases from running. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org