-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage for infinispan cache extension
- Loading branch information
Showing
14 changed files
with
535 additions
and
0 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
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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<artifactId>cache-infinispan</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: Cache: Infinispan</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-infinispan-cache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus.qe</groupId> | ||
<artifactId>quarkus-test-service-infinispan</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
7 changes: 7 additions & 0 deletions
7
cache/infinispan/src/main/java/io/quarkus/ts/cache/infinispan/ApplicationScopeService.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,7 @@ | ||
package io.quarkus.ts.cache.infinispan; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class ApplicationScopeService extends BaseServiceWithCache { | ||
} |
52 changes: 52 additions & 0 deletions
52
cache/infinispan/src/main/java/io/quarkus/ts/cache/infinispan/BaseServiceWithCache.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,52 @@ | ||
package io.quarkus.ts.cache.infinispan; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.infinispan.protostream.GeneratedSchema; | ||
import org.infinispan.protostream.annotations.Proto; | ||
import org.infinispan.protostream.annotations.ProtoSchema; | ||
|
||
import io.quarkus.cache.CacheInvalidate; | ||
import io.quarkus.cache.CacheInvalidateAll; | ||
import io.quarkus.cache.CacheKey; | ||
import io.quarkus.cache.CacheResult; | ||
|
||
public abstract class BaseServiceWithCache { | ||
|
||
private static final String CACHE_NAME = "service-cache"; | ||
|
||
private static final AtomicInteger counter = new AtomicInteger(0); | ||
|
||
@CacheResult(cacheName = CACHE_NAME) | ||
public String getValue() { | ||
return "Value: " + counter.getAndIncrement(); | ||
} | ||
|
||
@CacheInvalidate(cacheName = CACHE_NAME) | ||
public void invalidate() { | ||
// do nothing | ||
} | ||
|
||
@CacheResult(cacheName = CACHE_NAME) | ||
public ExpensiveResponse getValueWithPrefix(@CacheKey String prefix) { | ||
return new ExpensiveResponse(prefix + ": " + counter.getAndIncrement()); | ||
} | ||
|
||
@CacheInvalidate(cacheName = CACHE_NAME) | ||
public void invalidateWithPrefix(@CacheKey String prefix) { | ||
// do nothing | ||
} | ||
|
||
@CacheInvalidateAll(cacheName = CACHE_NAME) | ||
public void invalidateAll() { | ||
// do nothing | ||
} | ||
|
||
@Proto | ||
public record ExpensiveResponse(String result) { | ||
} | ||
|
||
@ProtoSchema(includeClasses = { ExpensiveResponse.class }) | ||
interface Schema extends GeneratedSchema { | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
cache/infinispan/src/main/java/io/quarkus/ts/cache/infinispan/BlockingWithCacheResource.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,57 @@ | ||
package io.quarkus.ts.cache.infinispan; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
|
||
import io.quarkus.cache.CacheInvalidate; | ||
import io.quarkus.cache.CacheInvalidateAll; | ||
import io.quarkus.cache.CacheKey; | ||
import io.quarkus.cache.CacheResult; | ||
import io.smallrye.common.annotation.Blocking; | ||
|
||
@Blocking | ||
@Path("/api/blocking") | ||
public class BlockingWithCacheResource { | ||
|
||
private static final String CACHE_NAME = "api-blocking-cache"; | ||
|
||
private final AtomicInteger counter = new AtomicInteger(0); | ||
|
||
@GET | ||
@CacheResult(cacheName = CACHE_NAME) | ||
public String getValue() { | ||
return "Value: " + counter.getAndIncrement(); | ||
} | ||
|
||
@POST | ||
@Path("/invalidate-cache") | ||
@CacheInvalidate(cacheName = CACHE_NAME) | ||
public void invalidate() { | ||
// do nothing | ||
} | ||
|
||
@GET | ||
@Path("/using-prefix/{prefix}") | ||
@CacheResult(cacheName = CACHE_NAME) | ||
public String getValueWithPrefix(@PathParam("prefix") @CacheKey String prefix) { | ||
return prefix + ": " + counter.getAndIncrement(); | ||
} | ||
|
||
@POST | ||
@Path("/using-prefix/{prefix}/invalidate-cache") | ||
@CacheInvalidate(cacheName = CACHE_NAME) | ||
public void invalidateWithPrefix(@PathParam("prefix") @CacheKey String prefix) { | ||
// do nothing | ||
} | ||
|
||
@POST | ||
@Path("/invalidate-cache-all") | ||
@CacheInvalidateAll(cacheName = CACHE_NAME) | ||
public void invalidateAll() { | ||
// do nothing | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
cache/infinispan/src/main/java/io/quarkus/ts/cache/infinispan/CacheExpirationResource.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,21 @@ | ||
package io.quarkus.ts.cache.infinispan; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import io.quarkus.cache.CacheKey; | ||
import io.quarkus.cache.CacheResult; | ||
|
||
@Path("/cache") | ||
public class CacheExpirationResource { | ||
|
||
@GET | ||
@Path("/{key}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@CacheResult(cacheName = "expiring-cache") | ||
public String getCachedValue(@CacheKey String key) { | ||
return "Value for key " + key + " at " + System.currentTimeMillis(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
cache/infinispan/src/main/java/io/quarkus/ts/cache/infinispan/ReactiveWithCacheResource.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,58 @@ | ||
package io.quarkus.ts.cache.infinispan; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
|
||
import io.quarkus.cache.CacheInvalidate; | ||
import io.quarkus.cache.CacheInvalidateAll; | ||
import io.quarkus.cache.CacheKey; | ||
import io.quarkus.cache.CacheResult; | ||
import io.smallrye.common.annotation.NonBlocking; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@NonBlocking | ||
@Path("/api/reactive") | ||
public class ReactiveWithCacheResource { | ||
|
||
private static final String CACHE_NAME = "api-reactive-cache"; | ||
|
||
private final AtomicInteger counter = new AtomicInteger(0); | ||
|
||
@GET | ||
@CacheResult(cacheName = CACHE_NAME) | ||
public Uni<String> getValue() { | ||
return Uni.createFrom().item("Value: " + counter.getAndIncrement()); | ||
} | ||
|
||
@POST | ||
@Path("/invalidate-cache") | ||
@CacheInvalidate(cacheName = CACHE_NAME) | ||
public Uni<Void> invalidate() { | ||
return Uni.createFrom().nullItem(); | ||
} | ||
|
||
@GET | ||
@Path("/using-prefix/{prefix}") | ||
@CacheResult(cacheName = CACHE_NAME) | ||
public Uni<String> getValueWithPrefix(@PathParam("prefix") @CacheKey String prefix) { | ||
return Uni.createFrom().item(prefix + ": " + counter.getAndIncrement()); | ||
} | ||
|
||
@POST | ||
@Path("/using-prefix/{prefix}/invalidate-cache") | ||
@CacheInvalidate(cacheName = CACHE_NAME) | ||
public Uni<Void> invalidateWithPrefix(@PathParam("prefix") @CacheKey String prefix) { | ||
return Uni.createFrom().nullItem(); | ||
} | ||
|
||
@POST | ||
@Path("/invalidate-cache-all") | ||
@CacheInvalidateAll(cacheName = CACHE_NAME) | ||
public Uni<Void> invalidateAll() { | ||
return Uni.createFrom().nullItem(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
cache/infinispan/src/main/java/io/quarkus/ts/cache/infinispan/RequestScopeService.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,7 @@ | ||
package io.quarkus.ts.cache.infinispan; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
|
||
@RequestScoped | ||
public class RequestScopeService extends BaseServiceWithCache { | ||
} |
66 changes: 66 additions & 0 deletions
66
cache/infinispan/src/main/java/io/quarkus/ts/cache/infinispan/ServiceWithCacheResource.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,66 @@ | ||
package io.quarkus.ts.cache.infinispan; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
@Path("/services") | ||
public class ServiceWithCacheResource { | ||
|
||
public static final String APPLICATION_SCOPE_SERVICE_PATH = "application-scope"; | ||
public static final String REQUEST_SCOPE_SERVICE_PATH = "request-scope"; | ||
|
||
@Inject | ||
ApplicationScopeService applicationScopeService; | ||
|
||
@Inject | ||
RequestScopeService requestScopeService; | ||
|
||
@GET | ||
@Path("/{service}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String getValueFromService(@PathParam("service") String service) { | ||
return lookupServiceByPathParam(service).getValue(); | ||
} | ||
|
||
@POST | ||
@Path("/{service}/invalidate-cache") | ||
public void invalidateCacheFromService(@PathParam("service") String service) { | ||
lookupServiceByPathParam(service).invalidate(); | ||
} | ||
|
||
@POST | ||
@Path("/{service}/invalidate-cache-all") | ||
public void invalidateCacheAllFromService(@PathParam("service") String service) { | ||
lookupServiceByPathParam(service).invalidateAll(); | ||
} | ||
|
||
@GET | ||
@Path("/{service}/using-prefix/{prefix}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public BaseServiceWithCache.ExpensiveResponse getValueUsingPrefixFromService(@PathParam("service") String service, | ||
@PathParam("prefix") String prefix) { | ||
return lookupServiceByPathParam(service).getValueWithPrefix(prefix); | ||
} | ||
|
||
@POST | ||
@Path("/{service}/using-prefix/{prefix}/invalidate-cache") | ||
public void invalidateCacheUsingPrefixFromService(@PathParam("service") String service, | ||
@PathParam("prefix") String prefix) { | ||
lookupServiceByPathParam(service).invalidateWithPrefix(prefix); | ||
} | ||
|
||
private BaseServiceWithCache lookupServiceByPathParam(String service) { | ||
if (APPLICATION_SCOPE_SERVICE_PATH.equals(service)) { | ||
return applicationScopeService; | ||
} else if (REQUEST_SCOPE_SERVICE_PATH.equals(service)) { | ||
return requestScopeService; | ||
} | ||
|
||
throw new IllegalArgumentException("Service " + service + " is not recognised"); | ||
} | ||
} |
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,3 @@ | ||
quarkus.infinispan-client.hosts=localhost:11222 | ||
quarkus.cache.infinispan.expiring-cache.lifespan=3s | ||
quarkus.cache.infinispan.expiring-cache.max-idle=5s |
Oops, something went wrong.