Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis cache: make blocking executions unordered #42540

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private <K, V> Uni<V> computeValue(K key, Function<K, V> valueLoader, boolean is
public V get() {
return valueLoader.apply(key);
}
}).runSubscriptionOn(MutinyHelper.blockingExecutor(vertx.getDelegate()));
}).runSubscriptionOn(MutinyHelper.blockingExecutor(vertx.getDelegate(), false));
} else {
return Uni.createFrom().item(valueLoader.apply(key));
}
Expand Down Expand Up @@ -205,8 +205,8 @@ public Uni<?> apply(V value) {
result = set(connection, encodedKey, encodedValue).replaceWith(value);
}
if (isWorkerThread) {
return result
.runSubscriptionOn(MutinyHelper.blockingExecutor(vertx.getDelegate()));
return result.runSubscriptionOn(
MutinyHelper.blockingExecutor(vertx.getDelegate(), false));
}
return result;
}
Expand Down