diff --git a/README.md b/README.md index cea393f922..203547fe2f 100644 --- a/README.md +++ b/README.md @@ -1066,6 +1066,10 @@ a collection using a filter and a projection. All tests are performed using: Reactive equivalent of `nosql-db/mongodb`. Uses reactive ReactiveMongoClient (without codecs) +### `nosql-db/infinispan` + +Provides some coverage similar to `infinispan-client` module, but with focus on connecting to local cluster and Dev mode and not on working with OpenShift + ### `websockets/quarkus-websockets` Coverage for sending messages over websockets @@ -1107,4 +1111,4 @@ Test coverage includes: - normal HTTP requests - Cloud Event Binary mode - Structured Mode -- Multiple functions declared in one application \ No newline at end of file +- Multiple functions declared in one application diff --git a/nosql-db/infinispan/pom.xml b/nosql-db/infinispan/pom.xml new file mode 100644 index 0000000000..8ee8569c23 --- /dev/null +++ b/nosql-db/infinispan/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + io.quarkus.ts.qe + parent + 1.0.0-SNAPSHOT + ../.. + + infinispan + jar + Quarkus QE TS: Infinispan + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-infinispan-client + + + io.quarkus.qe + quarkus-test-service-infinispan + test + + + + + + skip-tests-on-windows + + + windows + + + + + + maven-surefire-plugin + + true + + + + maven-failsafe-plugin + + true + + + + + + + + + native + + + native + + + + + fast-jar + + + + diff --git a/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/FirstCounterResource.java b/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/FirstCounterResource.java new file mode 100644 index 0000000000..74319a9c54 --- /dev/null +++ b/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/FirstCounterResource.java @@ -0,0 +1,7 @@ +package io.quarkus.ts.infinispan.client; + +import javax.ws.rs.Path; + +@Path("/first-counter") +public class FirstCounterResource extends InfinispanCounterResource { +} diff --git a/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/InfinispanClientApp.java b/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/InfinispanClientApp.java new file mode 100644 index 0000000000..40d467356a --- /dev/null +++ b/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/InfinispanClientApp.java @@ -0,0 +1,63 @@ +package io.quarkus.ts.infinispan.client; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import org.infinispan.client.hotrod.RemoteCache; +import org.infinispan.client.hotrod.RemoteCacheManager; +import org.infinispan.client.hotrod.annotation.ClientCacheEntryCreated; +import org.infinispan.client.hotrod.annotation.ClientCacheEntryModified; +import org.infinispan.client.hotrod.annotation.ClientCacheEntryRemoved; +import org.infinispan.client.hotrod.annotation.ClientListener; +import org.infinispan.client.hotrod.event.ClientCacheEntryCreatedEvent; +import org.infinispan.client.hotrod.event.ClientCacheEntryModifiedEvent; +import org.infinispan.client.hotrod.event.ClientCacheEntryRemovedEvent; +import org.infinispan.commons.configuration.XMLStringConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.quarkus.runtime.StartupEvent; + +@ApplicationScoped +public class InfinispanClientApp { + + private static final Logger LOGGER = LoggerFactory.getLogger("InfinispanClientApp"); + + @Inject + RemoteCacheManager cacheManager; + + private static final String MYCACHE_CACHE_CONFIG = "" + + "" + + ""; + + void onStart(@Observes StartupEvent ev) { + LOGGER.info("Create or get cache named mycache with the default configuration"); + RemoteCache cache = cacheManager.administration().getOrCreateCache("mycache", + new XMLStringConfiguration(String.format(MYCACHE_CACHE_CONFIG, "mycache"))); + cache.addClientListener(new EventPrintListener()); + if (cache.isEmpty()) { + cache.put("counter", 0); + } + } + + @ClientListener + static class EventPrintListener { + + @ClientCacheEntryCreated + public void handleCreatedEvent(ClientCacheEntryCreatedEvent e) { + LOGGER.info("Listener: cache entry was CREATED: " + e); + } + + @ClientCacheEntryModified + public void handleModifiedEvent(ClientCacheEntryModifiedEvent e) { + LOGGER.info("Listener: cache entry was MODIFIED: " + e); + } + + @ClientCacheEntryRemoved + public void handleRemovedEvent(ClientCacheEntryRemovedEvent e) { + LOGGER.info("Listener: cache entry was REMOVED: " + e); + } + + } +} diff --git a/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/InfinispanCounterResource.java b/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/InfinispanCounterResource.java new file mode 100644 index 0000000000..e3713c9092 --- /dev/null +++ b/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/InfinispanCounterResource.java @@ -0,0 +1,62 @@ +package io.quarkus.ts.infinispan.client; + +import java.util.concurrent.atomic.AtomicInteger; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.infinispan.client.hotrod.RemoteCache; + +import io.quarkus.infinispan.client.Remote; + +public class InfinispanCounterResource { + protected AtomicInteger counter = new AtomicInteger(0); + + @Inject + @Remote("mycache") + RemoteCache cache; + + @Path("/get-cache") + @GET + @Produces(MediaType.TEXT_PLAIN) + public Integer getCacheCounter() { + return cache.get("counter"); + } + + @Path("/get-client") + @GET + @Produces(MediaType.TEXT_PLAIN) + public Integer getClientCounter() { + return counter.get(); + } + + @Path("/increment-counters") + @PUT + @Produces(MediaType.TEXT_PLAIN) + public String incCounters() { + int invocationClientNumber = counter.incrementAndGet(); + int invocationCacheNumber = cache.get("counter") + 1; + cache.put("counter", invocationCacheNumber); + return "Cache=" + invocationCacheNumber + " Client=" + invocationClientNumber; + } + + @Path("/reset-cache") + @PUT + @Produces(MediaType.TEXT_PLAIN) + public String resetCacheCounter() { + cache.put("counter", 0); + return "Cache=" + cache.get("counter"); + } + + @Path("/reset-client") + @PUT + @Produces(MediaType.TEXT_PLAIN) + public String resetClientCounter() { + counter.set(0); + return "Client=" + counter.get(); + } +} diff --git a/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/SecondCounterResource.java b/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/SecondCounterResource.java new file mode 100644 index 0000000000..6294c22ecf --- /dev/null +++ b/nosql-db/infinispan/src/main/java/io/quarkus/ts/infinispan/client/SecondCounterResource.java @@ -0,0 +1,7 @@ +package io.quarkus.ts.infinispan.client; + +import javax.ws.rs.Path; + +@Path("/second-counter") +public class SecondCounterResource extends InfinispanCounterResource { +} diff --git a/nosql-db/infinispan/src/main/resources/application.properties b/nosql-db/infinispan/src/main/resources/application.properties new file mode 100644 index 0000000000..67631119e5 --- /dev/null +++ b/nosql-db/infinispan/src/main/resources/application.properties @@ -0,0 +1,7 @@ +quarkus.infinispan-client.auth-username=admin +quarkus.infinispan-client.auth-password=password +quarkus.infinispan-client.client-intelligence=BASIC + +quarkus.infinispan-client.cache."cache".configuration-uri=cache-configuration.xml +quarkus.infinispan-client.cache."cache".near-cache-mode: disabled +quarkus.infinispan-client.cache."cache".near-cache-max-entries: -1 diff --git a/nosql-db/infinispan/src/main/resources/cache-configuration.xml b/nosql-db/infinispan/src/main/resources/cache-configuration.xml new file mode 100644 index 0000000000..2f5f86fa1e --- /dev/null +++ b/nosql-db/infinispan/src/main/resources/cache-configuration.xml @@ -0,0 +1,11 @@ + + + Very basic cache configuration + + + + + + + + diff --git a/nosql-db/infinispan/src/test/java/io/quarkus/ts/infinispan/DevModeInfinispanIT.java b/nosql-db/infinispan/src/test/java/io/quarkus/ts/infinispan/DevModeInfinispanIT.java new file mode 100644 index 0000000000..d26d27252d --- /dev/null +++ b/nosql-db/infinispan/src/test/java/io/quarkus/ts/infinispan/DevModeInfinispanIT.java @@ -0,0 +1,39 @@ +package io.quarkus.ts.infinispan; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.apache.http.HttpStatus; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.bootstrap.InfinispanService; +import io.quarkus.test.bootstrap.RestService; +import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.services.Container; +import io.quarkus.test.services.DevModeQuarkusApplication; + +@QuarkusScenario +public class DevModeInfinispanIT { + @Container(image = "${infinispan.image}", port = 11222) + static InfinispanService infinispan = new InfinispanService() + .withUsername("admin") + .withPassword("password"); + + @DevModeQuarkusApplication() + static RestService service = new RestService() + .withProperty("quarkus.infinispan-client.server-list", + () -> infinispan.getURI().toString()); + + @Test + void smoke() { + String firstCache = service.given() + .get("/first-counter/get-cache") + .then().statusCode(HttpStatus.SC_OK) + .extract().asString(); + String secondCache = service.given() + .get("/second-counter/get-cache") + .then().statusCode(HttpStatus.SC_OK) + .extract().asString(); + + assertEquals(firstCache, secondCache); + } +} diff --git a/nosql-db/infinispan/src/test/java/io/quarkus/ts/infinispan/InfinispanIT.java b/nosql-db/infinispan/src/test/java/io/quarkus/ts/infinispan/InfinispanIT.java new file mode 100644 index 0000000000..68061aeebc --- /dev/null +++ b/nosql-db/infinispan/src/test/java/io/quarkus/ts/infinispan/InfinispanIT.java @@ -0,0 +1,41 @@ +package io.quarkus.ts.infinispan; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.apache.http.HttpStatus; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.bootstrap.InfinispanService; +import io.quarkus.test.bootstrap.RestService; +import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.scenarios.annotations.DisabledOnNative; +import io.quarkus.test.services.Container; +import io.quarkus.test.services.QuarkusApplication; + +@QuarkusScenario +@DisabledOnNative(reason = "https://github.com/quarkusio/quarkus/issues/30304") +public class InfinispanIT { + @Container(image = "${infinispan.image}", port = 11222) + static InfinispanService infinispan = new InfinispanService() + .withUsername("admin") + .withPassword("password"); + + @QuarkusApplication() + static RestService service = new RestService() + .withProperty("quarkus.infinispan-client.server-list", + () -> infinispan.getURI().toString()); + + @Test + void smoke() { + String firstCache = service.given() + .get("/first-counter/get-cache") + .then().statusCode(HttpStatus.SC_OK) + .extract().asString(); + String secondCache = service.given() + .get("/second-counter/get-cache") + .then().statusCode(HttpStatus.SC_OK) + .extract().asString(); + + assertEquals(firstCache, secondCache); + } +} diff --git a/pom.xml b/pom.xml index 89c4c32c66..7851240f41 100644 --- a/pom.xml +++ b/pom.xml @@ -571,6 +571,7 @@ env-info nosql-db/mongodb nosql-db/mongodb-reactive + nosql-db/infinispan