From 3f3178a2371c76017a42fa71e6f9b67b66c1ef54 Mon Sep 17 00:00:00 2001 From: Manyanda Chitimbo Date: Mon, 7 Jun 2021 20:56:51 +0200 Subject: [PATCH] feat(redis): introduce factory methods to create clients dynamically Closes https://github.com/quarkusio/quarkus/issues/13887 --- docs/src/main/asciidoc/redis.adoc | 32 ++++++ .../deployment/RedisClientProcessor.java | 2 +- extensions/redis-client/runtime/pom.xml | 10 ++ .../io/quarkus/redis/client/RedisClient.java | 23 +++++ .../client/reactive/ReactiveRedisClient.java | 24 +++++ .../client/runtime/RedisClientRecorder.java | 4 +- .../redis/client/runtime/RedisClientUtil.java | 11 ++- ...roducer.java => RedisClientsProducer.java} | 33 +++++-- .../client/runtime/RedisClientUtilTest.java | 37 +++++++ ...edisWithDynamicClientCreationResource.java | 50 ++++++++++ .../src/main/resources/application.properties | 1 + .../io/quarkus/redis/it/QuarkusRedisTest.java | 97 +++++++++++-------- .../it/QuarkusRedisWithNamedClientIT.java | 8 -- .../it/QuarkusRedisWithNamedClientTest.java | 62 ------------ .../QuarkusRedisWithParameterInjectionIT.java | 8 -- ...uarkusRedisWithParameterInjectionTest.java | 62 ------------ .../it/QuarkusRedisWithProvidedHostsIT.java | 8 -- .../it/QuarkusRedisWithProvidedHostsTest.java | 62 ------------ 18 files changed, 271 insertions(+), 263 deletions(-) rename extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/{RedisAPIProducer.java => RedisClientsProducer.java} (57%) create mode 100644 extensions/redis-client/runtime/src/test/java/io/quarkus/redis/client/runtime/RedisClientUtilTest.java create mode 100644 integration-tests/redis-client/src/main/java/io/quarkus/redis/it/RedisWithDynamicClientCreationResource.java delete mode 100644 integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithNamedClientIT.java delete mode 100644 integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithNamedClientTest.java delete mode 100644 integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithParameterInjectionIT.java delete mode 100644 integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithParameterInjectionTest.java delete mode 100644 integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithProvidedHostsIT.java delete mode 100644 integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithProvidedHostsTest.java diff --git a/docs/src/main/asciidoc/redis.adoc b/docs/src/main/asciidoc/redis.adoc index a03ee0dc8707e..329bcf1e04bb3 100644 --- a/docs/src/main/asciidoc/redis.adoc +++ b/docs/src/main/asciidoc/redis.adoc @@ -551,6 +551,7 @@ So when you access the `/q/health/ready` endpoint of your application you will h This behavior can be disabled by setting the `quarkus.redis.health.enabled` property to `false` in your `application.properties`. +[[multiple-clients-configuration]] == Multiple Redis Clients The Redis extension allows you to configure multiple clients. @@ -585,6 +586,36 @@ RedisClient redisClient2; ReactiveRedisClient reactiveClient2; ---- +=== Creating Clients Programmatically + +The `RedisClient` and `ReactiveRedisClient` provide factory methods to create clients programmatically. +The client to be created are configured using the usual <>. + +[NOTE] +==== +This is useful to create a client dynamically in a non-CDI bean e.g a link:hibernate-orm-panache.adoc[Panache entity]. +Or to create a different client when running in pub/sub mode. This mode requires two different connections +because once a connection invokes a subscriber mode then it cannot be used for running other commands +than the command to leave that mode. +==== + +The below code snippet shows how we can create dynamic clients using the configurations in <>. +[source,java,indent=0] +---- +// creating default redis client +RedisClient defaultRedisClient = RedisClient.createClient(); + +// creating named redis client whose configuration name is "second" +RedisClient namedRedisClient = RedisClient.createClient("second"); + +// creating a default reactive redis client +ReactiveRedisClient defaultReactiveRedisClient = ReactiveRedisClient.createClient(); + +// creating a named reactive redis client whose configuration name is "second" +ReactiveRedisClient namedReactiveRedisClient = ReactiveRedisClient.createClient("second"); +---- + + [[dev-services]] === DevServices (Configuration Free Redis) @@ -599,6 +630,7 @@ When running the production version of the application, the Redis connection nee so if you want to include a production database config in your `application.properties` and continue to use DevServices we recommend that you use the `%prod.` profile to define your Redis settings. +[[config-reference]] == Configuration Reference include::{generated-dir}/config/quarkus-redis-client.adoc[opts=optional, leveloffset=+1] diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java index c3f97a6e8379b..a0a58881accb2 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java @@ -67,7 +67,7 @@ List registerRedisBeans() { return Arrays.asList( AdditionalBeanBuildItem .builder() - .addBeanClass("io.quarkus.redis.client.runtime.RedisAPIProducer") + .addBeanClass("io.quarkus.redis.client.runtime.RedisClientsProducer") .setDefaultScope(SINGLETON.getName()) .setUnremovable() .build(), diff --git a/extensions/redis-client/runtime/pom.xml b/extensions/redis-client/runtime/pom.xml index 190acd9933dad..ec614da3ce39b 100644 --- a/extensions/redis-client/runtime/pom.xml +++ b/extensions/redis-client/runtime/pom.xml @@ -29,6 +29,16 @@ quarkus-smallrye-health true + + org.assertj + assertj-core + test + + + org.junit.jupiter + junit-jupiter + test + diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisClient.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisClient.java index 87becf24687e0..37fc5e842da67 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisClient.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisClient.java @@ -1,7 +1,11 @@ package io.quarkus.redis.client; +import static io.quarkus.redis.client.runtime.RedisClientUtil.DEFAULT_CLIENT; + import java.util.List; +import io.quarkus.arc.Arc; +import io.quarkus.redis.client.runtime.RedisClientsProducer; import io.vertx.redis.client.Response; /** @@ -13,6 +17,25 @@ * the Redis Commands Page */ public interface RedisClient { + /** + * Creates the {@link RedisClient} using the default redis client configuration + * + * @return {@link RedisClient} - the default redis client + */ + static RedisClient createClient() { + return createClient(DEFAULT_CLIENT); + } + + /** + * Creates the {@link RedisClient} using the named redis client configuration + * + * @return {@link RedisClient} - the named client + */ + static RedisClient createClient(String name) { + RedisClientsProducer redisClientsProducer = Arc.container().instance(RedisClientsProducer.class).get(); + return redisClientsProducer.getRedisClient(name); + } + void close(); Response append(String arg0, String arg1); diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/reactive/ReactiveRedisClient.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/reactive/ReactiveRedisClient.java index c9175d1563e55..aeb7e23ef26c2 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/reactive/ReactiveRedisClient.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/reactive/ReactiveRedisClient.java @@ -1,7 +1,12 @@ package io.quarkus.redis.client.reactive; +import static io.quarkus.redis.client.runtime.RedisClientUtil.DEFAULT_CLIENT; + import java.util.List; +import io.quarkus.arc.Arc; +import io.quarkus.redis.client.RedisClient; +import io.quarkus.redis.client.runtime.RedisClientsProducer; import io.smallrye.mutiny.Uni; import io.vertx.mutiny.redis.client.Response; @@ -12,6 +17,25 @@ * the Redis Commands Page */ public interface ReactiveRedisClient { + /** + * Creates the {@link RedisClient} using the default redis client configuration + * + * @return {@link ReactiveRedisClient} - the default reactive redis client + */ + static ReactiveRedisClient createClient() { + return createClient(DEFAULT_CLIENT); + } + + /** + * Creates the {@link RedisClient} using the named redis client configuration + * + * @return {@link ReactiveRedisClient} - the named reactive redis client + */ + static ReactiveRedisClient createClient(String name) { + RedisClientsProducer redisClientsProducer = Arc.container().instance(RedisClientsProducer.class).get(); + return redisClientsProducer.getReactiveRedisClient(name); + } + void close(); Uni append(String arg0, String arg1); diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientRecorder.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientRecorder.java index 02ebd1f75ffd5..c307ebf70a97e 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientRecorder.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientRecorder.java @@ -73,7 +73,7 @@ public Redis get() { } private RedisAPIContainer getRedisAPIContainer(String clientName) { - RedisAPIProducer redisAPIProducer = Arc.container().instance(RedisAPIProducer.class).get(); - return redisAPIProducer.getRedisAPIContainer(clientName); + RedisClientsProducer redisClientsProducer = Arc.container().instance(RedisClientsProducer.class).get(); + return redisClientsProducer.getRedisAPIContainer(clientName); } } diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientUtil.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientUtil.java index f1030014b42d2..39968909c20fa 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientUtil.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientUtil.java @@ -115,7 +115,16 @@ public static boolean isDefault(String clientName) { } public static RedisConfiguration getConfiguration(RedisConfig config, String name) { - return isDefault(name) ? config.defaultClient : config.additionalRedisClients.get(name); + if (isDefault(name)) { + return config.defaultClient; + } + + RedisConfiguration redisConfiguration = config.additionalRedisClients.get(name); + if (redisConfiguration != null) { + return redisConfiguration; + } + + throw new IllegalArgumentException(String.format("Configuration for %s redis client does not exists", name)); } public static RedisHostsProvider findProvider(String name) { diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisAPIProducer.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientsProducer.java similarity index 57% rename from extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisAPIProducer.java rename to extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientsProducer.java index ca98ec44e54eb..06e8e3b2803ba 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisAPIProducer.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/client/runtime/RedisClientsProducer.java @@ -15,13 +15,14 @@ import io.vertx.redis.client.RedisAPI; import io.vertx.redis.client.RedisOptions; -class RedisAPIProducer { +public class RedisClientsProducer { + private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(10); private static Map REDIS_APIS = new ConcurrentHashMap<>(); private final Vertx vertx; private final RedisConfig redisConfig; - public RedisAPIProducer(RedisConfig redisConfig, Vertx vertx) { + public RedisClientsProducer(RedisConfig redisConfig, Vertx vertx) { this.redisConfig = redisConfig; this.vertx = vertx; } @@ -30,12 +31,9 @@ public RedisAPIContainer getRedisAPIContainer(String name) { return REDIS_APIS.computeIfAbsent(name, new Function() { @Override public RedisAPIContainer apply(String s) { - Duration timeout = Duration.ofSeconds(10); - RedisConfiguration redisConfiguration = RedisClientUtil.getConfiguration(RedisAPIProducer.this.redisConfig, + RedisConfiguration redisConfiguration = RedisClientUtil.getConfiguration(RedisClientsProducer.this.redisConfig, name); - if (redisConfiguration.timeout.isPresent()) { - timeout = redisConfiguration.timeout.get(); - } + Duration timeout = redisConfiguration.timeout.orElse(DEFAULT_TIMEOUT); RedisOptions options = RedisClientUtil.buildOptions(redisConfiguration); Redis redis = Redis.createClient(vertx, options); RedisAPI redisAPI = RedisAPI.api(redis); @@ -48,6 +46,27 @@ public RedisAPIContainer apply(String s) { }); } + public RedisClient getRedisClient(String name) { + RedisConfiguration redisConfiguration = RedisClientUtil.getConfiguration(RedisClientsProducer.this.redisConfig, + name); + Duration timeout = redisConfiguration.timeout.orElse(DEFAULT_TIMEOUT); + RedisOptions options = RedisClientUtil.buildOptions(redisConfiguration); + Redis redis = Redis.createClient(vertx, options); + RedisAPI redisAPI = RedisAPI.api(redis); + MutinyRedisAPI mutinyRedisAPI = new MutinyRedisAPI(redisAPI); + return new RedisClientImpl(mutinyRedisAPI, timeout); + } + + public ReactiveRedisClient getReactiveRedisClient(String name) { + RedisConfiguration redisConfiguration = RedisClientUtil.getConfiguration(RedisClientsProducer.this.redisConfig, + name); + RedisOptions options = RedisClientUtil.buildOptions(redisConfiguration); + Redis redis = Redis.createClient(vertx, options); + RedisAPI redisAPI = RedisAPI.api(redis); + MutinyRedisAPI mutinyRedisAPI = new MutinyRedisAPI(redisAPI); + return new ReactiveRedisClientImpl(mutinyRedisAPI); + } + @PreDestroy public void close() { for (RedisAPIContainer container : REDIS_APIS.values()) { diff --git a/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/client/runtime/RedisClientUtilTest.java b/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/client/runtime/RedisClientUtilTest.java new file mode 100644 index 0000000000000..52ac57dd70edd --- /dev/null +++ b/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/client/runtime/RedisClientUtilTest.java @@ -0,0 +1,37 @@ +package io.quarkus.redis.client.runtime; + +import static io.quarkus.redis.client.runtime.RedisClientUtil.DEFAULT_CLIENT; +import static io.quarkus.redis.client.runtime.RedisClientUtil.getConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.HashMap; + +import org.junit.jupiter.api.Test; + +import io.quarkus.redis.client.runtime.RedisConfig.RedisConfiguration; + +class RedisClientUtilTest { + + @Test + void testGetConfiguration() { + RedisConfig config = new RedisConfig(); + config.defaultClient = new RedisConfiguration(); + config.additionalRedisClients = new HashMap<>(); + RedisConfiguration namedConfiguration = new RedisConfiguration(); + config.additionalRedisClients.put("some-configuration", namedConfiguration); + + // get default client configuration + RedisConfiguration configuration = getConfiguration(config, DEFAULT_CLIENT); + assertThat(configuration).isEqualTo(config.defaultClient); + + // get named client configuration + configuration = getConfiguration(config, "some-configuration"); + assertThat(configuration).isEqualTo(namedConfiguration); + + // throw error for non-existing named client + assertThatThrownBy(() -> { + getConfiguration(config, "non-existing"); + }).isInstanceOf(IllegalArgumentException.class); + } +} diff --git a/integration-tests/redis-client/src/main/java/io/quarkus/redis/it/RedisWithDynamicClientCreationResource.java b/integration-tests/redis-client/src/main/java/io/quarkus/redis/it/RedisWithDynamicClientCreationResource.java new file mode 100644 index 0000000000000..d6b7b9e335faa --- /dev/null +++ b/integration-tests/redis-client/src/main/java/io/quarkus/redis/it/RedisWithDynamicClientCreationResource.java @@ -0,0 +1,50 @@ +package io.quarkus.redis.it; + +import java.util.Arrays; + +import javax.enterprise.context.ApplicationScoped; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import io.quarkus.redis.client.RedisClient; +import io.quarkus.redis.client.reactive.ReactiveRedisClient; +import io.smallrye.mutiny.Uni; +import io.vertx.redis.client.Response; + +@Path("/quarkus-redis-dynamic-client-creation") +@ApplicationScoped +public class RedisWithDynamicClientCreationResource { + // synchronous + @GET + @Path("/sync/{key}") + public String getSync(@PathParam("key") String key) { + Response response = RedisClient.createClient("dynamic").get(key); + return response == null ? null : response.toString(); + } + + @POST + @Path("/sync/{key}") + public void setSync(@PathParam("key") String key, String value) { + RedisClient.createClient("dynamic").set(Arrays.asList(key, value)); + } + + // reactive + @GET + @Path("/reactive/{key}") + public Uni getReactive(@PathParam("key") String key) { + return ReactiveRedisClient.createClient("dynamic") + .get(key) + .map(response -> response == null ? null : response.toString()); + } + + @POST + @Path("/reactive/{key}") + public Uni setReactive(@PathParam("key") String key, String value) { + return ReactiveRedisClient.createClient("dynamic") + .set(Arrays.asList(key, value)) + .map(response -> null); + } + +} diff --git a/integration-tests/redis-client/src/main/resources/application.properties b/integration-tests/redis-client/src/main/resources/application.properties index e186d71d09325..2842b2a380a32 100644 --- a/integration-tests/redis-client/src/main/resources/application.properties +++ b/integration-tests/redis-client/src/main/resources/application.properties @@ -3,3 +3,4 @@ quarkus.redis.named-client.hosts=redis://localhost:6379/1 quarkus.redis.parameter-injection.hosts=redis://localhost:6379/2 quarkus.redis.named-reactive-client.hosts=redis://localhost:6379/1 quarkus.redis.provided-hosts.hosts-provider-name=test-hosts-provider +quarkus.redis.dynamic.hosts=redis://localhost:6379/4 diff --git a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisTest.java b/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisTest.java index 700f8d7888ce6..6fd402ec6d76e 100644 --- a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisTest.java +++ b/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisTest.java @@ -8,54 +8,67 @@ @QuarkusTest class QuarkusRedisTest { - static final String SYNC_KEY = "sync-key"; - static final String SYNC_VALUE = "sync-value"; - static final String REACTIVE_KEY = "reactive-key"; - static final String REACTIVE_VALUE = "reactive-value"; + static final String SYNC_KEY = "named-sync-key"; + static final String SYNC_VALUE = "named-sync-value"; + + static final String REACTIVE_KEY = "named-reactive-key"; + static final String REACTIVE_VALUE = "named-reactive-value"; + + static final String[] BASE_URLS = { "/quarkus-redis", + "/quarkus-redis-with-named", + "/quarkus-redis-dynamic-client-creation", + "/quarkus-redis-provided-hosts", + "/quarkus-redis-parameter-injection" }; @Test public void sync() { - RestAssured.given() - .when() - .get("/quarkus-redis/sync/" + SYNC_KEY) - .then() - .statusCode(204); // the key is not set yet - - RestAssured.given() - .body(SYNC_VALUE) - .when() - .post("/quarkus-redis/sync/" + SYNC_KEY) - .then() - .statusCode(204); - - RestAssured.given() - .when() - .get("/quarkus-redis/sync/" + SYNC_KEY) - .then() - .statusCode(200) - .body(CoreMatchers.is(SYNC_VALUE)); + for (String baseUrl : BASE_URLS) { + String path = String.format("%s/sync/%s", baseUrl, SYNC_KEY); + RestAssured.given() + .when() + .get(path) + .then() + .statusCode(204); // the key is not set yet + + RestAssured.given() + .body(SYNC_VALUE) + .when() + .post(path) + .then() + .statusCode(204); + + RestAssured.given() + .when() + .get(path) + .then() + .statusCode(200) + .body(CoreMatchers.is(SYNC_VALUE)); + } } @Test public void reactive() { - RestAssured.given() - .when() - .get("/quarkus-redis/reactive/" + REACTIVE_KEY) - .then() - .statusCode(204); // the reactive key is not set yet - - RestAssured.given() - .body(REACTIVE_VALUE) - .when() - .post("/quarkus-redis/reactive/" + REACTIVE_KEY) - .then() - .statusCode(204); - - RestAssured.given() - .when() - .get("/quarkus-redis/reactive/" + REACTIVE_KEY) - .then() - .statusCode(200) - .body(CoreMatchers.is(REACTIVE_VALUE)); + for (String baseUrl : BASE_URLS) { + String path = String.format("%s/reactive/%s", baseUrl, REACTIVE_KEY); + RestAssured.given() + .when() + .get(path) + .then() + .statusCode(204); // the reactive key is not set yet + + RestAssured.given() + .body(REACTIVE_VALUE) + .when() + .post(path) + .then() + .statusCode(204); + + RestAssured.given() + .when() + .get(path) + .then() + .statusCode(200) + .body(CoreMatchers.is(REACTIVE_VALUE)); + } } } diff --git a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithNamedClientIT.java b/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithNamedClientIT.java deleted file mode 100644 index 92c551b40c99e..0000000000000 --- a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithNamedClientIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.quarkus.redis.it; - -import io.quarkus.test.junit.NativeImageTest; - -@NativeImageTest -class QuarkusRedisWithNamedClientIT extends QuarkusRedisWithNamedClientTest { - -} diff --git a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithNamedClientTest.java b/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithNamedClientTest.java deleted file mode 100644 index bdde0097d9bcb..0000000000000 --- a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithNamedClientTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.quarkus.redis.it; - -import org.hamcrest.CoreMatchers; -import org.junit.jupiter.api.Test; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; - -@QuarkusTest -class QuarkusRedisWithNamedClientTest { - static final String SYNC_KEY = "named-sync-key"; - static final String SYNC_VALUE = "named-sync-value"; - - static final String REACTIVE_KEY = "named-reactive-key"; - static final String REACTIVE_VALUE = "named-reactive-value"; - - @Test - public void sync() { - RestAssured.given() - .when() - .get("/quarkus-redis-with-named/sync/" + SYNC_KEY) - .then() - .statusCode(204); // the key is not set yet - - RestAssured.given() - .body(SYNC_VALUE) - .when() - .post("/quarkus-redis-with-named/sync/" + SYNC_KEY) - .then() - .statusCode(204); - - RestAssured.given() - .when() - .get("/quarkus-redis-with-named/sync/" + SYNC_KEY) - .then() - .statusCode(200) - .body(CoreMatchers.is(SYNC_VALUE)); - } - - @Test - public void reactive() { - RestAssured.given() - .when() - .get("/quarkus-redis-with-named/reactive/" + REACTIVE_KEY) - .then() - .statusCode(204); // the reactive key is not set yet - - RestAssured.given() - .body(REACTIVE_VALUE) - .when() - .post("/quarkus-redis-with-named/reactive/" + REACTIVE_KEY) - .then() - .statusCode(204); - - RestAssured.given() - .when() - .get("/quarkus-redis-with-named/reactive/" + REACTIVE_KEY) - .then() - .statusCode(200) - .body(CoreMatchers.is(REACTIVE_VALUE)); - } -} diff --git a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithParameterInjectionIT.java b/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithParameterInjectionIT.java deleted file mode 100644 index 02f89847cb8d2..0000000000000 --- a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithParameterInjectionIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.quarkus.redis.it; - -import io.quarkus.test.junit.NativeImageTest; - -@NativeImageTest -class QuarkusRedisWithParameterInjectionIT extends QuarkusRedisWithParameterInjectionTest { - -} diff --git a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithParameterInjectionTest.java b/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithParameterInjectionTest.java deleted file mode 100644 index 074447ea01b0d..0000000000000 --- a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithParameterInjectionTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.quarkus.redis.it; - -import org.hamcrest.CoreMatchers; -import org.junit.jupiter.api.Test; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; - -@QuarkusTest -class QuarkusRedisWithParameterInjectionTest { - static final String SYNC_KEY = "named-sync-key"; - static final String SYNC_VALUE = "named-sync-value"; - - static final String REACTIVE_KEY = "named-reactive-key"; - static final String REACTIVE_VALUE = "named-reactive-value"; - - @Test - public void sync() { - RestAssured.given() - .when() - .get("/quarkus-redis-parameter-injection/sync/" + SYNC_KEY) - .then() - .statusCode(204); // the key is not set yet - - RestAssured.given() - .body(SYNC_VALUE) - .when() - .post("/quarkus-redis-parameter-injection/sync/" + SYNC_KEY) - .then() - .statusCode(204); - - RestAssured.given() - .when() - .get("/quarkus-redis-parameter-injection/sync/" + SYNC_KEY) - .then() - .statusCode(200) - .body(CoreMatchers.is(SYNC_VALUE)); - } - - @Test - public void reactive() { - RestAssured.given() - .when() - .get("/quarkus-redis-parameter-injection/reactive/" + REACTIVE_KEY) - .then() - .statusCode(204); // the reactive key is not set yet - - RestAssured.given() - .body(REACTIVE_VALUE) - .when() - .post("/quarkus-redis-parameter-injection/reactive/" + REACTIVE_KEY) - .then() - .statusCode(204); - - RestAssured.given() - .when() - .get("/quarkus-redis-parameter-injection/reactive/" + REACTIVE_KEY) - .then() - .statusCode(200) - .body(CoreMatchers.is(REACTIVE_VALUE)); - } -} diff --git a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithProvidedHostsIT.java b/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithProvidedHostsIT.java deleted file mode 100644 index 1ba176de1d927..0000000000000 --- a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithProvidedHostsIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.quarkus.redis.it; - -import io.quarkus.test.junit.NativeImageTest; - -@NativeImageTest -class QuarkusRedisWithProvidedHostsIT extends QuarkusRedisWithProvidedHostsTest { - -} diff --git a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithProvidedHostsTest.java b/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithProvidedHostsTest.java deleted file mode 100644 index b9f252d4bb9b6..0000000000000 --- a/integration-tests/redis-client/src/test/java/io/quarkus/redis/it/QuarkusRedisWithProvidedHostsTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.quarkus.redis.it; - -import org.hamcrest.CoreMatchers; -import org.junit.jupiter.api.Test; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; - -@QuarkusTest -class QuarkusRedisWithProvidedHostsTest { - static final String SYNC_KEY = "named-sync-key"; - static final String SYNC_VALUE = "named-sync-value"; - - static final String REACTIVE_KEY = "named-reactive-key"; - static final String REACTIVE_VALUE = "named-reactive-value"; - - @Test - public void sync() { - RestAssured.given() - .when() - .get("/quarkus-redis-provided-hosts/sync/" + SYNC_KEY) - .then() - .statusCode(204); // the key is not set yet - - RestAssured.given() - .body(SYNC_VALUE) - .when() - .post("/quarkus-redis-provided-hosts/sync/" + SYNC_KEY) - .then() - .statusCode(204); - - RestAssured.given() - .when() - .get("/quarkus-redis-provided-hosts/sync/" + SYNC_KEY) - .then() - .statusCode(200) - .body(CoreMatchers.is(SYNC_VALUE)); - } - - @Test - public void reactive() { - RestAssured.given() - .when() - .get("/quarkus-redis-provided-hosts/reactive/" + REACTIVE_KEY) - .then() - .statusCode(204); // the reactive key is not set yet - - RestAssured.given() - .body(REACTIVE_VALUE) - .when() - .post("/quarkus-redis-provided-hosts/reactive/" + REACTIVE_KEY) - .then() - .statusCode(204); - - RestAssured.given() - .when() - .get("/quarkus-redis-provided-hosts/reactive/" + REACTIVE_KEY) - .then() - .statusCode(200) - .body(CoreMatchers.is(REACTIVE_VALUE)); - } -}