Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mihaita-tinta/3d9f88a89a26080f70b7016808c4b972 to your computer and use it in GitHub Desktop.
Save mihaita-tinta/3d9f88a89a26080f70b7016808c4b972 to your computer and use it in GitHub Desktop.
package com.mihaita.articles.caching;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.stream.IntStream;
@SpringBootTest(classes = {MyServiceTestConfiguration.class, CompletableFutureCacheableConfiguration.class},
properties = {
"logging.level.org.springframework.cache=TRACE",
"logging.level.com.mihaita.articles.caching=TRACE",
})
@ExtendWith(SpringExtension.class)
class CompletableFutureCacheableMethodInterceptorTest {
private static final Logger log = LoggerFactory.getLogger(CompletableFutureCacheableMethodInterceptorTest.class);
@Autowired
MyServiceTestConfiguration.MyCompletableFutureCachedService service;
@Test
public void testFutureCacheableCompletableFuture() {
IntStream.range(0, 10)
.mapToObj(i -> 1)
.forEach(i -> service.getStuffById(i)
.thenAccept(res -> {
log.info("testFutureCacheableCompletableFuture - {} call thenAccept: {}", i, res);
})
.exceptionally(res -> {
log.info("testFutureCacheableCompletableFuture - {} call failed", i);
return null;
})
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment