event) {
- System.out.printf("About to modify %s%n", event.getKey());
+ String logMessage = String.format("About to modify %s%n", event.getKey());
+ logTrack.append(logMessage);
+ System.out.printf(logMessage);
}
}
diff --git a/infinispan-remote/listeners/src/test/java/org/infinispan/tutorial/simple/remote/listen/InfinispanRemoteListenTest.java b/infinispan-remote/listeners/src/test/java/org/infinispan/tutorial/simple/remote/listen/InfinispanRemoteListenTest.java
new file mode 100644
index 00000000..21932c9d
--- /dev/null
+++ b/infinispan-remote/listeners/src/test/java/org/infinispan/tutorial/simple/remote/listen/InfinispanRemoteListenTest.java
@@ -0,0 +1,42 @@
+package org.infinispan.tutorial.simple.remote.listen;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+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;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class InfinispanRemoteListenTest {
+
+ @BeforeAll
+ public static void start() {
+ InfinispanRemoteListen.connectToInfinispan();
+ }
+
+ @AfterAll
+ public static void stop() {
+ InfinispanRemoteListen.disconnect(true);
+ }
+
+ @Test
+ public void testRemoteListen() throws Exception {
+ assertNotNull(InfinispanRemoteListen.cacheManager);
+ assertNotNull(InfinispanRemoteListen.cache);
+
+ InfinispanRemoteListen.registerListener();
+
+ assertNotNull(InfinispanRemoteListen.listener);
+
+ InfinispanRemoteListen.manipulateCache();
+
+ Thread.sleep(1000);
+
+ String logTrack = InfinispanRemoteListen.listener.logTrack.toString();
+ assertEquals(2, InfinispanRemoteListen.cache.size());
+ assertTrue(logTrack.contains("Created"));
+ assertTrue(logTrack.contains("About to modify"));
+ }
+}
diff --git a/infinispan-remote/multimap/pom.xml b/infinispan-remote/multimap/pom.xml
index 212cd55b..32e4ac6a 100644
--- a/infinispan-remote/multimap/pom.xml
+++ b/infinispan-remote/multimap/pom.xml
@@ -46,5 +46,10 @@
org.infinispan
infinispan-client-hotrod
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
diff --git a/infinispan-remote/multimap/src/main/java/org/infinispan/tutorial/simple/remote/multimap/InfinispanRemoteMultimap.java b/infinispan-remote/multimap/src/main/java/org/infinispan/tutorial/simple/remote/multimap/InfinispanRemoteMultimap.java
index 0b5c003a..5ca6fa8a 100644
--- a/infinispan-remote/multimap/src/main/java/org/infinispan/tutorial/simple/remote/multimap/InfinispanRemoteMultimap.java
+++ b/infinispan-remote/multimap/src/main/java/org/infinispan/tutorial/simple/remote/multimap/InfinispanRemoteMultimap.java
@@ -6,6 +6,10 @@
import org.infinispan.client.hotrod.multimap.RemoteMultimapCacheManagerFactory;
import org.infinispan.tutorial.simple.connect.TutorialsConnectorHelper;
+import java.util.concurrent.TimeUnit;
+
+import static org.infinispan.tutorial.simple.connect.TutorialsConnectorHelper.TUTORIAL_CACHE_NAME;
+
/**
* The Remote Multimap simple tutorial.
*
@@ -18,29 +22,46 @@
*/
public class InfinispanRemoteMultimap {
+ static RemoteCacheManager cacheManager;
+ static MultimapCacheManager multimapCacheManager;
+ static RemoteMultimapCache multimap;
+
public static void main(String[] args) throws Exception {
+ connectToInfinispan();
+ manipulateMultimap();
+ disconnect(false);
+ }
+
+ static void manipulateMultimap() throws Exception {
+ multimap.put(2016, "Rosita");
+ multimap.put(2016, "Guillermo");
+ multimap.put(2016, "Patricia");
+ multimap.put(2016, "Silvia");
+ multimap.put(2017, "Matilda");
+ multimap.put(2017, "Hector");
+ multimap.put(2018, "Richard").get(10, TimeUnit.SECONDS);
+
+ multimap.get(2016).whenComplete((v, ex) -> {
+ System.out.println(v);
+ }).join();
+ }
+
+ public static void connectToInfinispan() {
// Connect to the server and create a cache
- RemoteCacheManager cacheManager = TutorialsConnectorHelper.connect();
+ cacheManager = TutorialsConnectorHelper.connect();
// Retrieve the MultimapCacheManager from the CacheManager.
- MultimapCacheManager multimapCacheManager = RemoteMultimapCacheManagerFactory.from(cacheManager);
+ multimapCacheManager = RemoteMultimapCacheManagerFactory.from(cacheManager);
// Retrieve the multimap cache.
- RemoteMultimapCache people = multimapCacheManager.get(TutorialsConnectorHelper.TUTORIAL_CACHE_NAME);
- people.put(2016, "Alberto");
- people.put(2016, "Oihana");
- people.put(2016, "Roman");
- people.put(2016, "Ane");
- people.put(2017, "Paula");
- people.put(2017, "Aimar");
- people.put(2018, "Elaia");
-
- people.get(2016).whenComplete((v, ex) -> {
- System.out.println(v);
- }).join();
+ multimap = multimapCacheManager.get(TUTORIAL_CACHE_NAME);
+ }
+ public static void disconnect(boolean removeCache) {
+ if (removeCache) {
+ cacheManager.administration().removeCache(TUTORIAL_CACHE_NAME);
+ }
// Stop the cache manager and release all resources
TutorialsConnectorHelper.stop(cacheManager);
}
-
}
diff --git a/infinispan-remote/multimap/src/test/java/org/infinispan/tutorial/simple/remote/multimap/InfinispanRemoteMultimapTest.java b/infinispan-remote/multimap/src/test/java/org/infinispan/tutorial/simple/remote/multimap/InfinispanRemoteMultimapTest.java
new file mode 100644
index 00000000..f8d7a129
--- /dev/null
+++ b/infinispan-remote/multimap/src/test/java/org/infinispan/tutorial/simple/remote/multimap/InfinispanRemoteMultimapTest.java
@@ -0,0 +1,36 @@
+package org.infinispan.tutorial.simple.remote.multimap;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class InfinispanRemoteMultimapTest {
+
+ @BeforeAll
+ public static void start() {
+ InfinispanRemoteMultimap.connectToInfinispan();
+ }
+
+ @AfterAll
+ public static void stop() {
+ InfinispanRemoteMultimap.disconnect(true);
+ }
+
+ @Test
+ public void testRemoteMultimap() throws Exception {
+ assertNotNull(InfinispanRemoteMultimap.cacheManager);
+ assertNotNull(InfinispanRemoteMultimap.multimapCacheManager);
+ assertNotNull(InfinispanRemoteMultimap.multimap);
+
+ InfinispanRemoteMultimap.manipulateMultimap();
+ Collection people = InfinispanRemoteMultimap.multimap.get(2018).get(10, TimeUnit.SECONDS);
+ assertEquals(1, people.size());
+ assertEquals("Richard", people.toArray()[0]);
+ }
+}
diff --git a/infinispan-remote/near-cache/pom.xml b/infinispan-remote/near-cache/pom.xml
index 6febd0d8..b71bd214 100644
--- a/infinispan-remote/near-cache/pom.xml
+++ b/infinispan-remote/near-cache/pom.xml
@@ -46,5 +46,10 @@
org.infinispan
infinispan-client-hotrod
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
diff --git a/infinispan-remote/near-cache/src/main/java/org/infinispan/tutorial/simple/nearcache/InfinispanNearCache.java b/infinispan-remote/near-cache/src/main/java/org/infinispan/tutorial/simple/nearcache/InfinispanNearCache.java
index bbec2e24..d8e3e9b5 100644
--- a/infinispan-remote/near-cache/src/main/java/org/infinispan/tutorial/simple/nearcache/InfinispanNearCache.java
+++ b/infinispan-remote/near-cache/src/main/java/org/infinispan/tutorial/simple/nearcache/InfinispanNearCache.java
@@ -1,33 +1,27 @@
package org.infinispan.tutorial.simple.nearcache;
-import java.time.Duration;
-import java.time.Instant;
-import java.util.Random;
-
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.configuration.NearCacheMode;
import org.infinispan.tutorial.simple.connect.TutorialsConnectorHelper;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Random;
+
+import static org.infinispan.tutorial.simple.connect.TutorialsConnectorHelper.TUTORIAL_CACHE_NAME;
+
public class InfinispanNearCache {
public static final String CACHE_WITH_NEAR_CACHING = "testCacheNearCaching";
- public static void main(String[] args) {
- ConfigurationBuilder builder = TutorialsConnectorHelper.connectionConfig();
- // Add an additional cache with near caching configuration
- builder.remoteCache(CACHE_WITH_NEAR_CACHING)
- .configuration(TutorialsConnectorHelper.TUTORIAL_CACHE_CONFIG.replace("CACHE_NAME", CACHE_WITH_NEAR_CACHING))
- .nearCacheMode(NearCacheMode.INVALIDATED)
- .nearCacheMaxEntries(20)
- .nearCacheUseBloomFilter(true);
-
- // Connect to the server with the near cache configuration for the test cache
- RemoteCacheManager cacheManager = TutorialsConnectorHelper.connect(builder);
+ static RemoteCacheManager cacheManager;
+ static RemoteCache testCache;
+ static RemoteCache withNearCaching;
- RemoteCache testCache = cacheManager.getCache(TutorialsConnectorHelper.TUTORIAL_CACHE_NAME);
- RemoteCache withNearCaching = cacheManager.getCache(CACHE_WITH_NEAR_CACHING);
+ public static void main(String[] args) {
+ connectToInfinispan();
for (int i = 1; i<= 20; i++) {
testCache.put(i, String.valueOf(i));
@@ -38,11 +32,10 @@ public static void main(String[] args) {
readCache(testCache);
readCache(withNearCaching);
- // Stop the cache manager and release all resources
- cacheManager.stop();
+ disconnect(false);
}
- private static void readCache(RemoteCache cache) {
+ static void readCache(RemoteCache cache) {
Instant start = Instant.now();
Random random = new Random();
random.ints(10_000, 1, 20).forEach(num -> cache.get(num));
@@ -51,4 +44,27 @@ private static void readCache(RemoteCache cache) {
System.out.println(String.format("Time to complete with cache %s is %d milliseconds", cache.getName(), timeElapsed));
}
+ public static void connectToInfinispan() {
+ ConfigurationBuilder builder = TutorialsConnectorHelper.connectionConfig();
+ // Add an additional cache with near caching configuration
+ builder.remoteCache(CACHE_WITH_NEAR_CACHING)
+ .configuration(TutorialsConnectorHelper.TUTORIAL_CACHE_CONFIG.replace("CACHE_NAME", CACHE_WITH_NEAR_CACHING))
+ .nearCacheMode(NearCacheMode.INVALIDATED)
+ .nearCacheMaxEntries(20)
+ .nearCacheUseBloomFilter(true);
+
+ // Connect to the server with the near cache configuration for the test cache
+ cacheManager = TutorialsConnectorHelper.connect(builder);
+ testCache = cacheManager.getCache(TUTORIAL_CACHE_NAME);
+ withNearCaching = cacheManager.getCache(CACHE_WITH_NEAR_CACHING);
+ }
+
+ public static void disconnect(boolean removeCache) {
+ if (removeCache) {
+ cacheManager.administration().removeCache(TUTORIAL_CACHE_NAME);
+ cacheManager.administration().removeCache(CACHE_WITH_NEAR_CACHING);
+ }
+ // Stop the cache manager and release all resources
+ cacheManager.stop();
+ }
}
diff --git a/infinispan-remote/near-cache/src/test/java/org/infinispan/tutorial/simple/nearcache/InfinispanNearCacheTest.java b/infinispan-remote/near-cache/src/test/java/org/infinispan/tutorial/simple/nearcache/InfinispanNearCacheTest.java
new file mode 100644
index 00000000..a3b347e2
--- /dev/null
+++ b/infinispan-remote/near-cache/src/test/java/org/infinispan/tutorial/simple/nearcache/InfinispanNearCacheTest.java
@@ -0,0 +1,27 @@
+package org.infinispan.tutorial.simple.nearcache;
+
+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.assertNotNull;
+
+public class InfinispanNearCacheTest {
+
+ @BeforeAll
+ public static void start() {
+ InfinispanNearCache.connectToInfinispan();
+ }
+
+ @AfterAll
+ public static void stop() {
+ InfinispanNearCache.disconnect(true);
+ }
+
+ @Test
+ public void testNearCache() {
+ assertNotNull(InfinispanNearCache.testCache);
+ assertNotNull(InfinispanNearCache.withNearCaching);
+ }
+
+}
\ No newline at end of file
diff --git a/infinispan-remote/per-cache-configuration/pom.xml b/infinispan-remote/per-cache-configuration/pom.xml
index ef929098..b8a92663 100644
--- a/infinispan-remote/per-cache-configuration/pom.xml
+++ b/infinispan-remote/per-cache-configuration/pom.xml
@@ -44,5 +44,10 @@
org.infinispan
infinispan-client-hotrod
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
diff --git a/infinispan-remote/per-cache-configuration/src/main/java/org/infinispan/tutorial/simple/remote/percache/InfinispanRemotePerCache.java b/infinispan-remote/per-cache-configuration/src/main/java/org/infinispan/tutorial/simple/remote/percache/InfinispanRemotePerCache.java
index b99f5663..059978c3 100644
--- a/infinispan-remote/per-cache-configuration/src/main/java/org/infinispan/tutorial/simple/remote/percache/InfinispanRemotePerCache.java
+++ b/infinispan-remote/per-cache-configuration/src/main/java/org/infinispan/tutorial/simple/remote/percache/InfinispanRemotePerCache.java
@@ -21,41 +21,67 @@
public class InfinispanRemotePerCache {
+ public static final String MY_CACHE = "my-cache";
+ public static final String ANOTHER_CACHE = "another-cache";
+ public static final String URI_CACHE = "uri-cache";
+ static RemoteCacheManager cacheManager;
+ static RemoteCache cache;
+ static RemoteCache anotherCache;
+ static RemoteCache uriCache;
+
public static void main(String[] args) throws Exception {
+ connectToInfinispan();
+ manipulateCaches();
+
+ disconnect(false);
+ }
+
+ static void manipulateCaches() {
+ // Obtain a remote cache that does not exist.
+ // Rather than return null, create the cache from a template.
+ cache = cacheManager.getCache(MY_CACHE);
+ /// Store a value
+ cache.put("hello", "world");
+ // Retrieve the value and print it out
+ System.out.printf("key = %s\n", cache.get("hello"));
+
+ anotherCache = cacheManager.getCache(ANOTHER_CACHE);
+ /// Store a value
+ anotherCache.put("hello-another", "world-another");
+ // Retrieve the value and print it out
+ System.out.printf("key = %s\n", anotherCache.get("hello-another"));
+
+ uriCache = cacheManager.getCache(URI_CACHE);
+ /// Store a value
+ uriCache.put("hello-uri", "world-uri");
+ // Retrieve the value and print it out
+ System.out.printf("key = %s\n", uriCache.get("hello-uri"));
+ }
+
+ public static void connectToInfinispan() throws Exception {
// Create a configuration for a locally-running server
ConfigurationBuilder builder = TutorialsConnectorHelper.connectionConfig();
//Add per-cache configuration that uses an org.infinispan cache template.
- builder.remoteCache("my-cache")
- .templateName(DefaultTemplate.DIST_SYNC);
+ builder.remoteCache(MY_CACHE)
+ .templateName(DefaultTemplate.DIST_SYNC);
//Add per-cache configuration with a cache definition in XML format.
- builder.remoteCache("another-cache")
- .configuration("");
-
- builder.remoteCache("uri-cache").configurationURI(
- InfinispanRemotePerCache.class.getClassLoader().getResource("cacheConfig.xml").toURI());
-
- // Connect to the server
- try (RemoteCacheManager cacheManager = TutorialsConnectorHelper.connect(builder)) {
- // Obtain a remote cache that does not exist.
- // Rather than return null, create the cache from a template.
- RemoteCache cache = cacheManager.getCache("my-cache");
- /// Store a value
- cache.put("hello", "world");
- // Retrieve the value and print it out
- System.out.printf("key = %s\n", cache.get("hello"));
-
- RemoteCache anotherCache = cacheManager.getCache("another-cache");
- /// Store a value
- anotherCache.put("hello-another", "world-another");
- // Retrieve the value and print it out
- System.out.printf("key = %s\n", anotherCache.get("hello-another"));
-
- RemoteCache uriCache = cacheManager.getCache("uri-cache");
- /// Store a value
- uriCache.put("hello-uri", "world-uri");
- // Retrieve the value and print it out
- System.out.printf("key = %s\n", uriCache.get("hello-uri"));
+ builder.remoteCache(ANOTHER_CACHE)
+ .configuration("");
+
+ builder.remoteCache(URI_CACHE).configurationURI(
+ InfinispanRemotePerCache.class.getClassLoader().getResource("cacheConfig.xml").toURI());
+
+ cacheManager = TutorialsConnectorHelper.connect(builder);
+ }
+
+ public static void disconnect(boolean removeCaches) {
+ if (removeCaches) {
+ cacheManager.administration().removeCache(MY_CACHE);
+ cacheManager.administration().removeCache(ANOTHER_CACHE);
+ cacheManager.administration().removeCache(URI_CACHE);
}
+
+ TutorialsConnectorHelper.stop(cacheManager);
}
}
diff --git a/infinispan-remote/per-cache-configuration/src/test/java/org/infinispan/tutorial/simple/remote/percache/InfinispanRemotePerCacheTest.java b/infinispan-remote/per-cache-configuration/src/test/java/org/infinispan/tutorial/simple/remote/percache/InfinispanRemotePerCacheTest.java
new file mode 100644
index 00000000..0fdaa88a
--- /dev/null
+++ b/infinispan-remote/per-cache-configuration/src/test/java/org/infinispan/tutorial/simple/remote/percache/InfinispanRemotePerCacheTest.java
@@ -0,0 +1,35 @@
+package org.infinispan.tutorial.simple.remote.percache;
+
+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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+
+public class InfinispanRemotePerCacheTest {
+
+ @BeforeAll
+ public static void start() throws Exception {
+ InfinispanRemotePerCache.connectToInfinispan();
+ }
+
+ @AfterAll
+ public static void stop() {
+ InfinispanRemotePerCache.disconnect(true);
+ }
+
+ @Test
+ public void testRemotePerCacheConfiguration() {
+ assertNotNull(InfinispanRemotePerCache.cacheManager);
+ assertNull(InfinispanRemotePerCache.cache);
+ assertNull(InfinispanRemotePerCache.anotherCache);
+ assertNull(InfinispanRemotePerCache.uriCache);
+
+ InfinispanRemotePerCache.manipulateCaches();
+ assertNotNull(InfinispanRemotePerCache.cache);
+ assertNotNull(InfinispanRemotePerCache.anotherCache);
+ assertNotNull(InfinispanRemotePerCache.uriCache);
+ }
+}
\ No newline at end of file
diff --git a/infinispan-remote/query/pom.xml b/infinispan-remote/query/pom.xml
index c1ff2688..f1e03aa6 100644
--- a/infinispan-remote/query/pom.xml
+++ b/infinispan-remote/query/pom.xml
@@ -65,5 +65,10 @@
protostream-processor
${version.protostream}
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
diff --git a/infinispan-remote/query/src/main/java/org/infinispan/tutorial/simple/remote/query/InfinispanRemoteQuery.java b/infinispan-remote/query/src/main/java/org/infinispan/tutorial/simple/remote/query/InfinispanRemoteQuery.java
index b26ba206..326b4692 100644
--- a/infinispan-remote/query/src/main/java/org/infinispan/tutorial/simple/remote/query/InfinispanRemoteQuery.java
+++ b/infinispan-remote/query/src/main/java/org/infinispan/tutorial/simple/remote/query/InfinispanRemoteQuery.java
@@ -5,9 +5,6 @@
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.commons.api.query.Query;
import org.infinispan.protostream.GeneratedSchema;
-import org.infinispan.query.Search;
-import org.infinispan.query.dsl.impl.BaseQueryFactory;
-import org.infinispan.server.resp.commands.connection.SELECT;
import org.infinispan.tutorial.simple.connect.TutorialsConnectorHelper;
import java.net.URI;
@@ -28,9 +25,83 @@
public class InfinispanRemoteQuery {
public static final String INDEXED_PEOPLE_CACHE = "indexedPeopleCache";
+ static RemoteCacheManager client;
+ static RemoteCache peopleCache;
public static void main(String[] args) throws Exception {
+ connectToInfinispan();
+ addDataToCache();
+ queryAll();
+ queryWithWhereStatementOnValues();
+ queryByKey();
+ queryWithProjection();
+ deleteByQuery();
+
+ disconnect(false);
+ }
+
+ static List queryAll() {
+ // Query all
+ Query query = peopleCache.query("FROM tutorial.Person");
+ List queryResult = query.execute().list();
+ // Print the results
+ System.out.println("SIZE " + queryResult.size());
+ System.out.println(queryResult);
+ return queryResult;
+ }
+
+ static List deleteByQuery() {
+ Query query = peopleCache.query("DELETE FROM tutorial.Person p where p.key.pseudo = 'dmalfoy'");
+ System.out.println("== DELETE count:" + query.execute().count().value());
+ // Query all
+ query = peopleCache.query("FROM tutorial.Person");
+ List queryResult = query.execute().list();
+ // Print the results
+ System.out.println("SIZE " + queryResult.size());
+ System.out.println(queryResult);
+ return queryResult;
+ }
+
+ static List queryWithProjection() {
+ // Create a query with projection
+ System.out.println("== Query with key and values projection");
+ Query