Skip to content

Commit

Permalink
ISPN-16317 Unit Test Remote Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Jul 23, 2024
1 parent 0c325e4 commit 37ae3a4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
5 changes: 5 additions & 0 deletions infinispan-remote/cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,30 @@
*/
public class InfinispanRemoteCache {

static RemoteCacheManager cacheManager;
static RemoteCache<String, String> cache;

public static void main(String[] args) {
// Connect to the server
RemoteCacheManager cacheManager = TutorialsConnectorHelper.connect();
// Obtain the remote cache
RemoteCache<String, String> cache = cacheManager.getCache(TUTORIAL_CACHE_NAME);
/// Store a value
connectToInfinispan();
manipulateCache();
deconnect();
}

static void manipulateCache() {
// Store a value
cache.put("key", "value");
// Retrieve the value and print it out
System.out.printf("key = %s\n", cache.get("key"));
}

static void connectToInfinispan() {
// Connect to the server
cacheManager = TutorialsConnectorHelper.connect();
// Obtain the remote cache
cache = cacheManager.getCache(TUTORIAL_CACHE_NAME);
}

static void deconnect() {
// Stop the cache manager and release all resources
TutorialsConnectorHelper.stop(cacheManager);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.infinispan.tutorial.simple.remote;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class InfinispanRemoteCacheTest {

@BeforeAll
public static void start() {
InfinispanRemoteCache.connectToInfinispan();
}

@AfterAll
public static void stop() {
InfinispanRemoteCache.deconnect();
}

@Test
public void testRemoteCache() {
assertNotNull(InfinispanRemoteCache.cache);

InfinispanRemoteCache.manipulateCache();

assertEquals("value", InfinispanRemoteCache.cache.get("key"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ public static void stopInfinispanContainer() {
}

public static void stop(RemoteCacheManager cacheManager) {
cacheManager.stop();
stopInfinispanContainer();
if (cacheManager != null){
cacheManager.stop();
stopInfinispanContainer();
}
}

}

0 comments on commit 37ae3a4

Please sign in to comment.