forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into federation-batch-tests
- Loading branch information
Showing
19 changed files
with
347 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ache/deployment-spi/src/main/java/io/quarkus/cache/deployment/spi/CacheTypeBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.cache.deployment.spi; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* A build item that can be used by extensions to determine what kind of cache backend is configured. | ||
* This is useful for cases where caching extensions specific data does not make sense for remote cache backends | ||
*/ | ||
public final class CacheTypeBuildItem extends SimpleBuildItem { | ||
|
||
private final Type type; | ||
|
||
public CacheTypeBuildItem(Type type) { | ||
this.type = type; | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
public enum Type { | ||
LOCAL, | ||
REMOTE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 25 additions & 6 deletions
31
extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/CacheProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ns/qute/runtime/src/main/java/io/quarkus/qute/runtime/cache/MissingCacheConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.qute.runtime.cache; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.Function; | ||
|
||
import jakarta.enterprise.event.Observes; | ||
|
||
import io.quarkus.qute.CacheSectionHelper; | ||
import io.quarkus.qute.EngineBuilder; | ||
import io.quarkus.qute.ResultNode; | ||
|
||
public class MissingCacheConfigurator { | ||
|
||
void configureEngine(@Observes EngineBuilder builder) { | ||
builder.addSectionHelper(new CacheSectionHelper.Factory(new CacheSectionHelper.Cache() { | ||
|
||
@Override | ||
public CompletionStage<ResultNode> getValue(String key, Function<String, CompletionStage<ResultNode>> loader) { | ||
throw new IllegalStateException("#cache cannot be used without the 'quarkus-cache' extension"); | ||
} | ||
})); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...ntime/src/main/java/io/quarkus/qute/runtime/cache/UnsupportedRemoteCacheConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.qute.runtime.cache; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.Function; | ||
|
||
import jakarta.enterprise.event.Observes; | ||
|
||
import io.quarkus.qute.CacheSectionHelper; | ||
import io.quarkus.qute.EngineBuilder; | ||
import io.quarkus.qute.ResultNode; | ||
|
||
public class UnsupportedRemoteCacheConfigurator { | ||
|
||
void configureEngine(@Observes EngineBuilder builder) { | ||
builder.addSectionHelper(new CacheSectionHelper.Factory(new CacheSectionHelper.Cache() { | ||
|
||
@Override | ||
public CompletionStage<ResultNode> getValue(String key, Function<String, CompletionStage<ResultNode>> loader) { | ||
throw new IllegalStateException("#cache is not supported for remote caches"); | ||
} | ||
})); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...phql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/CompressionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.quarkus.smallrye.graphql.deployment; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.microprofile.graphql.GraphQLApi; | ||
import org.eclipse.microprofile.graphql.Query; | ||
import org.hamcrest.CoreMatchers; | ||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class CompressionTest extends AbstractGraphQLTest { | ||
|
||
private static final String PI = "3.141592653589793238462643383279502884197169399375105820"; | ||
private static final String TAU = "6.28"; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")) | ||
.overrideConfigKey("quarkus.http.enable-compression", "true"); | ||
|
||
@Test | ||
public void singleValidQueryCompressedResponseTest() { | ||
String body = getPayload("{ validPiQuery }"); | ||
assertCompressed(body, PI); | ||
} | ||
|
||
@Test | ||
public void multipleValidQueriesCompressedResponseTest() { | ||
String body = getPayload("{ validPiQuery validTauQuery }"); | ||
assertCompressed(body, PI, TAU); | ||
} | ||
|
||
@Test | ||
public void singleInvalidQueryCompressedResponseTest() { | ||
String body = getPayload("{ invalidQuery }"); | ||
assertCompressed(body, "errors"); | ||
} | ||
|
||
private void assertCompressed(String body, String... expectedOutput) { | ||
org.hamcrest.Matcher messageMatcher = Arrays.stream(expectedOutput) | ||
.map(CoreMatchers::containsString) | ||
.reduce(Matchers.allOf(), (a, b) -> Matchers.allOf(a, b)); | ||
|
||
RestAssured.given() | ||
.body(body) | ||
.contentType(MEDIATYPE_JSON) | ||
.post("/graphql") | ||
.prettyPeek() | ||
.then() | ||
.assertThat() | ||
.statusCode(200) | ||
.header("Content-Encoding", "gzip") | ||
.body(messageMatcher); | ||
} | ||
|
||
@GraphQLApi | ||
public static class Schema { | ||
@Query | ||
public String validPiQuery() { | ||
return PI; | ||
} | ||
|
||
@Query | ||
public String validTauQuery() { | ||
return TAU; | ||
} | ||
|
||
@Query | ||
public String invalidQuery() { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
.../src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLCompressionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.smallrye.graphql.runtime; | ||
|
||
import io.vertx.core.Handler; | ||
import io.vertx.core.http.HttpHeaders; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class SmallRyeGraphQLCompressionHandler implements Handler<RoutingContext> { | ||
|
||
private final Handler<RoutingContext> routeHandler; | ||
|
||
public SmallRyeGraphQLCompressionHandler(Handler<RoutingContext> routeHandler) { | ||
this.routeHandler = routeHandler; | ||
} | ||
|
||
@Override | ||
public void handle(RoutingContext context) { | ||
context.addHeadersEndHandler(new Handler<Void>() { | ||
@Override | ||
public void handle(Void event) { | ||
context.response().headers().remove(HttpHeaders.CONTENT_ENCODING); | ||
} | ||
}); | ||
routeHandler.handle(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.