Skip to content

Commit

Permalink
test: resturcture java behavior tests (#3161)
Browse files Browse the repository at this point in the history
* test(bindings/java): polish tests and setup

Signed-off-by: tison <[email protected]>

* docs: update

Signed-off-by: tison <[email protected]>

* test: resturcture java behavior tests

Signed-off-by: tison <[email protected]>

* tidy

Signed-off-by: tison <[email protected]>

* fix s3 tests

Signed-off-by: tison <[email protected]>

* fix jdk8 test compat

Signed-off-by: tison <[email protected]>

* bump version

Signed-off-by: tison <[email protected]>

* squash files

Signed-off-by: tison <[email protected]>

---------

Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun authored Sep 23, 2023
1 parent a2fab34 commit 5d4300e
Show file tree
Hide file tree
Showing 13 changed files with 462 additions and 563 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/bindings_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ jobs:
# https://maven.apache.org/guides/mini/guide-reproducible-builds.html#how-to-test-my-maven-build-reproducibility
shell: bash
run: |
./mvnw clean install -DskipTests -Dcargo-build.features=services-redis
./mvnw clean install -DskipTests
./mvnw verify artifact:compare
4 changes: 2 additions & 2 deletions .github/workflows/service_test_redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ jobs:
OPENDAL_REDIS_ROOT: /
OPENDAL_REDIS_DB: 0

binding_java_redis:
java:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -209,7 +209,7 @@ jobs:
- name: Test
shell: bash
working-directory: bindings/java
run: ./mvnw test -Dtest=org.apache.opendal.OperatorTest -Dcargo-build.features=services-redis
run: ./mvnw test -Dtest=org.apache.opendal.behavior.RedisTest -Dcargo-build.features=services-redis
env:
OPENDAL_REDIS_TEST: on
OPENDAL_REDIS_ENDPOINT: tcp://127.0.0.1:6379
Expand Down
29 changes: 18 additions & 11 deletions .github/workflows/service_test_s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,30 @@ jobs:
# Refer to https://opendal.apache.org/docs/services/s3#compatible-services for more information
OPENDAL_S3_ENABLE_EXACT_BUF_WRITE: true

binding_java_s3:
java:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup MinIO Server
shell: bash
working-directory: fixtures/s3
run: docker-compose -f docker-compose-minio.yml up -d
- name: Setup test bucket
env:
AWS_ACCESS_KEY_ID: "minioadmin"
AWS_SECRET_ACCESS_KEY: "minioadmin"
AWS_EC2_METADATA_DISABLED: "true"
run: aws --endpoint-url http://127.0.0.1:9000/ s3 mb s3://test
- name: Setup Rust toolchain
uses: ./.github/actions/setup

- name: Test
shell: bash
working-directory: bindings/java
run: ./mvnw test -Dtest=org.apache.opendal.OperatorTest
run: ./mvnw test -Dtest=org.apache.opendal.behavior.S3Test
env:
OPENDAL_S3_TEST: ${{ secrets.OPENDAL_S3_TEST }}
OPENDAL_S3_ROOT: ${{ secrets.OPENDAL_S3_ROOT }}
OPENDAL_S3_BUCKET: ${{ secrets.OPENDAL_S3_BUCKET }}
OPENDAL_S3_ENDPOINT: ${{ secrets.OPENDAL_S3_ENDPOINT }}
OPENDAL_S3_ACCESS_KEY_ID: ${{ secrets.OPENDAL_S3_ACCESS_KEY_ID }}
OPENDAL_S3_SECRET_ACCESS_KEY: ${{ secrets.OPENDAL_S3_SECRET_ACCESS_KEY }}
OPENDAL_S3_REGION: ap-northeast-1
OPENDAL_S3_TEST: on
OPENDAL_S3_BUCKET: test
OPENDAL_S3_ENDPOINT: "http://127.0.0.1:9000"
OPENDAL_S3_ACCESS_KEY_ID: minioadmin
OPENDAL_S3_SECRET_ACCESS_KEY: minioadmin
OPENDAL_S3_REGION: us-east-1
65 changes: 27 additions & 38 deletions bindings/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ Generally, you can first add the `os-maven-plugin` for automatically detect the

```xml
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.7.0</version>
</extension>
</extensions>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.7.0</version>
</extension>
</extensions>
</build>
```

Then add the dependency to `opendal-java` as following:

```xml
<dependencies>
<dependency>
<groupId>org.apache.opendal</groupId>
<artifactId>opendal-java</artifactId>
Expand All @@ -39,32 +40,30 @@ Then add the dependency to `opendal-java` as following:
<version>${opendal.version}</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
</dependencies>
```

### Gradle

For Gradle you can first add the `com.google.osdetector` for automatically detect the classifier based on your platform:
For Gradle, you can first add the `com.google.osdetector` for automatically detect the classifier based on your platform:

```groovy
plugins {
...
id "com.google.osdetector" version "1.7.3"
}
```

Then add the dependency to `opendal-java` as following:

```groovy
dependencies {
...
// OpenDAL
implementation "org.apache.opendal:opendal-java:0.40.0"
implementation "org.apache.opendal:opendal-java:0.40.0:$osdetector.classifier"
}
```

### Classified library

Note that the dependency without classifier ships all classes and resources except the "opendal_java" shared library. And those with classifier bundle only the shared library.

For downstream usage, it's recommended:
Expand Down Expand Up @@ -98,47 +97,37 @@ You can run the base tests with the following command:
./mvnw clean verify
```

## Run Service Tests
## Code style

Please copy `{project.rootdir}/.env.example` to `{project.rootdir}/.env` and change the values on need.
This project uses [spotless](https://github.com/diffplug/spotless) for code formatting so that all developers share a consistent code style without bikeshedding on it.

Take `fs` for example, we need to enable bench on `fs` on `/tmp`.
You can apply the code style with the following command::

```dotenv
OPENDAL_FS_TEST=false
OPENDAL_FS_ROOT=/path/to/dir
```shell
./mvnw spotless:apply
```

into
## Run Service Tests

Services tests read necessary configs from env vars or the `.env` file.

You can copy [.env.example](/.env.example) to `${project.rootdir}/.env` and change the values on need, or directly set env vars with `export KEY=VALUE`.

```dotenv
Take `fs` for example, we need to enable bench on `fs` on `/tmp`:

```properties
OPENDAL_FS_TEST=on
OPENDAL_FS_ROOT=/opendal
```

You can run service tests of enabled with the following command:

```shell
./mvnw test -Dtest=org.apache.opendal.OperatorTest
./mvnw test -Dtest=org.apache.opendal.behavior.FsTest # replace with the certain service tests
```

You can run the unbound service with the following command:
Remember to enable the necessary features via `-Dcargo-build.features=services-xxx` when running specific service test:

```shell
./mvnw test -Dtest=org.apache.opendal.OperatorTest -Dcargo-build.features=services-redis
```

> **Note:**
>
> The `-Dcargo-build.features=services-redis` argument is a temporary workaround. See also:
>
> * https://github.com/apache/incubator-opendal/pull/3060
> * https://github.com/apache/incubator-opendal/issues/3066
Additionally, this project uses [spotless](https://github.com/diffplug/spotless) for code formatting so that all developers share a consistent code style without bikeshedding on it.

You can apply the code style with the following command::

```shell
./mvnw spotless:apply
./mvnw test -Dtest=org.apache.opendal.behavior.RedisTest -Dcargo-build.features=services-redis
```
41 changes: 11 additions & 30 deletions bindings/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@

<!-- library dependencies -->
<assertj.version>3.23.1</assertj.version>
<dotenv.version>2.3.2</dotenv.version>
<lombok.version>1.18.30</lombok.version>
<slf4j.version>2.0.7</slf4j.version>
<testcontainers.version>1.18.3</testcontainers.version>

<!-- plugins dependencies -->
<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
<os-maven-plugin.version>1.7.0</os-maven-plugin.version>
<palantir-java-format.version>2.36.0</palantir-java-format.version>
Expand All @@ -73,20 +73,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>7.11.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
Expand All @@ -109,6 +95,11 @@
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>${dotenv.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -119,16 +110,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
Expand All @@ -145,13 +126,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Loading

0 comments on commit 5d4300e

Please sign in to comment.