This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new e2337670c refactor(bindings/java): align test idiom with OPENDAL_TEST
(#3328)
e2337670c is described below
commit e2337670c7e193fc53639782f30bb4ca41b13693
Author: tison <[email protected]>
AuthorDate: Wed Oct 18 10:46:13 2023 +0800
refactor(bindings/java): align test idiom with OPENDAL_TEST (#3328)
test(bindings/java): align test idiom with OPENDAL_TEST
Signed-off-by: tison <[email protected]>
---
.github/workflows/service_test_redis.yml | 4 +-
.github/workflows/service_test_s3.yml | 4 +-
bindings/java/README.md | 24 ++----
.../test/behavior/AbstractBehaviorTest.java | 97 ++++++++--------------
.../opendal/test/behavior/FsBehaviorTest.java | 37 +++++++++
.../opendal/test/behavior/MemoryBehaviorTest.java | 33 ++++++++
.../opendal/test/behavior/ServiceBehaviorTest.java | 58 +++++++++++++
.../test/behavior/ServiceBehaviorTests.java | 92 --------------------
8 files changed, 173 insertions(+), 176 deletions(-)
diff --git a/.github/workflows/service_test_redis.yml
b/.github/workflows/service_test_redis.yml
index 1f738eac3..8bb9aecc1 100644
--- a/.github/workflows/service_test_redis.yml
+++ b/.github/workflows/service_test_redis.yml
@@ -210,9 +210,9 @@ jobs:
- name: Test
shell: bash
working-directory: bindings/java
- run: ./mvnw test -Dgroups="services_redis"
-Dcargo-build.features=services-redis
+ run: ./mvnw test -Dtest=ServiceBehaviorTest
-Dcargo-build.features=services-redis
env:
- OPENDAL_REDIS_TEST: on
+ OPENDAL_TEST: redis
OPENDAL_REDIS_ENDPOINT: tcp://127.0.0.1:6379
OPENDAL_REDIS_ROOT: /
OPENDAL_REDIS_DB: 0
diff --git a/.github/workflows/service_test_s3.yml
b/.github/workflows/service_test_s3.yml
index fcceeed7c..d97a36bb4 100644
--- a/.github/workflows/service_test_s3.yml
+++ b/.github/workflows/service_test_s3.yml
@@ -238,9 +238,9 @@ jobs:
- name: Test
shell: bash
working-directory: bindings/java
- run: ./mvnw test -Dgroups="services_s3"
+ run: ./mvnw test -Dtest=ServiceBehaviorTest
env:
- OPENDAL_S3_TEST: on
+ OPENDAL_TEST: s3
OPENDAL_S3_BUCKET: test
OPENDAL_S3_ENDPOINT: "http://127.0.0.1:9000"
OPENDAL_S3_ACCESS_KEY_ID: minioadmin
diff --git a/bindings/java/README.md b/bindings/java/README.md
index 5a7596e03..72b73302d 100644
--- a/bindings/java/README.md
+++ b/bindings/java/README.md
@@ -116,30 +116,22 @@ You can copy [.env.example](/.env.example) to
`${project.rootdir}/.env` and chan
Take `fs` for example, we need to enable bench on `fs` on `/tmp`:
```properties
-OPENDAL_FS_TEST=on
-OPENDAL_FS_ROOT=/opendal
+OPENDAL_TEST=fs
+OPENDAL_FS_ROOT=/tmp
```
You can run service tests of enabled with the following command:
```shell
-./mvnw test -Dtest=org.apache.opendal.behavior.FsTest # replace with the
certain service tests
-```
-
-Or:
-
-```shell
-./mvnw test -Dgroups="services_fs" # replace with the certain service tests
+./mvnw test -Dtest=ServiceBehaviorTest
```
Remember to enable the necessary features via
`-Dcargo-build.features=services-xxx` when running specific service test:
```shell
-./mvnw test -Dtest=org.apache.opendal.behavior.RedisTest
-Dcargo-build.features=services-redis
-```
-
-Or:
-
-```shell
-./mvnw test -Dgroups="services_redis" -Dcargo-build.features=services-redis
+export OPENDAL_TEST=redis
+export OPENDAL_REDIS_ENDPOINT=tcp://127.0.0.1:6379
+export OPENDAL_REDIS_ROOT=/
+export OPENDAL_REDIS_DB=0
+./mvnw test -Dtest=ServiceBehaviorTest -Dcargo-build.features=services-redis
```
diff --git
a/bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java
index b8bbcdb2c..6b407167e 100644
---
a/bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java
+++
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java
@@ -23,10 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
-import io.github.cdimascio.dotenv.Dotenv;
-import io.github.cdimascio.dotenv.DotenvEntry;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
@@ -41,18 +38,17 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class AbstractBehaviorTest {
+ protected final Logger log = LoggerFactory.getLogger(getClass());
protected final String scheme;
protected final Map<String, String> config;
protected Operator operator;
protected BlockingOperator blockingOperator;
- protected AbstractBehaviorTest(String scheme) {
- this(scheme, createSchemeConfig(scheme));
- }
-
protected AbstractBehaviorTest(String scheme, Map<String, String> config) {
this.scheme = scheme;
this.config = config;
@@ -60,9 +56,12 @@ public abstract class AbstractBehaviorTest {
@BeforeAll
public void setup() {
- assertThat(isSchemeEnabled(config))
- .describedAs("service test for " + scheme + " is not enabled.")
- .isTrue();
+ log.info(
+
"\n================================================================================"
+ + "\nTest {} is running with scheme {}."
+ +
"\n--------------------------------------------------------------------------------",
+ getClass().getCanonicalName(),
+ scheme);
this.operator = Operator.of(scheme, config);
this.blockingOperator = BlockingOperator.of(scheme, config);
}
@@ -194,7 +193,7 @@ public abstract class AbstractBehaviorTest {
*/
@Test
public void testCreateDir() {
- final String path = String.format("%s/",
UUID.randomUUID().toString());
+ final String path = UUID.randomUUID() + "/";
operator.createDir(path).join();
final Metadata meta = operator.stat(path).join();
@@ -208,7 +207,7 @@ public abstract class AbstractBehaviorTest {
*/
@Test
public void testCreateDirExisting() {
- final String path = String.format("%s/",
UUID.randomUUID().toString());
+ final String path = UUID.randomUUID() + "/";
operator.createDir(path).join();
operator.createDir(path).join();
@@ -283,7 +282,7 @@ public abstract class AbstractBehaviorTest {
*/
@Test
public void testCopySourceDir() {
- final String sourcePath = String.format("%s/",
UUID.randomUUID().toString());
+ final String sourcePath = UUID.randomUUID() + "/";
final String targetPath = UUID.randomUUID().toString();
assertThatThrownBy(() -> operator.copy(sourcePath,
targetPath).join())
@@ -300,7 +299,7 @@ public abstract class AbstractBehaviorTest {
operator.write(sourcePath, content).join();
- final String targetPath = String.format("%s/",
UUID.randomUUID().toString());
+ final String targetPath = UUID.randomUUID() + "/";
operator.createDir(targetPath).join();
assertThatThrownBy(() -> operator.copy(sourcePath,
targetPath).join())
@@ -336,11 +335,8 @@ public abstract class AbstractBehaviorTest {
operator.write(sourcePath, content).join();
- final String targetPath = String.format(
- "%s/%s/%s",
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString());
+ final String targetPath =
+ String.format("%s/%s/%s", UUID.randomUUID(),
UUID.randomUUID(), UUID.randomUUID());
operator.copy(sourcePath, targetPath).join();
@@ -351,7 +347,7 @@ public abstract class AbstractBehaviorTest {
}
/**
- * Copy to a exist path should overwrite successfully.
+ * Copy to an existing path should overwrite successfully.
*/
@Test
public void testCopyOverwrite() {
@@ -424,7 +420,7 @@ public abstract class AbstractBehaviorTest {
*/
@Test
public void testRenameSourceDir() {
- final String sourcePath = String.format("%s/",
UUID.randomUUID().toString());
+ final String sourcePath = UUID.randomUUID() + "/";
final String targetPath = UUID.randomUUID().toString();
operator.createDir(sourcePath).join();
@@ -445,7 +441,7 @@ public abstract class AbstractBehaviorTest {
operator.write(sourcePath, content).join();
- final String targetPath = String.format("%s/",
UUID.randomUUID().toString());
+ final String targetPath = UUID.randomUUID() + "/";
operator.createDir(targetPath).join();
@@ -482,11 +478,8 @@ public abstract class AbstractBehaviorTest {
operator.write(sourcePath, content).join();
- final String targetPath = String.format(
- "%s/%s/%s",
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString());
+ final String targetPath =
+ String.format("%s/%s/%s", UUID.randomUUID(),
UUID.randomUUID(), UUID.randomUUID());
operator.rename(sourcePath, targetPath).join();
@@ -500,7 +493,7 @@ public abstract class AbstractBehaviorTest {
}
/**
- * Rename to a exist path should overwrite successfully.
+ * Rename to an existing path should overwrite successfully.
*/
@Test
public void testRenameOverwrite() {
@@ -589,7 +582,7 @@ public abstract class AbstractBehaviorTest {
*/
@Test
public void testBlockingCreateDir() {
- final String path = String.format("%s/",
UUID.randomUUID().toString());
+ final String path = UUID.randomUUID() + "/";
blockingOperator.createDir(path);
final Metadata meta = blockingOperator.stat(path);
@@ -603,7 +596,7 @@ public abstract class AbstractBehaviorTest {
*/
@Test
public void testBlockingDirExisting() {
- final String path = String.format("%s/",
UUID.randomUUID().toString());
+ final String path = UUID.randomUUID() + "/";
blockingOperator.createDir(path);
blockingOperator.createDir(path);
@@ -660,7 +653,7 @@ public abstract class AbstractBehaviorTest {
*/
@Test
public void testBlockingCopySourceDir() {
- final String sourcePath = String.format("%s/",
UUID.randomUUID().toString());
+ final String sourcePath = UUID.randomUUID() + "/";
final String targetPath = UUID.randomUUID().toString();
blockingOperator.createDir(sourcePath);
@@ -681,7 +674,7 @@ public abstract class AbstractBehaviorTest {
blockingOperator.write(sourcePath, sourceContent);
- final String targetPath = String.format("%s/",
UUID.randomUUID().toString());
+ final String targetPath = UUID.randomUUID() + "/";
blockingOperator.createDir(targetPath);
@@ -718,11 +711,8 @@ public abstract class AbstractBehaviorTest {
blockingOperator.write(sourcePath, content);
- final String targetPath = String.format(
- "%s/%s/%s",
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString());
+ final String targetPath =
+ String.format("%s/%s/%s", UUID.randomUUID(),
UUID.randomUUID(), UUID.randomUUID());
blockingOperator.copy(sourcePath, targetPath);
@@ -733,7 +723,7 @@ public abstract class AbstractBehaviorTest {
}
/**
- * Copy to a exist path should overwrite successfully.
+ * Copy to an existing path should overwrite successfully.
*/
@Test
public void testBlockingCopyOverwrite() {
@@ -806,7 +796,7 @@ public abstract class AbstractBehaviorTest {
*/
@Test
public void testBlockingRenameSourceDir() {
- final String sourcePath = String.format("%s/",
UUID.randomUUID().toString());
+ final String sourcePath = UUID.randomUUID() + "/";
final String targetPath = UUID.randomUUID().toString();
blockingOperator.createDir(sourcePath);
@@ -825,7 +815,7 @@ public abstract class AbstractBehaviorTest {
blockingOperator.write(sourcePath, sourceContent);
- final String targetPath = String.format("%s/",
UUID.randomUUID().toString());
+ final String targetPath = UUID.randomUUID() + "/";
blockingOperator.createDir(targetPath);
@@ -862,11 +852,8 @@ public abstract class AbstractBehaviorTest {
blockingOperator.write(sourcePath, sourceContent);
- final String targetPath = String.format(
- "%s/%s/%s",
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString(),
- UUID.randomUUID().toString());
+ final String targetPath =
+ String.format("%s/%s/%s", UUID.randomUUID(),
UUID.randomUUID(), UUID.randomUUID());
blockingOperator.rename(sourcePath, targetPath);
@@ -880,7 +867,7 @@ public abstract class AbstractBehaviorTest {
}
/**
- * Rename to a exist path should overwrite successfully.
+ * Rename to an existing path should overwrite successfully.
*/
@Test
public void testBlockingRenameOverwrite() {
@@ -918,22 +905,4 @@ public abstract class AbstractBehaviorTest {
random.nextBytes(content);
return content;
}
-
- protected static boolean isSchemeEnabled(Map<String, String> config) {
- final String turnOn = config.getOrDefault("test", "").toLowerCase();
- return turnOn.equals("on") || turnOn.equals("true");
- }
-
- protected static Map<String, String> createSchemeConfig(String scheme) {
- final Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
- final Map<String, String> config = new HashMap<>();
- final String prefix = "opendal_" + scheme.toLowerCase() + "_";
- for (DotenvEntry entry : dotenv.entries()) {
- final String key = entry.getKey().toLowerCase();
- if (key.startsWith(prefix)) {
- config.put(key.substring(prefix.length()), entry.getValue());
- }
- }
- return config;
- }
}
diff --git
a/bindings/java/src/test/java/org/apache/opendal/test/behavior/FsBehaviorTest.java
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/FsBehaviorTest.java
new file mode 100644
index 000000000..6acf1d28a
--- /dev/null
+++
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/FsBehaviorTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.opendal.test.behavior;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.Map;
+import org.assertj.core.util.Files;
+
+class FsBehaviorTest extends AbstractBehaviorTest {
+ protected FsBehaviorTest() {
+ super("fs", createSchemeConfig());
+ }
+
+ private static Map<String, String> createSchemeConfig() {
+ final File tempDir = Files.newTemporaryFolder();
+ tempDir.deleteOnExit();
+ return Collections.singletonMap("root", tempDir.getAbsolutePath());
+ }
+}
diff --git
a/bindings/java/src/test/java/org/apache/opendal/test/behavior/MemoryBehaviorTest.java
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/MemoryBehaviorTest.java
new file mode 100644
index 000000000..23ece54d3
--- /dev/null
+++
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/MemoryBehaviorTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.opendal.test.behavior;
+
+import java.util.Collections;
+import java.util.Map;
+
+class MemoryBehaviorTest extends AbstractBehaviorTest {
+ protected MemoryBehaviorTest() {
+ super("memory", createSchemeConfig());
+ }
+
+ private static Map<String, String> createSchemeConfig() {
+ return Collections.singletonMap("root", "/tmp");
+ }
+}
diff --git
a/bindings/java/src/test/java/org/apache/opendal/test/behavior/ServiceBehaviorTest.java
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/ServiceBehaviorTest.java
new file mode 100644
index 000000000..8341f8351
--- /dev/null
+++
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/ServiceBehaviorTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.opendal.test.behavior;
+
+import io.github.cdimascio.dotenv.Dotenv;
+import io.github.cdimascio.dotenv.DotenvEntry;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.condition.EnabledIf;
+
+@EnabledIf("enabled")
+class ServiceBehaviorTest extends AbstractBehaviorTest {
+ protected ServiceBehaviorTest() {
+ super(lookupScheme(), createSchemeConfig());
+ }
+
+ private static boolean enabled() {
+ return lookupScheme() != null;
+ }
+
+ private static String lookupScheme() {
+ final Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
+ return dotenv.get("OPENDAL_TEST");
+ }
+
+ private static Map<String, String> createSchemeConfig() {
+ final String scheme = lookupScheme();
+ final Map<String, String> config = new HashMap<>();
+ if (scheme != null) {
+ final String prefix = "opendal_" + scheme.toLowerCase() + "_";
+ final Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
+ for (DotenvEntry entry : dotenv.entries()) {
+ final String key = entry.getKey().toLowerCase();
+ if (key.startsWith(prefix)) {
+ config.put(key.substring(prefix.length()),
entry.getValue());
+ }
+ }
+ }
+ return config;
+ }
+}
diff --git
a/bindings/java/src/test/java/org/apache/opendal/test/behavior/ServiceBehaviorTests.java
b/bindings/java/src/test/java/org/apache/opendal/test/behavior/ServiceBehaviorTests.java
deleted file mode 100644
index c8154419a..000000000
---
a/bindings/java/src/test/java/org/apache/opendal/test/behavior/ServiceBehaviorTests.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.opendal.test.behavior;
-
-import java.io.File;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.assertj.core.util.Files;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.condition.EnabledIf;
-
-@Tag("services_memory")
-@Slf4j
-class MemoryTest extends AbstractBehaviorTest {
- public MemoryTest() {
- super("memory", defaultSchemeConfig());
- }
-
- private static Map<String, String> defaultSchemeConfig() {
- final Map<String, String> config = createSchemeConfig("memory");
- if (!isSchemeEnabled(config)) {
- log.info("Running MemoryTest with default config.");
- config.clear();
- config.put("test", "on");
- config.put("root", "/tmp");
- }
- return config;
- }
-}
-
-@Tag("services_fs")
-@Slf4j
-class FsTest extends AbstractBehaviorTest {
- public FsTest() {
- super("fs", schemeConfig());
- }
-
- private static Map<String, String> schemeConfig() {
- final Map<String, String> config = createSchemeConfig("fs");
- if (!isSchemeEnabled(config)) {
- log.info("Running FsTest with default config.");
- config.clear();
-
- final File tempDir = Files.newTemporaryFolder();
- tempDir.deleteOnExit();
- config.put("test", "on");
- config.put("root", tempDir.getAbsolutePath());
- }
- return config;
- }
-}
-
-@Tag("services_redis")
-@EnabledIf("enabled")
-class RedisTest extends AbstractBehaviorTest {
- public RedisTest() {
- super("redis");
- }
-
- private static boolean enabled() {
- return isSchemeEnabled(createSchemeConfig("redis"));
- }
-}
-
-@Tag("services_s3")
-@EnabledIf("enabled")
-class S3Test extends AbstractBehaviorTest {
- public S3Test() {
- super("s3");
- }
-
- private static boolean enabled() {
- return isSchemeEnabled(createSchemeConfig("s3"));
- }
-}