rdblue commented on a change in pull request #1823:
URL: https://github.com/apache/iceberg/pull/1823#discussion_r547533230



##########
File path: 
aws/src/test/java/org/apache/iceberg/aws/glue/DynamoLockManagerTest.java
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.iceberg.aws.AwsProperties;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
+import software.amazon.awssdk.services.dynamodb.model.DeleteTableRequest;
+import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
+import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
+
+public class DynamoLockManagerTest {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(DynamoLockManagerTest.class);
+
+  private static final String DYNAMO_LOCAL_DOWNLOAD_URL =
+      
"https://s3.us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz";;
+  private static final String DYNAMO_LOCAL_DIR_NAME = "/tmp/dynamo-local";
+  private static final int DYNAMO_LOCAL_SERVER_PORT = 2333;
+  private static final String TABLE_NAME = "dynamoLockTable";
+
+  private Process dynamoLocalProcess;
+  private DynamoDbClient dynamo;
+  private AwsProperties properties;
+  private LockManager lockManager;
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    Runtime rt = Runtime.getRuntime();
+    Process pr = rt.exec(String.format("curl %s -o %s.tar.gz", 
DYNAMO_LOCAL_DOWNLOAD_URL, DYNAMO_LOCAL_DIR_NAME));
+    pr.waitFor();
+    pr = rt.exec(String.format("mkdir %s", DYNAMO_LOCAL_DIR_NAME));
+    pr.waitFor();
+    pr = rt.exec(String.format("tar xvzf %s.tar.gz -C %s", 
DYNAMO_LOCAL_DIR_NAME, DYNAMO_LOCAL_DIR_NAME));
+    pr.waitFor();
+  }
+
+  @Before
+  public void before() throws Exception {
+    Runtime rt = Runtime.getRuntime();
+    dynamoLocalProcess = rt.exec(String.format("java 
-Djava.library.path=%s/DynamoDBLocal_lib -jar " +
+            "%s/DynamoDBLocal.jar -inMemory -port %s",
+        DYNAMO_LOCAL_DIR_NAME, DYNAMO_LOCAL_DIR_NAME, 
DYNAMO_LOCAL_SERVER_PORT));
+    Thread.sleep(1000); // wait for start
+    dynamo = DynamoDbClient.builder()
+        .endpointOverride(URI.create(String.format("http://0.0.0.0:%d/";, 
DYNAMO_LOCAL_SERVER_PORT)))
+        .region(Region.US_EAST_1) // dummy region
+        .credentialsProvider(StaticCredentialsProvider.create(
+            AwsBasicCredentials.create("key", "secret"))) // dummy credential
+        .httpClient(UrlConnectionHttpClient.create())
+        .build();
+    properties = new AwsProperties();
+    properties.setGlueCatalogLockEnabled(true);
+    properties.setGlueCatalogLockTable(TABLE_NAME);
+    lockManager = new DynamoLockManager(dynamo, properties);
+  }
+
+  @After
+  public void after() throws Exception {
+    dynamo.deleteTable(DeleteTableRequest.builder()
+        .tableName(TABLE_NAME)
+        .build());
+    dynamoLocalProcess.destroy();
+    dynamoLocalProcess.waitFor();
+  }
+
+  @AfterClass
+  public static void afterClass() throws Exception {
+    Runtime.getRuntime().exec(String.format("rm %s.tar.gz", 
DYNAMO_LOCAL_DIR_NAME)).waitFor();
+    Runtime.getRuntime().exec(String.format("rm -rf %s", 
DYNAMO_LOCAL_DIR_NAME)).waitFor();
+  }
+
+  @Test
+  public void testTableCreation() {
+    try {
+      dynamo.describeTable(DescribeTableRequest.builder()
+          .tableName(TABLE_NAME)
+          .build());
+    } catch (Exception e) {
+      LOG.error("encountered failure", e);
+      Assert.fail("Should not throw exception when describing DynamoDB lock 
table");
+    }

Review comment:
       Tests already fail if an unexpected exception is thrown. I would remove 
the try/catch here.




----------------------------------------------------------------
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

Reply via email to