forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that failed unis are not cached
Fixes: quarkusio#39677
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
.../deployment/src/test/java/io/quarkus/cache/test/runtime/UniReturnTypeWithFailureTest.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,53 @@ | ||
package io.quarkus.cache.test.runtime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
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.cache.CacheResult; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.core.impl.NoStackTraceException; | ||
|
||
public class UniReturnTypeWithFailureTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest().withApplicationRoot((jar) -> jar.addClass(CachedService.class)); | ||
|
||
@Inject | ||
CachedService cachedService; | ||
|
||
@Test | ||
void testCacheResult() { | ||
assertThrows(NoStackTraceException.class, () -> cachedService.cacheResult("k1").await().indefinitely()); | ||
assertEquals(1, cachedService.getCacheResultInvocations()); | ||
assertEquals("", cachedService.cacheResult("k1").await().indefinitely()); | ||
assertEquals(2, cachedService.getCacheResultInvocations()); | ||
assertEquals("", cachedService.cacheResult("k1").await().indefinitely()); | ||
assertEquals(2, cachedService.getCacheResultInvocations()); | ||
} | ||
|
||
@ApplicationScoped | ||
static class CachedService { | ||
|
||
private volatile int cacheResultInvocations; | ||
|
||
@CacheResult(cacheName = "test-cache") | ||
public Uni<String> cacheResult(String key) { | ||
cacheResultInvocations++; | ||
if (cacheResultInvocations == 1) { | ||
return Uni.createFrom().failure(new NoStackTraceException("dummy")); | ||
} | ||
return Uni.createFrom().item(() -> new String()); | ||
} | ||
|
||
public int getCacheResultInvocations() { | ||
return cacheResultInvocations; | ||
} | ||
} | ||
} |
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