org.redisson.api.LocalCachedMapOptions Java Examples
The following examples show how to use
org.redisson.api.LocalCachedMapOptions.
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: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testLFU() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.<String, Integer>defaults().evictionPolicy(EvictionPolicy.LFU).cacheSize(5)); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); map.put("14", 2); map.put("15", 3); map.put("16", 4); map.put("17", 5); map.put("18", 6); assertThat(cache.size()).isEqualTo(5); assertThat(map.size()).isEqualTo(6); assertThat(map.keySet()).containsOnly("12", "14", "15", "16", "17", "18"); assertThat(map.values()).containsOnly(1, 2, 3, 4, 5, 6); }
Example #2
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
public void execute() throws InterruptedException { LocalCachedMapOptions<String, Integer> options = LocalCachedMapOptions.<String, Integer>defaults().evictionPolicy(EvictionPolicy.LFU).cacheSize(5); map1 = redisson.getLocalCachedMap("test", options); cache1 = map1.getCachedMap(); map2 = redisson.getLocalCachedMap("test", options); cache2 = map2.getCachedMap(); map1.put("1", 1); map1.put("2", 2); assertThat(map2.get("1")).isEqualTo(1); assertThat(map2.get("2")).isEqualTo(2); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); test(); }
Example #3
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
public void execute() throws InterruptedException { LocalCachedMapOptions<String, Integer> options = LocalCachedMapOptions.<String, Integer>defaults().evictionPolicy(EvictionPolicy.LFU) .syncStrategy(SyncStrategy.UPDATE) .reconnectionStrategy(ReconnectionStrategy.CLEAR) .cacheSize(5); map1 = redisson.getLocalCachedMap("test2", options); cache1 = map1.getCachedMap(); map2 = redisson.getLocalCachedMap("test2", options); cache2 = map2.getCachedMap(); map1.put("1", 1); map1.put("2", 2); Thread.sleep(50); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); test(); }
Example #4
Source File: RedissonTransactionalLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testRollback() { RLocalCachedMap<String, String> m1 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); m1.put("1", "2"); m1.put("3", "4"); RLocalCachedMap<String, String> m2 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); m2.get("1"); m2.get("3"); RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults()); RMap<String, String> map = transaction.getLocalCachedMap(m1); assertThat(map.get("1")).isEqualTo("2"); assertThat(map.remove("3")).isEqualTo("4"); assertThat(m1.get("3")).isEqualTo("4"); transaction.rollback(); assertThat(redisson.getKeys().count()).isEqualTo(1); assertThat(m1.get("1")).isEqualTo("2"); assertThat(m1.get("3")).isEqualTo("4"); assertThat(m2.get("1")).isEqualTo("2"); assertThat(m2.get("3")).isEqualTo("4"); }
Example #5
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testPutGetCache() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); map.put("14", 2); map.put("15", 3); assertThat(cache).containsValues(1, 2, 3); assertThat(map.get("12")).isEqualTo(1); assertThat(map.get("14")).isEqualTo(2); assertThat(map.get("15")).isEqualTo(3); RLocalCachedMap<String, Integer> map1 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); assertThat(map1.get("12")).isEqualTo(1); assertThat(map1.get("14")).isEqualTo(2); assertThat(map1.get("15")).isEqualTo(3); }
Example #6
Source File: RedissonTransactionalLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testPut() throws InterruptedException { RLocalCachedMap<String, String> m1 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); m1.put("1", "2"); m1.put("3", "4"); RLocalCachedMap<String, String> m2 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); m2.get("1"); m2.get("3"); RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults()); RMap<String, String> map = transaction.getLocalCachedMap(m1); assertThat(map.put("3", "5")).isEqualTo("4"); assertThat(map.get("3")).isEqualTo("5"); assertThat(m1.get("3")).isEqualTo("4"); assertThat(m2.get("3")).isEqualTo("4"); transaction.commit(); assertThat(m1.get("3")).isEqualTo("5"); assertThat(m2.get("3")).isEqualTo("5"); }
Example #7
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testGetAllCache() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("getAll", LocalCachedMapOptions.defaults()); Map<String, Integer> cache = map.getCachedMap(); map.put("1", 100); map.put("2", 200); map.put("3", 300); map.put("4", 400); assertThat(cache.size()).isEqualTo(4); Map<String, Integer> filtered = map.getAll(new HashSet<String>(Arrays.asList("2", "3", "5"))); Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("2", 200); expectedMap.put("3", 300); assertThat(filtered).isEqualTo(expectedMap); RMap<String, Integer> map1 = redisson.getLocalCachedMap("getAll", LocalCachedMapOptions.defaults()); Map<String, Integer> filtered1 = map1.getAll(new HashSet<String>(Arrays.asList("2", "3", "5"))); assertThat(filtered1).isEqualTo(expectedMap); }
Example #8
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testLRU() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.<String, Integer>defaults().evictionPolicy(EvictionPolicy.LRU).cacheSize(5)); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); map.put("14", 2); map.put("15", 3); map.put("16", 4); map.put("17", 5); map.put("18", 6); assertThat(cache.size()).isEqualTo(5); assertThat(map.size()).isEqualTo(6); assertThat(map.keySet()).containsOnly("12", "14", "15", "16", "17", "18"); assertThat(map.values()).containsOnly(1, 2, 3, 4, 5, 6); }
Example #9
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testFastPutIfAbsent() throws Exception { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); SimpleKey key = new SimpleKey("1"); SimpleValue value = new SimpleValue("2"); map.put(key, value); assertThat(map.fastPutIfAbsent(key, new SimpleValue("3"))).isFalse(); assertThat(cache.size()).isEqualTo(1); assertThat(map.get(key)).isEqualTo(value); SimpleKey key1 = new SimpleKey("2"); SimpleValue value1 = new SimpleValue("4"); assertThat(map.fastPutIfAbsent(key1, value1)).isTrue(); assertThat(cache.size()).isEqualTo(2); assertThat(map.get(key1)).isEqualTo(value1); }
Example #10
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testReadAllEntrySet() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); map.put(new SimpleKey("33"), new SimpleValue("44")); map.put(new SimpleKey("5"), new SimpleValue("6")); assertThat(map.readAllEntrySet().size()).isEqualTo(3); assertThat(cache.size()).isEqualTo(3); Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map); assertThat(map.readAllEntrySet()).containsOnlyElementsOf(testMap.entrySet()); RMap<SimpleKey, SimpleValue> map2 = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); assertThat(map2.readAllEntrySet()).containsOnlyElementsOf(testMap.entrySet()); }
Example #11
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testPutIfAbsent() throws Exception { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); SimpleKey key = new SimpleKey("1"); SimpleValue value = new SimpleValue("2"); map.put(key, value); Assert.assertEquals(value, map.putIfAbsent(key, new SimpleValue("3"))); Assert.assertEquals(value, map.get(key)); SimpleKey key1 = new SimpleKey("2"); SimpleValue value1 = new SimpleValue("4"); Assert.assertNull(map.putIfAbsent(key1, value1)); Assert.assertEquals(value1, map.get(key1)); assertThat(cache.size()).isEqualTo(2); }
Example #12
Source File: RedissonLocalCachedMap.java From redisson with Apache License 2.0 | 6 votes |
@Override public RFuture<V> getAsync(Object key) { checkKey(key); CacheKey cacheKey = toCacheKey(key); CacheValue cacheValue = cache.get(cacheKey); if (cacheValue != null && cacheValue.getValue() != null) { return RedissonPromise.newSucceededFuture((V) cacheValue.getValue()); } if (storeMode == LocalCachedMapOptions.StoreMode.LOCALCACHE) { return RedissonPromise.newSucceededFuture(null); } RFuture<V> future = super.getAsync((K) key); future.onComplete((value, e) -> { if (e != null) { return; } if (value != null) { cachePut(cacheKey, key, value); } }); return future; }
Example #13
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testRemoveValueFail() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); boolean res = map.remove(new SimpleKey("2"), new SimpleValue("1")); Assert.assertFalse(res); boolean res1 = map.remove(new SimpleKey("1"), new SimpleValue("3")); Assert.assertFalse(res1); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertEquals("2", val1.getValue()); assertThat(cache.size()).isEqualTo(1); }
Example #14
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testReplaceOldValueSuccess() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); boolean res = map.replace(new SimpleKey("1"), new SimpleValue("2"), new SimpleValue("3")); Assert.assertTrue(res); boolean res1 = map.replace(new SimpleKey("1"), new SimpleValue("2"), new SimpleValue("3")); Assert.assertFalse(res1); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertEquals("3", val1.getValue()); assertThat(cache.size()).isEqualTo(1); }
Example #15
Source File: RedissonLocalCachedMap.java From redisson with Apache License 2.0 | 6 votes |
private void broadcastLocalCacheStore(V value, ByteBuf mapKey, CacheKey cacheKey) { if (storeMode != LocalCachedMapOptions.StoreMode.LOCALCACHE) { return; } if (invalidateEntryOnChange != 0) { Object msg; if (syncStrategy == SyncStrategy.UPDATE) { ByteBuf mapValue = encodeMapValue(value); msg = new LocalCachedMapUpdate(mapKey, mapValue); } else { msg = new LocalCachedMapInvalidate(instanceId, cacheKey.getKeyHash()); } listener.getInvalidationTopic().publishAsync(msg); } mapKey.release(); }
Example #16
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testReadAllValues() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); map.put(new SimpleKey("33"), new SimpleValue("44")); map.put(new SimpleKey("5"), new SimpleValue("6")); assertThat(cache.size()).isEqualTo(3); assertThat(map.readAllValues().size()).isEqualTo(3); Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map); assertThat(map.readAllValues()).containsOnlyElementsOf(testMap.values()); RMap<SimpleKey, SimpleValue> map2 = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); assertThat(map2.readAllValues()).containsOnlyElementsOf(testMap.values()); }
Example #17
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testReadValuesAndEntries() { RLocalCachedMap<Object, Object> m = redisson.getLocalCachedMap("testValuesWithNearCache2", LocalCachedMapOptions.defaults()); m.clear(); m.put("a", 1); m.put("b", 2); m.put("c", 3); Set<Integer> expectedValuesSet = new HashSet<>(); expectedValuesSet.add(1); expectedValuesSet.add(2); expectedValuesSet.add(3); Set<Object> actualValuesSet = new HashSet<>(m.readAllValues()); Assert.assertEquals(expectedValuesSet, actualValuesSet); Map<String, Integer> expectedMap = new HashMap<>(); expectedMap.put("a", 1); expectedMap.put("b", 2); expectedMap.put("c", 3); Assert.assertEquals(expectedMap.entrySet(), m.readAllEntrySet()); }
Example #18
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testInvalidationOnUpdateNonBinaryCodec() throws InterruptedException { LocalCachedMapOptions<String, String> options = LocalCachedMapOptions.<String, String>defaults().evictionPolicy(EvictionPolicy.LFU).cacheSize(5); RLocalCachedMap<String, String> map1 = redisson.getLocalCachedMap("test", new StringCodec(), options); Map<String, String> cache1 = map1.getCachedMap(); RLocalCachedMap<String, String> map2 = redisson.getLocalCachedMap("test", new StringCodec(), options); Map<String, String> cache2 = map2.getCachedMap(); map1.put("1", "1"); map1.put("2", "2"); assertThat(map2.get("1")).isEqualTo("1"); assertThat(map2.get("2")).isEqualTo("2"); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); map1.put("1", "3"); map2.put("2", "4"); Thread.sleep(50); assertThat(cache1.size()).isEqualTo(1); assertThat(cache2.size()).isEqualTo(1); }
Example #19
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testAddAndGet() throws InterruptedException { RLocalCachedMap<Integer, Integer> map = redisson.getLocalCachedMap("getAll", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE), LocalCachedMapOptions.defaults()); Map<Integer, Integer> cache = map.getCachedMap(); map.put(1, 100); Integer res = map.addAndGet(1, 12); assertThat(cache.size()).isEqualTo(1); assertThat(res).isEqualTo(112); res = map.get(1); assertThat(res).isEqualTo(112); RMap<Integer, Double> map2 = redisson.getLocalCachedMap("getAll2", new CompositeCodec(redisson.getConfig().getCodec(), DoubleCodec.INSTANCE), LocalCachedMapOptions.defaults()); map2.put(1, new Double(100.2)); Double res2 = map2.addAndGet(1, new Double(12.1)); assertThat(res2).isEqualTo(112.3); res2 = map2.get(1); assertThat(res2).isEqualTo(112.3); RMap<String, Integer> mapStr = redisson.getLocalCachedMap("mapStr", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE), LocalCachedMapOptions.defaults()); assertThat(mapStr.put("1", 100)).isNull(); assertThat(mapStr.addAndGet("1", 12)).isEqualTo(112); assertThat(mapStr.get("1")).isEqualTo(112); assertThat(cache.size()).isEqualTo(1); }
Example #20
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testNoInvalidationOnRemove() throws InterruptedException { LocalCachedMapOptions<String, Integer> options = LocalCachedMapOptions.<String, Integer>defaults() .evictionPolicy(EvictionPolicy.LFU) .cacheSize(5) .syncStrategy(SyncStrategy.NONE); RLocalCachedMap<String, Integer> map1 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache1 = map1.getCachedMap(); RLocalCachedMap<String, Integer> map2 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache2 = map2.getCachedMap(); map1.put("1", 1); map1.put("2", 2); assertThat(map2.get("1")).isEqualTo(1); assertThat(map2.get("2")).isEqualTo(2); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); map1.remove("1"); map2.remove("2"); Thread.sleep(50); assertThat(cache1.size()).isEqualTo(1); assertThat(cache2.size()).isEqualTo(1); }
Example #21
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testSizeCache() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); map.put("14", 2); map.put("15", 3); assertThat(cache.size()).isEqualTo(3); assertThat(map.size()).isEqualTo(3); }
Example #22
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testLocalCacheClear() throws InterruptedException { LocalCachedMapOptions<String, Integer> options = LocalCachedMapOptions.<String, Integer>defaults() .evictionPolicy(EvictionPolicy.LFU) .cacheSize(5) .syncStrategy(SyncStrategy.INVALIDATE); RLocalCachedMap<String, Integer> map1 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache1 = map1.getCachedMap(); RLocalCachedMap<String, Integer> map2 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache2 = map2.getCachedMap(); map1.put("1", 1); map1.put("2", 2); assertThat(map2.get("1")).isEqualTo(1); assertThat(map2.get("2")).isEqualTo(2); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); map1.clearLocalCache(); assertThat(redisson.getKeys().count()).isEqualTo(1); assertThat(cache1.size()).isZero(); assertThat(cache2.size()).isZero(); }
Example #23
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testLocalCacheState() throws InterruptedException { LocalCachedMapOptions<String, String> options = LocalCachedMapOptions.<String, String>defaults() .evictionPolicy(EvictionPolicy.LFU) .cacheSize(5) .syncStrategy(SyncStrategy.INVALIDATE); RLocalCachedMap<String, String> map = redisson.getLocalCachedMap("test", options); map.put("1", "11"); map.put("2", "22"); assertThat(map.cachedKeySet()).containsExactlyInAnyOrder("1", "2"); assertThat(map.cachedValues()).containsExactlyInAnyOrder("11", "22"); assertThat(map.getCachedMap().keySet()).containsExactlyInAnyOrder("1", "2"); assertThat(map.getCachedMap().values()).containsExactlyInAnyOrder("11", "22"); }
Example #24
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testNoInvalidationOnUpdate() throws InterruptedException { LocalCachedMapOptions<String, Integer> options = LocalCachedMapOptions.<String, Integer>defaults() .evictionPolicy(EvictionPolicy.LFU) .cacheSize(5) .syncStrategy(SyncStrategy.NONE); RLocalCachedMap<String, Integer> map1 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache1 = map1.getCachedMap(); RLocalCachedMap<String, Integer> map2 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache2 = map2.getCachedMap(); map1.put("1", 1); map1.put("2", 2); assertThat(map2.get("1")).isEqualTo(1); assertThat(map2.get("2")).isEqualTo(2); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); map1.put("1", 3); map2.put("2", 4); Thread.sleep(50); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); }
Example #25
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testPutAllCache() throws InterruptedException { RLocalCachedMap<Integer, String> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); RLocalCachedMap<Integer, String> map1 = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<Integer, String> cache = map.getCachedMap(); Map<Integer, String> cache1 = map1.getCachedMap(); map.put(1, "1"); map.put(2, "2"); map.put(3, "3"); Map<Integer, String> joinMap = new HashMap<Integer, String>(); joinMap.put(4, "4"); joinMap.put(5, "5"); joinMap.put(6, "6"); map.putAll(joinMap); assertThat(cache.size()).isEqualTo(6); assertThat(cache1.size()).isEqualTo(0); assertThat(map.keySet()).containsOnly(1, 2, 3, 4, 5, 6); map1.putAll(joinMap); // waiting for cache cleanup listeners triggering Thread.sleep(500); assertThat(cache.size()).isEqualTo(3); assertThat(cache1.size()).isEqualTo(3); }
Example #26
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testBigPutAll() throws InterruptedException { RLocalCachedMap<Object, Object> m = redisson.getLocalCachedMap("testValuesWithNearCache2", LocalCachedMapOptions.defaults().evictionPolicy(EvictionPolicy.LFU).syncStrategy(SyncStrategy.INVALIDATE)); Map<Object, Object> map = new HashMap<>(); for (int k = 0; k < 10000; k++) { map.put("" + k, "" + k); } m.putAll(map); assertThat(m.size()).isEqualTo(10000); }
Example #27
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testRemoveValue() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); boolean res = map.remove(new SimpleKey("1"), new SimpleValue("2")); Assert.assertTrue(res); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertNull(val1); Assert.assertEquals(0, map.size()); assertThat(cache.size()).isEqualTo(0); }
Example #28
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testReplaceOldValueFail() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); boolean res = map.replace(new SimpleKey("1"), new SimpleValue("43"), new SimpleValue("31")); Assert.assertFalse(res); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertEquals("2", val1.getValue()); assertThat(cache.size()).isEqualTo(1); }
Example #29
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testReplaceValue() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); SimpleValue res = map.replace(new SimpleKey("1"), new SimpleValue("3")); Assert.assertEquals("2", res.getValue()); assertThat(cache.size()).isEqualTo(1); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertEquals("3", val1.getValue()); }
Example #30
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testRemove() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); assertThat(cache.size()).isEqualTo(1); assertThat(map.remove("12")).isEqualTo(1); assertThat(cache.size()).isEqualTo(0); assertThat(map.remove("14")).isNull(); }