diff --git a/infinispan-remote/connect-to-infinispan-server/src/main/java/org/infinispan/tutorial/simple/connect/TutorialsConnectorHelper.java b/infinispan-remote/connect-to-infinispan-server/src/main/java/org/infinispan/tutorial/simple/connect/TutorialsConnectorHelper.java index a3c1c8d2..5770a5c9 100644 --- a/infinispan-remote/connect-to-infinispan-server/src/main/java/org/infinispan/tutorial/simple/connect/TutorialsConnectorHelper.java +++ b/infinispan-remote/connect-to-infinispan-server/src/main/java/org/infinispan/tutorial/simple/connect/TutorialsConnectorHelper.java @@ -107,12 +107,16 @@ public static final RemoteCacheManager connect(ConfigurationBuilder builder) { } public static InfinispanContainer startInfinispanContainer() { + return startInfinispanContainer(1000); + } + + public static InfinispanContainer startInfinispanContainer(long millis) { try { INFINISPAN_CONTAINER = new InfinispanContainer(); INFINISPAN_CONTAINER.withUser(USER); INFINISPAN_CONTAINER.withPassword(PASSWORD); INFINISPAN_CONTAINER.start(); - Thread.sleep(3000); + Thread.sleep(millis); } catch (Exception ex) { System.out.println("Unable to start Infinispan container"); return null; diff --git a/infinispan-remote/reactive-api/src/main/java/org/infinispan/tutorial/simple/reactive/InfinispanReactiveApi.java b/infinispan-remote/reactive-api/src/main/java/org/infinispan/tutorial/simple/reactive/InfinispanReactiveApi.java index 9b5eb711..a5067f09 100644 --- a/infinispan-remote/reactive-api/src/main/java/org/infinispan/tutorial/simple/reactive/InfinispanReactiveApi.java +++ b/infinispan-remote/reactive-api/src/main/java/org/infinispan/tutorial/simple/reactive/InfinispanReactiveApi.java @@ -2,6 +2,7 @@ import org.infinispan.api.Infinispan; import org.infinispan.api.mutiny.MutinyCache; +import org.infinispan.api.sync.SyncCache; import org.infinispan.commons.util.OS; import org.infinispan.hotrod.configuration.ClientIntelligence; import org.infinispan.hotrod.configuration.HotRodConfigurationBuilder; @@ -40,11 +41,7 @@ static void initCache() { } static void manipulateCacheReactive() { - ScheduledExecutorService executor = Executors.newScheduledThreadPool(4, t -> { - Thread wrap = new Thread(t); - wrap.setDaemon(true); - return wrap; - }); + ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); cache.set("hello", "reactive") .chain(ignore -> cache.get("hello")) @@ -53,23 +50,19 @@ static void manipulateCacheReactive() { .onItem().delayIt().onExecutor(executor).by(Duration.ofSeconds(1)) .invoke(v -> System.out.printf("%s -- %s\n", LocalDateTime.now(), v)) .await().atMost(Duration.ofSeconds(2)); + + executor.shutdown(); } public static final void connect() { // New API Connection HotRodConfigurationBuilder builder = createHotRodConfigurationBuilder(); - // Add default host/port server - builder.addServer().host(HOST).port(SINGLE_PORT); - infinispan = null; try { infinispan = Infinispan.create(builder.build()); clearCache(); } catch (Exception ex) { System.out.println("Unable to connect to a running server in localhost:11222. Try test containers"); - if (infinispan != null) { - disconnect(false); - } infinispan = null; } @@ -77,7 +70,7 @@ public static final void connect() { try { TutorialsConnectorHelper.startInfinispanContainer(); builder = createHotRodConfigurationBuilder(); - builder.addServer().host(HOST).port(INFINISPAN_CONTAINER.getFirstMappedPort()); + builder.addServer().host(HOST).port(INFINISPAN_CONTAINER.getMappedPort(SINGLE_PORT)); infinispan = Infinispan.create(builder.build()); clearCache(); } catch (Exception ex) { @@ -107,7 +100,10 @@ private static HotRodConfigurationBuilder createHotRodConfigurationBuilder() { private static void clearCache() { if (infinispan != null) { // Clear the cache in case it already exists from a previous running tutorial - infinispan.sync().caches().get(TUTORIAL_CACHE_NAME).clear(); + SyncCache cache = infinispan.sync().caches().get(TUTORIAL_CACHE_NAME); + if (cache != null) { + cache.clear(); + } } } diff --git a/infinispan-remote/reactive-api/src/test/java/org/infinispan/tutorial/simple/reactive/InfinispanReactiveApiTest.java b/infinispan-remote/reactive-api/src/test/java/org/infinispan/tutorial/simple/reactive/InfinispanReactiveApiTest.java index 1adce036..4a4a726e 100644 --- a/infinispan-remote/reactive-api/src/test/java/org/infinispan/tutorial/simple/reactive/InfinispanReactiveApiTest.java +++ b/infinispan-remote/reactive-api/src/test/java/org/infinispan/tutorial/simple/reactive/InfinispanReactiveApiTest.java @@ -2,12 +2,14 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.infinispan.tutorial.simple.connect.TutorialsConnectorHelper.TUTORIAL_CACHE_NAME; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +@Disabled public class InfinispanReactiveApiTest { @BeforeAll