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

feat(java): replace callbacks by CompletableFuture APIC-421 #452

Merged
merged 17 commits into from
May 10, 2022
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ jobs:
run: yarn cli build clients ${{ matrix.client.language }} ${{ matrix.client.toRun }}

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

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

- name: Check diff with pushed CTS
run: |
git --no-pager diff
exit $(git diff --name-only --diff-filter=d ${{ matrix.client.testsOutputPath }} | wc -l)
git --no-pager diff -- ${{ matrix.client.testsOutputPathToClean }}
exit $(git diff --name-only --diff-filter=d ${{ matrix.client.testsOutputPathToClean }} | wc -l)

- name: Run CTS
run: yarn cli cts run ${{ matrix.client.language }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
api/**
docs/**
src/**
gradle/**
README.md

.travis.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ dependencies {

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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/** Exception thrown in case of API failure such as 4XX, 5XX error. */
public class AlgoliaApiException extends AlgoliaRuntimeException {

public static final long serialVersionUID = -1L;

public int getHttpErrorCode() {
return httpErrorCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
public class AlgoliaRetryException extends AlgoliaRuntimeException {

public static final long serialVersionUID = -1L;

public AlgoliaRetryException(String message, Throwable cause) {
super(message, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/** Exception thrown when an error occurs during the Serialization/Deserialization process */
public class AlgoliaRuntimeException extends RuntimeException {

public static final long serialVersionUID = -1L;

public AlgoliaRuntimeException(String message, Throwable cause) {
super(message, cause);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.algolia.exceptions;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@SuppressWarnings("WeakerAccess")
public class LaunderThrowable {

/**
* Performs a get() on the asynchronous method. Launders both Interrupted and Execution exception
* to business exception
*
* @param f The CompletableFuture to block on.
*/
public static <T> T await(CompletableFuture<T> f) {
try {
return f.get();
} catch (InterruptedException | ExecutionException e) {
throw LaunderThrowable.launder(e);
}
}

/** Launders both Interrupted and Execution exception into business exception */
public static RuntimeException launder(Throwable t) {
if (t.getCause() instanceof AlgoliaApiException) {
throw (AlgoliaApiException) t.getCause();
}

if (t.getCause() instanceof AlgoliaRetryException) {
throw (AlgoliaRetryException) t.getCause();
}

if (t.getCause() instanceof AlgoliaRuntimeException) {
throw (AlgoliaRuntimeException) t.getCause();
}

throw new AlgoliaRuntimeException(t);
}
}
Loading