Fixed - Issue with asynchronous @Cacheable methods

Signed-off-by: seakider <seakider@gmail.com>
pull/6455/head
seakider 2 days ago
parent c600011dc9
commit 6fdbd58afd

@ -56,7 +56,7 @@ public class RedissonAsyncCache implements AsyncCache<RMap<Object, Object>> {
return map.getAsync(key)
.thenApply(v -> {
if (v != null) {
return Optional.of((T)conversionService.convert(v, ConversionContext.of(requiredType)));
return conversionService.convert(v, ConversionContext.of(requiredType));
}
return Optional.<T>empty();
})

@ -1,5 +1,6 @@
package org.redisson.micronaut;
import io.micronaut.cache.AsyncCache;
import io.micronaut.context.ApplicationContext;
import io.micronaut.inject.qualifiers.Qualifiers;
import org.junit.jupiter.api.Test;
@ -8,6 +9,9 @@ import org.redisson.micronaut.cache.RedissonSyncCache;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.assertj.core.api.Assertions.assertThat;
@ -42,4 +46,29 @@ public class RedissonCacheTest {
assertThat(cache.get(3, Integer.class).isPresent()).isTrue();
}
@Test
public void testAsyncCache() throws ExecutionException, InterruptedException {
Map<String, Object> map = new HashMap<>();
map.put("redisson.threads", "10");
map.put("redisson.single-server-config.address", "redis://127.0.0.1:6379");
map.put("redisson.caches.test.expire-after-write", "3s");
map.put("redisson.caches.test.expire-after-access", "3s");
ApplicationContext ac = ApplicationContext.run(map);
RedissonClient client = ac.getBean(RedissonClient.class);
assertThat(client).isNotNull();
client.getKeys().flushall();
RedissonSyncCache cache = ac.getBean(RedissonSyncCache.class, Qualifiers.byName("test"));
AsyncCache asyncCache = cache.async();
assertThat(asyncCache.get(3, Integer.class).get()).isEqualTo(Optional.empty());
CompletableFuture f = asyncCache.put(3, 4).toCompletableFuture();
f.join();
assertThat(asyncCache.get(3, Integer.class).get()).isEqualTo(Optional.of(4));
}
}

@ -56,7 +56,7 @@ public class RedissonAsyncCache implements AsyncCache<RMap<Object, Object>> {
return map.getAsync(key)
.thenApply(v -> {
if (v != null) {
return Optional.of((T)conversionService.convert(v, ConversionContext.of(requiredType)));
return conversionService.convert(v, ConversionContext.of(requiredType));
}
return Optional.<T>empty();
})

@ -1,5 +1,6 @@
package org.redisson.micronaut;
import io.micronaut.cache.AsyncCache;
import io.micronaut.context.ApplicationContext;
import io.micronaut.inject.qualifiers.Qualifiers;
import org.junit.jupiter.api.Test;
@ -8,6 +9,9 @@ import org.redisson.micronaut.cache.RedissonSyncCache;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.assertj.core.api.Assertions.assertThat;
@ -42,4 +46,29 @@ public class RedissonCacheTest {
assertThat(cache.get(3, Integer.class).isPresent()).isTrue();
}
@Test
public void testAsyncCache() throws ExecutionException, InterruptedException {
Map<String, Object> map = new HashMap<>();
map.put("redisson.threads", "10");
map.put("redisson.single-server-config.address", "redis://127.0.0.1:6379");
map.put("redisson.caches.test.expire-after-write", "3s");
map.put("redisson.caches.test.expire-after-access", "3s");
ApplicationContext ac = ApplicationContext.run(map);
RedissonClient client = ac.getBean(RedissonClient.class);
assertThat(client).isNotNull();
client.getKeys().flushall();
RedissonSyncCache cache = ac.getBean(RedissonSyncCache.class, Qualifiers.byName("test"));
AsyncCache asyncCache = cache.async();
assertThat(asyncCache.get(3, Integer.class).get()).isEqualTo(Optional.empty());
CompletableFuture f = asyncCache.put(3, 4).toCompletableFuture();
f.join();
assertThat(asyncCache.get(3, Integer.class).get()).isEqualTo(Optional.of(4));
}
}

@ -56,7 +56,7 @@ public class RedissonAsyncCache implements AsyncCache<RMap<Object, Object>> {
return map.getAsync(key)
.thenApply(v -> {
if (v != null) {
return Optional.of((T)conversionService.convert(v, ConversionContext.of(requiredType)));
return conversionService.convert(v, ConversionContext.of(requiredType));
}
return Optional.<T>empty();
})

@ -1,5 +1,6 @@
package org.redisson.micronaut;
import io.micronaut.cache.AsyncCache;
import io.micronaut.context.ApplicationContext;
import io.micronaut.inject.qualifiers.Qualifiers;
import org.junit.jupiter.api.Test;
@ -12,6 +13,9 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.assertj.core.api.Assertions.assertThat;
@ -49,6 +53,30 @@ public class RedissonCacheTest {
cache.get(3, Integer.class);
Thread.sleep(2000);
assertThat(cache.get(3, Integer.class).isPresent()).isTrue();
}
@Test
public void testAsyncCache() throws ExecutionException, InterruptedException {
Map<String, Object> map = new HashMap<>();
map.put("redisson.threads", "10");
map.put("redisson.single-server-config.address", "redis://127.0.0.1:" + REDIS.getFirstMappedPort());
map.put("redisson.caches.test.expire-after-write", "10s");
map.put("redisson.caches.test.expire-after-access", "10s");
ApplicationContext ac = ApplicationContext.run(map);
RedissonClient client = ac.getBean(RedissonClient.class);
assertThat(client).isNotNull();
RedissonSyncCache cache = ac.getBean(RedissonSyncCache.class, Qualifiers.byName("test"));
AsyncCache asyncCache = cache.async();
assertThat(asyncCache.get(3, Integer.class).get()).isEqualTo(Optional.empty());
CompletableFuture f = asyncCache.put(3, 4).toCompletableFuture();
f.join();
assertThat(asyncCache.get(3, Integer.class).get()).isEqualTo(Optional.of(4));
}
@Test

Loading…
Cancel
Save