Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(bindings/java): for BlockingOperator #2344

Merged
merged 6 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions bindings/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ You can run tests with the following command:
```shell
mvn clean verify
```

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.
tisonkun marked this conversation as resolved.
Show resolved Hide resolved

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

```shell
mvn spotless:apply
```
29 changes: 29 additions & 0 deletions bindings/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
<spotless.version>2.37.0</spotless.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -196,6 +197,34 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<java>
<palantirJavaFormat>
<version>2.30.0</version>
</palantirJavaFormat>
<!-- static imports first, then others, no blank lines -->
<importOrder>
<order>\#|</order>
</importOrder>
<removeUnusedImports/>
<trimTrailingWhitespace/>
<endWithNewline/>
</java>
</configuration>
<executions>
<execution>
<id>codestyle</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@

import java.util.Map;

/**
* A blocking operator represents an underneath OpenDAL operator that
* accesses data synchronously.
*/
public class BlockingOperator extends NativeObject {
/**
* Construct a blocking operator:
*
* <p>
* You can find all possible schemes <a href="https://docs.rs/opendal/latest/opendal/enum.Scheme.html">here</a>
* and see what config options each service supports.
*
* @param schema the name of the underneath service to access data from.
* @param map a map of properties to construct the underneath operator.
*/
public BlockingOperator(String schema, Map<String, String> map) {
super(constructor(schema, map));
}
Expand All @@ -30,12 +44,12 @@ public void write(String fileName, String content) {
write(nativeHandle, fileName, content);
}

public String read(String s) {
return read(nativeHandle, s);
public String read(String fileName) {
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
return read(nativeHandle, fileName);
}

public void delete(String s) {
delete(nativeHandle, s);
public void delete(String fileName) {
delete(nativeHandle, fileName);
}

public Metadata stat(String fileName) {
Expand All @@ -46,8 +60,12 @@ public Metadata stat(String fileName) {
protected native void disposeInternal(long handle);

private static native long constructor(String schema, Map<String, String> map);

private static native void write(long nativeHandle, String fileName, String content);

private static native String read(long nativeHandle, String fileName);

private static native void delete(long nativeHandle, String fileName);

private static native long stat(long nativeHandle, String file);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,4 @@ public static String getClassifier() {
public static String getVersion() {
return INSTANCE.projectVersion;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public long getContentLength() {

@Override
protected native void disposeInternal(long handle);

private static native boolean isFile(long nativeHandle);

private static native long getContentLength(long nativeHandle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ private enum LibraryState {
LOADED
}

private static final AtomicReference<LibraryState> libraryLoaded =
new AtomicReference<>(LibraryState.NOT_LOADED);
private static final AtomicReference<LibraryState> libraryLoaded = new AtomicReference<>(LibraryState.NOT_LOADED);

static {
NativeObject.loadLibrary();
Expand All @@ -43,11 +42,7 @@ public static void loadLibrary() {
}

if (libraryLoaded.compareAndSet(LibraryState.NOT_LOADED, LibraryState.LOADING)) {
JarJniLoader.loadLib(
NativeObject.class,
"/native",
"opendal_java",
Environment.getClassifier());
JarJniLoader.loadLib(NativeObject.class, "/native", "opendal_java", Environment.getClassifier());
libraryLoaded.set(LibraryState.LOADED);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.concurrent.ConcurrentHashMap;

public class Operator extends NativeObject {
private static AsyncRegistry registry() {
private static AsyncRegistry registry() {
return AsyncRegistry.INSTANCE;
}

Expand Down Expand Up @@ -84,7 +84,10 @@ public CompletableFuture<String> read(String fileName) {
protected native void disposeInternal(long handle);

private static native long constructor(String schema, Map<String, String> map);

private static native long read(long nativeHandle, String fileName);

private static native long write(long nativeHandle, String fileName, String content);

private static native long stat(long nativeHandle, String file);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@

package org.apache.opendal;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class AsyncStepsTest {
Operator op;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public void clean() {
@Test
public void testStatNotExistFile() {
assertThatExceptionOfType(OpenDALException.class)
.isThrownBy(() -> op.stat("nonexistence"))
.extracting(OpenDALException::getCode)
.isEqualTo(OpenDALException.Code.NotFound);
.isThrownBy(() -> op.stat("nonexistence"))
.extracting(OpenDALException::getCode)
.isEqualTo(OpenDALException.Code.NotFound);
}

@Test
Expand All @@ -57,8 +57,8 @@ public void testCreateAndDelete() {
assertThat(op.read("testCreateAndDelete")).isEqualTo("Odin");
op.delete("testCreateAndDelete");
assertThatExceptionOfType(OpenDALException.class)
.isThrownBy(() -> op.stat("testCreateAndDelete"))
.extracting(OpenDALException::getCode)
.isEqualTo(OpenDALException.Code.NotFound);
.isThrownBy(() -> op.stat("testCreateAndDelete"))
.extracting(OpenDALException::getCode)
.isEqualTo(OpenDALException.Code.NotFound);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@

package org.apache.opendal;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "org.apache.opendal")
public class CucumberTest {

}
public class CucumberTest {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

package org.apache.opendal;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class StepsTest {
BlockingOperator op;

Expand All @@ -50,7 +49,6 @@ public void the_blocking_file_test_should_exist(String fileName) {
assertNotNull(metadata);
}


@Then("The blocking file {string} entry mode must be file")
public void the_blocking_file_test_entry_mode_must_be_file(String fileName) {
Metadata metadata = op.stat(fileName);
Expand Down