-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redis cache: make blocking executions unordered
When the Redis cache is invoked from an ordered Vert.x blocking execution, which happens for example with SmallRye GraphQL or with chained caching (one blocking `@CacheResult` method invoking other blocking `@CacheResult` method), the Redis cache ends up hanging. This is because the next execution cannot start until the previous execution finishes, but the previous execution waits for the next execution. This commit fixes that by making the Redis cache blocking executions unordered.
- Loading branch information
Showing
2 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...che/deployment/src/test/java/io/quarkus/cache/redis/deployment/ChainedRedisCacheTest.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,49 @@ | ||
package io.quarkus.cache.redis.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.cache.CacheResult; | ||
import io.quarkus.redis.datasource.RedisDataSource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ChainedRedisCacheTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot(jar -> jar.addClasses(ChainedCachedService.class, TestUtil.class)); | ||
|
||
@Inject | ||
ChainedCachedService chainedCachedService; | ||
|
||
@Test | ||
public void test() { | ||
RedisDataSource redisDataSource = Arc.container().select(RedisDataSource.class).get(); | ||
List<String> allKeysAtStart = TestUtil.allRedisKeys(redisDataSource); | ||
|
||
assertEquals("fubar:42", chainedCachedService.cache1("fubar")); | ||
|
||
List<String> allKeysAtEnd = TestUtil.allRedisKeys(redisDataSource); | ||
assertEquals(allKeysAtStart.size() + 2, allKeysAtEnd.size()); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class ChainedCachedService { | ||
@CacheResult(cacheName = "cache1") | ||
public String cache1(String key) { | ||
return key + ":" + cache2(42); | ||
} | ||
|
||
@CacheResult(cacheName = "cache2") | ||
public int cache2(int value) { | ||
return value; | ||
} | ||
} | ||
} |
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