forked from quarkus-qe/quarkus-test-suite
-
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.
Add tests for redis cache and coverage for quarkusio/quarkus#35680
Most of the tests are reused from caffeine module anshould cover similar scenarios as spring che and caffeine cache.
- Loading branch information
Showing
19 changed files
with
387 additions
and
8 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
cache/caffeine/src/main/java/io/quarkus/ts/cache/caffeine/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
2 changes: 1 addition & 1 deletion
2
cache/caffeine/src/main/java/io/quarkus/ts/cache/caffeine/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
2 changes: 1 addition & 1 deletion
2
cache/caffeine/src/main/java/io/quarkus/ts/cache/caffeine/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
2 changes: 1 addition & 1 deletion
2
cache/caffeine/src/main/java/io/quarkus/ts/cache/caffeine/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
2 changes: 1 addition & 1 deletion
2
cache/caffeine/src/main/java/io/quarkus/ts/cache/caffeine/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
2 changes: 1 addition & 1 deletion
2
cache/caffeine/src/main/java/io/quarkus/ts/cache/caffeine/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
4 changes: 2 additions & 2 deletions
4
...e/caffeine/src/test/java/io/quarkus/ts/cache/caffeine/cache/caffeine/CaffeineCacheIT.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
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,36 @@ | ||
<?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-redis</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: Cache: Redis</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-cache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-redis-cache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-qute</artifactId> | ||
</dependency> | ||
<!--> Added dependency to check https://github.com/quarkusio/quarkus/issues/35680 <--> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-mailer</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
7 changes: 7 additions & 0 deletions
7
cache/redis/src/main/java/io/quarkus/ts/cache/redis/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.caffeine; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class ApplicationScopeService extends BaseServiceWithCache { | ||
} |
38 changes: 38 additions & 0 deletions
38
cache/redis/src/main/java/io/quarkus/ts/cache/redis/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,38 @@ | ||
package io.quarkus.ts.cache.caffeine; | ||
|
||
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 int counter = 0; | ||
|
||
@CacheResult(cacheName = CACHE_NAME) | ||
public String getValue() { | ||
return "Value: " + counter++; | ||
} | ||
|
||
@CacheInvalidate(cacheName = CACHE_NAME) | ||
public void invalidate() { | ||
// do nothing | ||
} | ||
|
||
@CacheResult(cacheName = CACHE_NAME) | ||
public String getValueWithPrefix(@CacheKey String prefix) { | ||
return prefix + ": " + counter++; | ||
} | ||
|
||
@CacheInvalidate(cacheName = CACHE_NAME) | ||
public void invalidateWithPrefix(@CacheKey String prefix) { | ||
// do nothing | ||
} | ||
|
||
@CacheInvalidateAll(cacheName = CACHE_NAME) | ||
public void invalidateAll() { | ||
// do nothing | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
cache/redis/src/main/java/io/quarkus/ts/cache/redis/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.caffeine; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
|
||
@RequestScoped | ||
public class RequestScopeService extends BaseServiceWithCache { | ||
} |
65 changes: 65 additions & 0 deletions
65
cache/redis/src/main/java/io/quarkus/ts/cache/redis/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,65 @@ | ||
package io.quarkus.ts.cache.caffeine; | ||
|
||
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 String 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"); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
cache/redis/src/main/java/io/quarkus/ts/cache/redis/TemplateCacheResource.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,31 @@ | ||
package io.quarkus.ts.cache.caffeine; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.quarkus.qute.Template; | ||
|
||
@Path("template") | ||
public class TemplateCacheResource { | ||
|
||
@Inject | ||
Template cached; | ||
|
||
/** | ||
* Check for remote cache with Qute template. Qute should not use remote cache. | ||
* See https://github.com/quarkusio/quarkus/issues/35680#issuecomment-1711153725 | ||
* | ||
* @return Should return error contains `not supported for remote caches` | ||
*/ | ||
@GET | ||
@Path("error") | ||
public String getQuteTemplate() { | ||
try { | ||
return cached.render(); | ||
} catch (IllegalStateException e) { | ||
return e.getMessage(); | ||
} | ||
} | ||
|
||
} |
Empty file.
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 @@ | ||
{#cached}This cached template won't be working with remote cache like redis.{/cached} |
7 changes: 7 additions & 0 deletions
7
cache/redis/src/test/java/io/quarkus/ts/cache/redis/OpenShiftRedisCacheIT.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.redis; | ||
|
||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
|
||
@OpenShiftScenario | ||
public class OpenShiftRedisCacheIT extends RedisCacheIT { | ||
} |
Oops, something went wrong.