Skip to content

Bugfix/469 apply async timeout #342

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

Merged
merged 6 commits into from
May 13, 2021
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
33 changes: 3 additions & 30 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,6 @@ jobs:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1

verify-google-java-format:
name: Google Java Format Verification
runs-on: ubuntu-latest
needs: validation
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 15
- name: Cache Gradle
uses: actions/cache@v2
env:
java-version: 15
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-${{ env.java-version }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: ${{ runner.os }}-${{ env.java-version }}-gradle-
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Gradle Check
run: ./gradlew --info build -x test

test:
name: Test run
strategy:
Expand Down Expand Up @@ -70,11 +43,11 @@ jobs:
run: chmod +x ./gradlew
- name: Gradle Check (non-Windows)
if: matrix.os != 'windows-latest'
run: ./gradlew --info check -x verifyGoogleJavaFormat
run: ./gradlew --info check
- name: Gradle Check (Windows)
if: matrix.os == 'windows-latest'
shell: cmd
run: gradlew --info check -x verifyGoogleJavaFormat
run: gradlew --info check

build:
name: Sonar analysis
Expand Down Expand Up @@ -112,4 +85,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build jacocoTestReport sonarqube --info -x verifyGoogleJavaFormat
run: ./gradlew build jacocoTestReport sonarqube --info
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Gradle Check
run: ./gradlew --info check -x verifyGoogleJavaFormat
run: ./gradlew --info check

build:
name: Publish release
Expand Down
33 changes: 3 additions & 30 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,6 @@ jobs:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1

verify-google-java-format:
name: Google Java Format Verification
runs-on: ubuntu-latest
needs: validation
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 15
- name: Cache Gradle
uses: actions/cache@v2
env:
java-version: 15
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-${{ env.java-version }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: ${{ runner.os }}-${{ env.java-version }}-gradle-
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Gradle Check
run: ./gradlew --info build -x test

test:
name: Test run
needs: validation
Expand All @@ -65,7 +38,7 @@ jobs:
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Gradle Check
run: ./gradlew --info check -x verifyGoogleJavaFormat
run: ./gradlew --info check

build:
name: Publish snapshot
Expand Down Expand Up @@ -97,7 +70,7 @@ jobs:
env:
OSS_USER_TOKEN_KEY: ${{ secrets.OSS_USER_TOKEN_KEY }}
OSS_USER_TOKEN_PASS: ${{ secrets.OSS_USER_TOKEN_PASS }}
run: ./gradlew clean build publish -x test -x verifyGoogleJavaFormat
run: ./gradlew clean build publish -x test

sonar:
name: Sonar analysis
Expand Down Expand Up @@ -129,4 +102,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != null
run: ./gradlew build jacocoTestReport sonarqube --info -x verifyGoogleJavaFormat
run: ./gradlew build jacocoTestReport sonarqube --info
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ plugins {
id "org.sonarqube" version "3.2.0"
id "jacoco"
id 'io.codearte.nexus-staging' version '0.30.0'
id 'com.github.sherter.google-java-format' version '0.9' apply false
}

sonarqube {
Expand All @@ -49,7 +48,6 @@ subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'com.github.sherter.google-java-format'

repositories {
mavenLocal()
Expand Down Expand Up @@ -80,8 +78,6 @@ subprojects {

compileJava.dependsOn(processResources)

compileJava.mustRunAfter verifyGoogleJavaFormat

test {
useJUnitPlatform()

Expand Down
2 changes: 1 addition & 1 deletion github-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ git config --global user.name "GitHub Actions"
echo "Deploying release to Maven Central"
removeSnapshots

./gradlew clean build publish closeAndReleaseRepository -x verifyGoogleJavaFormat
./gradlew clean build publish closeAndReleaseRepository

commitRelease
bumpVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package graphql.kickstart.execution;

import graphql.ExecutionResult;
import graphql.kickstart.execution.input.GraphQLInvocationInput;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
class FutureBatchedExecutionResult implements FutureExecutionResult {

@Getter
private final GraphQLInvocationInput invocationInput;
private final CompletableFuture<List<ExecutionResult>> batched;

@Override
public CompletableFuture<GraphQLQueryResult> thenApplyQueryResult() {
return batched.thenApply(GraphQLQueryResult::create);
}

@Override
public void cancel() {
batched.cancel(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package graphql.kickstart.execution;

import graphql.kickstart.execution.input.GraphQLInvocationInput;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
class FutureErrorExecutionResult implements FutureExecutionResult {

private final GraphQLErrorQueryResult errorQueryResult;

@Override
public CompletableFuture<GraphQLQueryResult> thenApplyQueryResult() {
return CompletableFuture.completedFuture(errorQueryResult);
}

@Override
public GraphQLInvocationInput getInvocationInput() {
return null;
}

@Override
public void cancel() {
// nothing to do
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package graphql.kickstart.execution;

import graphql.ExecutionResult;
import graphql.kickstart.execution.input.GraphQLInvocationInput;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public interface FutureExecutionResult {

static FutureExecutionResult single(
GraphQLInvocationInput invocationInput, CompletableFuture<ExecutionResult> single) {
return new FutureSingleExecutionResult(invocationInput, single);
}

static FutureExecutionResult batched(
GraphQLInvocationInput invocationInput, CompletableFuture<List<ExecutionResult>> batched) {
return new FutureBatchedExecutionResult(invocationInput, batched);
}

static FutureExecutionResult error(GraphQLErrorQueryResult result) {
return new FutureErrorExecutionResult(result);
}

CompletableFuture<GraphQLQueryResult> thenApplyQueryResult();

GraphQLInvocationInput getInvocationInput();

void cancel();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package graphql.kickstart.execution;

import graphql.ExecutionResult;
import graphql.kickstart.execution.input.GraphQLInvocationInput;
import java.util.concurrent.CompletableFuture;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
class FutureSingleExecutionResult implements FutureExecutionResult {

@Getter
private final GraphQLInvocationInput invocationInput;
private final CompletableFuture<ExecutionResult> single;

@Override
public CompletableFuture<GraphQLQueryResult> thenApplyQueryResult() {
return single.thenApply(GraphQLQueryResult::create);
}

@Override
public void cancel() {
single.cancel(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
public class GraphQLInvoker {

private final GraphQLBuilder graphQLBuilder;
private final BatchedDataLoaderGraphQLBuilder batchedDataLoaderGraphQLBuilder;
private final GraphQLInvokerProxy proxy = GraphQL::executeAsync;

public FutureExecutionResult execute(GraphQLInvocationInput invocationInput) {
if (invocationInput instanceof GraphQLSingleInvocationInput) {
return FutureExecutionResult.single(
invocationInput, executeAsync((GraphQLSingleInvocationInput) invocationInput));
}
return FutureExecutionResult.batched(
invocationInput, executeAsync((GraphQLBatchedInvocationInput) invocationInput));
}

public CompletableFuture<ExecutionResult> executeAsync(
GraphQLSingleInvocationInput invocationInput) {
GraphQL graphQL = graphQLBuilder.build(invocationInput.getSchema());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package graphql.kickstart.servlet;

import java.io.IOException;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;

interface AsyncTimeoutListener extends AsyncListener {

default void onComplete(AsyncEvent event) throws IOException {}

default void onError(AsyncEvent event) throws IOException {}

default void onStartAsync(AsyncEvent event) throws IOException {}
}
Loading