Skip to content

Commit 961a4b5

Browse files
authored
feat(java): replace callbacks by CompletableFuture APIC-421 (#452)
1 parent d22e05f commit 961a4b5

File tree

58 files changed

+2002
-7235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2002
-7235
lines changed

.github/workflows/check.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ jobs:
220220
run: yarn cli build clients ${{ matrix.client.language }} ${{ matrix.client.toRun }}
221221

222222
- name: Clean CTS output before generate
223-
run: rm -rf ${{ matrix.client.testsOutputPath }}
223+
run: rm -rf ${{ matrix.client.testsOutputPathToClean }} || true
224224

225225
- name: Generate CTS
226226
run: yarn cli cts generate ${{ matrix.client.language }} ${{ matrix.client.toRun }}
227227

228228
- name: Check diff with pushed CTS
229229
run: |
230-
git --no-pager diff
231-
exit $(git diff --name-only --diff-filter=d ${{ matrix.client.testsOutputPath }} | wc -l)
230+
git --no-pager diff -- ${{ matrix.client.testsOutputPathToClean }}
231+
exit $(git diff --name-only --diff-filter=d ${{ matrix.client.testsOutputPathToClean }} | wc -l)
232232
233233
- name: Run CTS
234234
run: yarn cli cts run ${{ matrix.client.language }}

clients/algoliasearch-client-java-2/.openapi-generator-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
api/**
88
docs/**
99
src/**
10+
gradle/**
1011
README.md
1112

1213
.travis.yml

clients/algoliasearch-client-java-2/algoliasearch-core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ dependencies {
2121

2222
tasks.withType(JavaCompile) {
2323
options.encoding = 'UTF-8'
24+
options.compilerArgs += ['-Xlint:deprecation']
2425
}

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiCallback.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiResponse.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ProgressRequestBody.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ProgressResponseBody.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaApiException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/** Exception thrown in case of API failure such as 4XX, 5XX error. */
44
public class AlgoliaApiException extends AlgoliaRuntimeException {
55

6+
public static final long serialVersionUID = -1L;
7+
68
public int getHttpErrorCode() {
79
return httpErrorCode;
810
}

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRetryException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
public class AlgoliaRetryException extends AlgoliaRuntimeException {
88

9+
public static final long serialVersionUID = -1L;
10+
911
public AlgoliaRetryException(String message, Throwable cause) {
1012
super(message, cause);
1113
}

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRuntimeException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/** Exception thrown when an error occurs during the Serialization/Deserialization process */
44
public class AlgoliaRuntimeException extends RuntimeException {
55

6+
public static final long serialVersionUID = -1L;
7+
68
public AlgoliaRuntimeException(String message, Throwable cause) {
79
super(message, cause);
810
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.algolia.exceptions;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
import java.util.concurrent.ExecutionException;
5+
6+
@SuppressWarnings("WeakerAccess")
7+
public class LaunderThrowable {
8+
9+
/**
10+
* Performs a get() on the asynchronous method. Launders both Interrupted and Execution exception
11+
* to business exception
12+
*
13+
* @param f The CompletableFuture to block on.
14+
*/
15+
public static <T> T await(CompletableFuture<T> f) {
16+
try {
17+
return f.get();
18+
} catch (InterruptedException | ExecutionException e) {
19+
throw LaunderThrowable.launder(e);
20+
}
21+
}
22+
23+
/** Launders both Interrupted and Execution exception into business exception */
24+
public static RuntimeException launder(Throwable t) {
25+
if (t.getCause() instanceof AlgoliaApiException) {
26+
throw (AlgoliaApiException) t.getCause();
27+
}
28+
29+
if (t.getCause() instanceof AlgoliaRetryException) {
30+
throw (AlgoliaRetryException) t.getCause();
31+
}
32+
33+
if (t.getCause() instanceof AlgoliaRuntimeException) {
34+
throw (AlgoliaRuntimeException) t.getCause();
35+
}
36+
37+
throw new AlgoliaRuntimeException(t);
38+
}
39+
}

0 commit comments

Comments
 (0)