You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by op...@apache.org on 2021/09/30 06:38:03 UTC

[iceberg] branch master updated: Aliyun: Add configurable TestRule. (#3197)

This is an automated email from the ASF dual-hosted git repository.

openinx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 6f6bd49  Aliyun: Add configurable TestRule. (#3197)
6f6bd49 is described below

commit 6f6bd49b4afb562446d63261372dcd0c4a434e7b
Author: mikewu <xi...@gmail.com>
AuthorDate: Thu Sep 30 14:37:53 2021 +0800

    Aliyun: Add configurable TestRule. (#3197)
---
 .../iceberg/aliyun/oss/AliyunOSSTestUtility.java   | 59 ++++++++++++++++++++++
 .../aliyun/oss/mock/TestLocalAliyunOSS.java        |  3 +-
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/AliyunOSSTestUtility.java b/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/AliyunOSSTestUtility.java
new file mode 100644
index 0000000..0e872f3
--- /dev/null
+++ b/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/AliyunOSSTestUtility.java
@@ -0,0 +1,59 @@
+/*
+ * 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.aliyun.oss;
+
+import org.apache.iceberg.aliyun.oss.mock.AliyunOSSMockRule;
+import org.apache.iceberg.common.DynConstructors;
+import org.apache.iceberg.relocated.com.google.common.base.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AliyunOSSTestUtility {
+  private static final Logger LOG = LoggerFactory.getLogger(AliyunOSSTestUtility.class);
+  private static final String ALIYUN_TEST_OSS_TEST_RULE_CLASS = "ALIYUN_TEST_OSS_TEST_RULE_CLASS";
+
+  private AliyunOSSTestUtility() {
+  }
+
+  public static AliyunOSSTestRule initialize() {
+    AliyunOSSTestRule testRule;
+
+    String implClass = System.getenv(ALIYUN_TEST_OSS_TEST_RULE_CLASS);
+    if (!Strings.isNullOrEmpty(implClass)) {
+      LOG.info("The initializing AliyunOSSTestRule implementation is: {}", implClass);
+      try {
+        DynConstructors.Ctor<AliyunOSSTestRule> ctor =
+            DynConstructors.builder(AliyunOSSTestRule.class).impl(implClass).buildChecked();
+        testRule = ctor.newInstance();
+      } catch (NoSuchMethodException e) {
+        throw new IllegalArgumentException(String.format(
+            "Cannot initialize AliyunOSSTestRule, missing no-arg constructor: %s", implClass), e);
+      } catch (ClassCastException e) {
+        throw new IllegalArgumentException(String.format(
+            "Cannot initialize AliyunOSSTestRule, %s does not implement it.", implClass), e);
+      }
+    } else {
+      LOG.info("Initializing AliyunOSSTestRule implementation with default AliyunOSSMockRule");
+      testRule = AliyunOSSMockRule.builder().silent().build();
+    }
+
+    return testRule;
+  }
+}
diff --git a/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/TestLocalAliyunOSS.java b/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/TestLocalAliyunOSS.java
index faa13b2..6b9fc89 100644
--- a/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/TestLocalAliyunOSS.java
+++ b/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/TestLocalAliyunOSS.java
@@ -32,6 +32,7 @@ import java.util.Random;
 import java.util.UUID;
 import org.apache.commons.io.IOUtils;
 import org.apache.iceberg.aliyun.oss.AliyunOSSTestRule;
+import org.apache.iceberg.aliyun.oss.AliyunOSSTestUtility;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -41,7 +42,7 @@ import org.junit.Test;
 public class TestLocalAliyunOSS {
 
   @ClassRule
-  public static final AliyunOSSTestRule OSS_TEST_RULE = AliyunOSSMockRule.builder().silent().build();
+  public static final AliyunOSSTestRule OSS_TEST_RULE = AliyunOSSTestUtility.initialize();
 
   private final OSS oss = OSS_TEST_RULE.createOSSClient();
   private final String bucketName = OSS_TEST_RULE.testBucketName();