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

Data cache not working when using the programmatic API #22538

Closed
argenstijn opened this issue Dec 28, 2021 · 5 comments
Closed

Data cache not working when using the programmatic API #22538

argenstijn opened this issue Dec 28, 2021 · 5 comments
Assignees
Labels
area/cache env/windows Impacts Windows machines kind/enhancement New feature or request

Comments

@argenstijn
Copy link

Describe the bug

When using the programmic API of cache you are obliged to use @CacheResult annotation or else you will get the following exception

java.lang.RuntimeException: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: javax.enterprise.inject.spi.DeploymentException: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.cache.issue.CacheIssue, cacheName=my-cache]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1196)
at io.quarkus.arc.processor.BeanProcessor.processValidationErrors(BeanProcessor.java:147)
at io.quarkus.arc.deployment.ArcProcessor.generateResources(ArcProcessor.java:483)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at java.base/java.lang.Thread.run(Thread.java:829)
at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.cache.issue.CacheIssue, cacheName=my-cache]
at io.quarkus.cache.deployment.CacheProcessor.validateCacheAnnotationsAndProduceCacheNames(CacheProcessor.java:142)
... 11 more

at io.quarkus.test.junit.QuarkusTestExtension.throwBootFailureException(QuarkusTestExtension.java:587)
at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:660)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.api.extension.InvocationInterceptor.interceptTestClassConstructor(InvocationInterceptor.java:73)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:77)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestClassConstructor(ClassBasedTestDescriptor.java:355)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateTestClass(ClassBasedTestDescriptor.java:302)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.java:79)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:280)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$4(ClassBasedTestDescriptor.java:272)
at java.base/java.util.Optional.orElseGet(Optional.java:369)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:271)
at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:102)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:101)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:66)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:95)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:91)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:60)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Caused by: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: javax.enterprise.inject.spi.DeploymentException: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.cache.issue.CacheIssue, cacheName=my-cache]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1196)
at io.quarkus.arc.processor.BeanProcessor.processValidationErrors(BeanProcessor.java:147)
at io.quarkus.arc.deployment.ArcProcessor.generateResources(ArcProcessor.java:483)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at java.base/java.lang.Thread.run(Thread.java:829)
at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.cache.issue.CacheIssue, cacheName=my-cache]
at io.quarkus.cache.deployment.CacheProcessor.validateCacheAnnotationsAndProduceCacheNames(CacheProcessor.java:142)
... 11 more

at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:330)
at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:252)
at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:60)
at io.quarkus.test.junit.QuarkusTestExtension.doJavaStart(QuarkusTestExtension.java:221)
at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted(QuarkusTestExtension.java:564)
at io.quarkus.test.junit.QuarkusTestExtension.beforeAll(QuarkusTestExtension.java:602)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$10(ClassBasedTestDescriptor.java:381)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:381)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:205)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:80)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:148)
... 35 more

Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: javax.enterprise.inject.spi.DeploymentException: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.cache.issue.CacheIssue, cacheName=my-cache]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1196)
at io.quarkus.arc.processor.BeanProcessor.processValidationErrors(BeanProcessor.java:147)
at io.quarkus.arc.deployment.ArcProcessor.generateResources(ArcProcessor.java:483)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at java.base/java.lang.Thread.run(Thread.java:829)
at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.cache.issue.CacheIssue, cacheName=my-cache]
at io.quarkus.cache.deployment.CacheProcessor.validateCacheAnnotationsAndProduceCacheNames(CacheProcessor.java:142)
... 11 more

at io.quarkus.builder.Execution.run(Execution.java:116)
at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:79)
at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:161)
at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:328)
... 46 more

Caused by: javax.enterprise.inject.spi.DeploymentException: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.cache.issue.CacheIssue, cacheName=my-cache]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1196)
at io.quarkus.arc.processor.BeanProcessor.processValidationErrors(BeanProcessor.java:147)
at io.quarkus.arc.deployment.ArcProcessor.generateResources(ArcProcessor.java:483)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at java.base/java.lang.Thread.run(Thread.java:829)
at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.cache.issue.CacheIssue, cacheName=my-cache]
at io.quarkus.cache.deployment.CacheProcessor.validateCacheAnnotationsAndProduceCacheNames(CacheProcessor.java:142)
... 11 more

