Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/service_test_redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/service_test_s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 8 additions & 16 deletions bindings/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
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;
Expand All @@ -41,28 +38,30 @@
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;
}

@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);
}
Expand Down Expand Up @@ -194,7 +193,7 @@ public void precondition() {
*/
@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();
Expand All @@ -208,7 +207,7 @@ public void testCreateDir() {
*/
@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();

Expand Down Expand Up @@ -283,7 +282,7 @@ public void testCopyNonExistingSource() {
*/
@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())
Expand All @@ -300,7 +299,7 @@ public void testCopyTargetDir() {

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())
Expand Down Expand Up @@ -336,11 +335,8 @@ public void testCopyNested() {

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();

Expand All @@ -351,7 +347,7 @@ public void testCopyNested() {
}

/**
* Copy to a exist path should overwrite successfully.
* Copy to an existing path should overwrite successfully.
*/
@Test
public void testCopyOverwrite() {
Expand Down Expand Up @@ -424,7 +420,7 @@ public void testRenameNonExistingSource() {
*/
@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();
Expand All @@ -445,7 +441,7 @@ public void testRenameTargetDir() {

operator.write(sourcePath, content).join();

final String targetPath = String.format("%s/", UUID.randomUUID().toString());
final String targetPath = UUID.randomUUID() + "/";

operator.createDir(targetPath).join();

Expand Down Expand Up @@ -482,11 +478,8 @@ public void testRenameNested() {

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();

Expand All @@ -500,7 +493,7 @@ public void testRenameNested() {
}

/**
* Rename to a exist path should overwrite successfully.
* Rename to an existing path should overwrite successfully.
*/
@Test
public void testRenameOverwrite() {
Expand Down Expand Up @@ -589,7 +582,7 @@ public void precondition() {
*/
@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);
Expand All @@ -603,7 +596,7 @@ public void testBlockingCreateDir() {
*/
@Test
public void testBlockingDirExisting() {
final String path = String.format("%s/", UUID.randomUUID().toString());
final String path = UUID.randomUUID() + "/";
blockingOperator.createDir(path);
blockingOperator.createDir(path);

Expand Down Expand Up @@ -660,7 +653,7 @@ public void testBlockingCopyNonExistingSource() {
*/
@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);
Expand All @@ -681,7 +674,7 @@ public void testBlockingCopyTargetDir() {

blockingOperator.write(sourcePath, sourceContent);

final String targetPath = String.format("%s/", UUID.randomUUID().toString());
final String targetPath = UUID.randomUUID() + "/";

blockingOperator.createDir(targetPath);

Expand Down Expand Up @@ -718,11 +711,8 @@ public void testBlockingCopyNested() {

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

Expand All @@ -733,7 +723,7 @@ public void testBlockingCopyNested() {
}

/**
* Copy to a exist path should overwrite successfully.
* Copy to an existing path should overwrite successfully.
*/
@Test
public void testBlockingCopyOverwrite() {
Expand Down Expand Up @@ -806,7 +796,7 @@ public void testBlockingRenameNonExistingSource() {
*/
@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);
Expand All @@ -825,7 +815,7 @@ public void testBlockingRenameTargetDir() {

blockingOperator.write(sourcePath, sourceContent);

final String targetPath = String.format("%s/", UUID.randomUUID().toString());
final String targetPath = UUID.randomUUID() + "/";

blockingOperator.createDir(targetPath);

Expand Down Expand Up @@ -862,11 +852,8 @@ public void testBlockingRenameNested() {

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

Expand All @@ -880,7 +867,7 @@ public void testBlockingRenameNested() {
}

/**
* Rename to a exist path should overwrite successfully.
* Rename to an existing path should overwrite successfully.
*/
@Test
public void testBlockingRenameOverwrite() {
Expand Down Expand Up @@ -918,22 +905,4 @@ public static byte[] generateBytes() {
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;
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Comment thread
tisonkun marked this conversation as resolved.
protected FsBehaviorTest() {
super("fs", createSchemeConfig());
}

private static Map<String, String> createSchemeConfig() {
final File tempDir = Files.newTemporaryFolder();
tempDir.deleteOnExit();
return Collections.singletonMap("root", tempDir.getAbsolutePath());
}
}
Loading