-
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.
Skip caching Multi and log WARN message at build time
- Loading branch information
Showing
4 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
extensions/cache/deployment/src/test/java/io/quarkus/cache/test/runtime/MultiValueTest.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.cache.test.runtime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.cache.CacheResult; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.mutiny.Multi; | ||
|
||
/** | ||
* Tests the {@link CacheResult} annotation on methods returning {@link Multi}. | ||
*/ | ||
public class MultiValueTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(CachedService.class)); | ||
|
||
@Inject | ||
CachedService cachedService; | ||
|
||
@Test | ||
public void test() { | ||
|
||
/* | ||
* io.smallrye.mutiny.Multi values returned by methods annotated with @CacheResult should never be cached. | ||
* Let's check that the cached method from this test is executed on each call. | ||
*/ | ||
Multi<String> multi1 = cachedService.cachedMethod(); | ||
assertEquals(1, cachedService.getInvocations()); | ||
Multi<String> multi2 = cachedService.cachedMethod(); | ||
assertEquals(2, cachedService.getInvocations()); | ||
|
||
/* | ||
* io.smallrye.mutiny.Uni emitted items are cached by a callback when the Unis are resolved. | ||
* We need to make sure this isn't the case for Multi values. | ||
*/ | ||
multi1.collect().asList().await().indefinitely(); | ||
cachedService.cachedMethod(); | ||
assertEquals(3, cachedService.getInvocations()); | ||
} | ||
|
||
@ApplicationScoped | ||
static class CachedService { | ||
|
||
private int invocations; | ||
|
||
@CacheResult(cacheName = "test-cache") | ||
public Multi<String> cachedMethod() { | ||
invocations++; | ||
return Multi.createFrom().items("We", "are", "not", "cached!"); | ||
} | ||
|
||
public int getInvocations() { | ||
return invocations; | ||
} | ||
} | ||
} |
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