Expected behavior

@when injection a cache you should not have to use any 'cache ' annotation with exception of @Cache.

Actual behavior

When only using @Cache it result in the given exception:

Caused by: io.quarkus.cache.deployment.exception.UnknownCacheNameException: A field or method parameter is annotated with a @CacheName annotation referencing an unknown cache name [class=com.nn.aav.insurance.aab.proxy.business.authentication.boundary.OAuth2Filter, cacheName=customerapi]
at io.quarkus.cache.deployment.CacheProcessor.validateCacheAnnotationsAndProduceCacheNames(CacheProcessor.java:142)
... 11 more

How to Reproduce?

Just run the test

cache.zip

Output of uname -a or ver

Microsoft Windows [Version 10.0.19043.1415]

Output of java -version

openjdk version "11.0.12" 2021-07-20 LTS OpenJDK Runtime Environment Corretto-11.0.12.7.1 (build 11.0.12+7-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.12.7.1 (build 11.0.12+7-LTS, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

Quarkus 2.6.0

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.3

Additional information

No response

@argenstijn argenstijn added the kind/bug Something isn't working label Dec 28, 2021
@quarkus-bot quarkus-bot bot added env/windows Impacts Windows machines triage/needs-triage labels Dec 28, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Dec 28, 2021

/cc @gwenneg

@gwenneg
Copy link
Member

gwenneg commented Dec 29, 2021

Hi @argenstijn and thanks for creating this issue.

The behavior you described is actually intentional. As explained in the quarkus-cache doc:

Quarkus also offers a programmatic API which can be used to store, retrieve or delete values from any cache declared using the annotations API.

quarkus-cache is currently centered around the annotations API. The programmatic API is a new feature meant to be used with caches declared with annotations. It's not a standalone caching feature. I don't think the doc makes that detail clear enough though, I'll improve it.

The programmatic caching API is currently composed of two entry points: @CacheName and CacheManager.

Declaring a cache is not currently supported with @CacheName. The cache won't be created unless it is used with @CacheResult, @CacheInvalidate or @CacheInvalidateAll somewhere in the application. Same goes for CacheManager#getCache.

I think we could change things a bit and support the creation of a cache declared with @CacheName alone. I'll create a PR for it. However, CacheManager#getCache will still not support the creation of a cache because caches are instantiated at build time and there is no way to know at that moment which value will be passed to CacheManager#getCache at runtime.

@gwenneg gwenneg added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Dec 29, 2021
@gwenneg gwenneg self-assigned this Dec 29, 2021
@argenstijn
Copy link
Author

thanks for the explanation.

Yes, the documentation had an example without @CacheInvalidate and that was a bit confusing:

afbeelding

_CacheManager#getCache will still not support the creation of a cache because caches are instantiated at build time and there is not way to know at that moment which value will be passed to CacheManager#getCache at runtime.

Maybe by defining a property?

With kind regards,
Mark

@rafaelfnx
Copy link

Hi! I am experiencing the same problem here.

I think we could change things a bit and support the creation of a cache declared with @CacheName alone. I'll create a PR for it. However, CacheManager#getCache will still not support the creation of a cache because caches are instantiated at build time and there is no way to know at that moment which value will be passed to CacheManager#getCache at runtime.

I liked the solution, it would be great if @CacheName could create a cache by itself!

Maybe by defining a property?

I would like to express a positive vote for this solution as well.
It would be ideal if both were accepted.

@geoand geoand changed the title Data cach :not working when using the programmatic API Data cache not working when using the programmatic API Jan 14, 2022
@argenstijn
Copy link
Author

Close issue as the merge was done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cache env/windows Impacts Windows machines kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants