From 772847d0d3e9e32de5209f9d50d6ee142f8d8156 Mon Sep 17 00:00:00 2001 From: Katia Aresti Date: Thu, 15 Jun 2023 16:37:58 +0200 Subject: [PATCH] Fixes NullPointerException when using Infinispan Counter Manager --- .../test/OnlyUseCounterManagerTest.java | 39 +++++++++++++++++++ .../runtime/InfinispanClientProducer.java | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 extensions/infinispan-client/deployment/src/test/java/io/quarkus/infinispan/test/OnlyUseCounterManagerTest.java diff --git a/extensions/infinispan-client/deployment/src/test/java/io/quarkus/infinispan/test/OnlyUseCounterManagerTest.java b/extensions/infinispan-client/deployment/src/test/java/io/quarkus/infinispan/test/OnlyUseCounterManagerTest.java new file mode 100644 index 0000000000000..9e5ef51614826 --- /dev/null +++ b/extensions/infinispan-client/deployment/src/test/java/io/quarkus/infinispan/test/OnlyUseCounterManagerTest.java @@ -0,0 +1,39 @@ +package io.quarkus.infinispan.test; + +import static org.assertj.core.api.Assertions.assertThat; + +import jakarta.enterprise.inject.Default; +import jakarta.inject.Inject; + +import org.infinispan.client.hotrod.RemoteCacheManager; +import org.infinispan.counter.api.CounterConfiguration; +import org.infinispan.counter.api.CounterManager; +import org.infinispan.counter.api.CounterType; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.Arc; +import io.quarkus.test.QuarkusUnitTest; + +public class OnlyUseCounterManagerTest { + + //tag::injection[] + @Inject + CounterManager defaultCounterManager; + + //end::injection[] + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withConfigurationResource("empty-application-infinispan-client.properties"); + + @Test + public void testContainerHasBeans() { + assertThat(Arc.container().instance(RemoteCacheManager.class, Default.Literal.INSTANCE).get()).isNotNull(); + assertThat(Arc.container().instance(CounterManager.class, Default.Literal.INSTANCE).get()).isNotNull(); + + boolean created = defaultCounterManager.defineCounter("one", + CounterConfiguration.builder(CounterType.BOUNDED_STRONG).build()); + assertThat(created).isTrue(); + } +} diff --git a/extensions/infinispan-client/runtime/src/main/java/io/quarkus/infinispan/client/runtime/InfinispanClientProducer.java b/extensions/infinispan-client/runtime/src/main/java/io/quarkus/infinispan/client/runtime/InfinispanClientProducer.java index 952afe58b1ac4..d954202a327fc 100644 --- a/extensions/infinispan-client/runtime/src/main/java/io/quarkus/infinispan/client/runtime/InfinispanClientProducer.java +++ b/extensions/infinispan-client/runtime/src/main/java/io/quarkus/infinispan/client/runtime/InfinispanClientProducer.java @@ -409,7 +409,7 @@ public RemoteCacheManager getNamedRemoteCacheManager(String clientName) { } public CounterManager getNamedCounterManager(String clientName) { - RemoteCacheManager cacheManager = remoteCacheManagers.get(clientName); + RemoteCacheManager cacheManager = getNamedRemoteCacheManager(clientName); return RemoteCounterManagerFactory.asCounterManager(cacheManager); }