Java Code Examples for org.infinispan.Cache#putForExternalRead()
The following examples show how to use
org.infinispan.Cache#putForExternalRead() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConcurrencyVersioningTest.java From keycloak with Apache License 2.0 | 6 votes |
/** * Tests that if remove executes before put, then put still succeeds. * * @throws Exception */ @Test public void testGetRemovePutOnNonExisting() throws Exception { final DefaultCacheManager cacheManager = getVersionedCacheManager(); ExecutorService executor = Executors.newSingleThreadExecutor(); RemoveThread removeThread = new RemoveThread(cacheManager); Cache<String, String> cache = cacheManager.getCache(InfinispanConnectionProvider.REALM_CACHE_NAME); cache.remove("key"); startBatch(cache); cache.get("key"); executor.execute(removeThread); removeThread.getLatch().await(); cache.putForExternalRead("key", "value1"); endBatch(cache); Assert.assertEquals(cache.get("key"), "value1"); Assert.assertTrue(removeThread.isSuccess()); }
Example 2
Source File: ConcurrencyVersioningTest.java From keycloak with Apache License 2.0 | 6 votes |
/** * Test that if a put of an existing key is removed after the put and before tx commit, it is evicted * * @throws Exception */ @Test public void testGetRemovePutEternalOnExisting() throws Exception { final DefaultCacheManager cacheManager = getVersionedCacheManager(); ExecutorService executor = Executors.newSingleThreadExecutor(); RemoveThread removeThread = new RemoveThread(cacheManager); Cache<String, String> cache = cacheManager.getCache(InfinispanConnectionProvider.REALM_CACHE_NAME); cache.put("key", "value0"); startBatch(cache); cache.get("key"); executor.execute(removeThread); cache.putForExternalRead("key", "value1"); removeThread.getLatch().await(); try { endBatch(cache); // Assert.fail("Write skew should be detected"); } catch (Exception e) { } Assert.assertNull(cache.get("key")); Assert.assertTrue(removeThread.isSuccess()); }
Example 3
Source File: ConcurrencyVersioningTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test public void testPutExternalRemoveOnExisting() throws Exception { final DefaultCacheManager cacheManager = getVersionedCacheManager(); ExecutorService executor = Executors.newSingleThreadExecutor(); RemoveThread removeThread = new RemoveThread(cacheManager); Cache<String, String> cache = cacheManager.getCache(InfinispanConnectionProvider.REALM_CACHE_NAME); cache.put("key", "value0"); startBatch(cache); cache.putForExternalRead("key", "value1"); executor.execute(removeThread); removeThread.getLatch().await(); try { endBatch(cache); // Assert.fail("Write skew should be detected"); } catch (Exception e) { } Assert.assertNull(cache.get("key")); Assert.assertTrue(removeThread.isSuccess()); }
Example 4
Source File: InvalidationMode.java From infinispan-simple-tutorials with Apache License 2.0 | 5 votes |
private static void putForExternalReadKeyValue(Scanner scanner, Cache<String, String> cache) { System.out.println("# pe - Put for external read key/value \n"); String key = readUserInput("Enter a key: ", scanner); System.out.println("\n"); String value = readUserInput("Enter a value: ", scanner); //Put for external read won't invalidate the value if it's present in another node. cache.putForExternalRead(key, value); System.out.println(String.format("[%s, %s] added for external read", key, value)); }
Example 5
Source File: ConcurrencyVersioningTest.java From keycloak with Apache License 2.0 | 5 votes |
public void run() { Cache<String, String> cache = cacheManager.getCache(InfinispanConnectionProvider.REALM_CACHE_NAME); try { startBatch(cache); cache.putForExternalRead("key", "value2"); //cache.getAdvancedCache().getTransactionManager().commit(); endBatch(cache); success = true; } catch (Exception e) { success = false; } latch.countDown(); }
Example 6
Source File: ClusteredCacheBehaviorTest.java From keycloak with Apache License 2.0 | 4 votes |
@Test public void testListener() throws Exception { EmbeddedCacheManager node1 = createManager(); EmbeddedCacheManager node2 = createManager(); Cache<String, Object> node1Cache = node1.getCache(InfinispanConnectionProvider.REALM_CACHE_NAME); node1Cache.addListener(new CacheListener("node1")); Cache<String, Object> node2Cache = node2.getCache(InfinispanConnectionProvider.REALM_CACHE_NAME); node2Cache.addListener(new CacheListener("node2")); System.out.println("node1 create entry"); node1Cache.put("key", "node1"); System.out.println("node1 create entry"); node1Cache.put("key", "node111"); System.out.println("node2 create entry"); node2Cache.put("key", "node2"); System.out.println("node1 remove entry"); node1Cache.remove("key"); System.out.println("node2 remove entry"); node2Cache.remove("key"); System.out.println("node2 put entry"); node2Cache.put("key", "node2"); System.out.println("node2 evict entry"); node2Cache.evict("key"); System.out.println("node1/node2 putExternal entry"); node1Cache.putForExternalRead("key", "common"); node2Cache.putForExternalRead("key", "common"); System.out.println("node2 remove entry"); node2Cache.remove("key"); System.out.println("node1 remove entry"); node1Cache.remove("key"); // test remove non-existing node 2, existing node 1 System.out.println("Test non existent remove"); System.out.println("node1 create entry"); node1Cache.put("key", "value"); System.out.println("node2 remove non-existent entry"); System.out.println("exists?: " + node2Cache.containsKey("key")); node2Cache.remove("key"); // test clear System.out.println("Test clear cache"); System.out.println("add key to node 1, key2 to node2"); node1Cache.putForExternalRead("key", "value"); node2Cache.putForExternalRead("key", "value"); node2Cache.putForExternalRead("key2", "value"); System.out.println("Clear from node1"); node1Cache.clear(); System.out.println("node 2 exists key2?: " + node2Cache.containsKey("key2")); System.out.println("node 2 exists key?: " + node2Cache.containsKey("key")); }