Skip to content

Commit

Permalink
ISPN-16317 Evolve connector
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Jul 25, 2024
1 parent d018931 commit 73621a6
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.infinispan.tutorial.simple.connect;

import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
Expand Down Expand Up @@ -67,13 +68,11 @@ public static final RemoteCacheManager connect() {
public static InfinispanContainer INFINISPAN_CONTAINER;

public static final RemoteCacheManager connect(ConfigurationBuilder builder) {

RemoteCacheManager cacheManager = null;
try {
builder.addServer().host(HOST).port(SINGLE_PORT);
cacheManager = new RemoteCacheManager(builder.build());
// Clear the cache in case it already exists from a previous running tutorial
cacheManager.getCache(TUTORIAL_CACHE_NAME).clear();
//ping
System.out.println("Get cache names: " + cacheManager.getCacheNames());
} catch (Exception ex) {
System.out.println("Unable to connect to a running server in localhost:11222. Try test containers");
if (cacheManager != null) {
Expand All @@ -85,15 +84,24 @@ public static final RemoteCacheManager connect(ConfigurationBuilder builder) {
if (cacheManager == null) {
try {
startInfinispanContainer();
builder.addServer().host(HOST).port(INFINISPAN_CONTAINER.getFirstMappedPort());
builder.addServer().host(HOST).port(INFINISPAN_CONTAINER.getMappedPort(SINGLE_PORT));
cacheManager = new RemoteCacheManager(builder.build());
// Clear the cache in case it already exists from a previous running tutorial
cacheManager.getCache(TUTORIAL_CACHE_NAME).clear();
//ping
System.out.println("Get cache names: " + cacheManager.getCacheNames());
} catch (Exception ex) {
System.out.println("Infinispan Server start with Testcontainers failed. Exit");
System.exit(0);
}
}
if (cacheManager != null) {
// Clear the cache in case it already exists from a previous running tutorial
RemoteCache<Object, Object> testCache = cacheManager.getCache(TUTORIAL_CACHE_NAME);
if (testCache != null) {
testCache.clear();
} else {
System.out.println("Test cache does not exist");
}
}
// Return the connected cache manager
return cacheManager;
}
Expand Down

0 comments on commit 73621a6

Please sign in to comment.