Java Code Examples for org.redisson.api.RMapCache#destroy()

The following examples show how to use org.redisson.api.RMapCache#destroy() . 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: RedissonMapCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testValues() throws InterruptedException {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple05");
    map.put(new SimpleKey("33"), new SimpleValue("44"), 1, TimeUnit.SECONDS);
    map.put(new SimpleKey("1"), new SimpleValue("2"));

    Assert.assertTrue(map.values().contains(new SimpleValue("44")));
    Assert.assertFalse(map.values().contains(new SimpleValue("33")));
    Assert.assertTrue(map.values().contains(new SimpleValue("2")));

    Thread.sleep(1000);

    Assert.assertFalse(map.values().contains(new SimpleValue("44")));
    Assert.assertFalse(map.values().contains(new SimpleValue("33")));
    Assert.assertTrue(map.values().contains(new SimpleValue("2")));
    map.destroy();
}
 
Example 2
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testFastPutIfAbsentTTL() throws Exception {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple");
    SimpleKey key = new SimpleKey("1");
    SimpleValue value = new SimpleValue("2");
    map.put(key, value);
    assertThat(map.fastPutIfAbsent(key, new SimpleValue("3"))).isFalse();
    assertThat(map.get(key)).isEqualTo(value);

    SimpleKey key1 = new SimpleKey("2");
    SimpleValue value1 = new SimpleValue("4");
    assertThat(map.fastPutIfAbsent(key1, value1)).isTrue();
    assertThat(map.get(key1)).isEqualTo(value1);
    
    SimpleKey key2 = new SimpleKey("3");
    map.put(key2, new SimpleValue("31"), 500, TimeUnit.MILLISECONDS);
    assertThat(map.fastPutIfAbsent(key2, new SimpleValue("32"))).isFalse();
    
    Thread.sleep(500);
    assertThat(map.fastPutIfAbsent(key2, new SimpleValue("32"))).isTrue();
    assertThat(map.get(key2)).isEqualTo(new SimpleValue("32"));
    map.destroy();

}
 
Example 3
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreatedListener() {
    RMapCache<Integer, Integer> map = redisson.getMapCache("simple");
    
    checkCreatedListener(map, 1, 2, () -> map.put(1, 2));
    checkCreatedListener(map, 10, 2, () -> map.put(10, 2, 2, TimeUnit.SECONDS));
    checkCreatedListener(map, 2, 5, () -> map.fastPut(2, 5));
    checkCreatedListener(map, 13, 2, () -> map.fastPut(13, 2, 2, TimeUnit.SECONDS));
    checkCreatedListener(map, 3, 2, () -> map.putIfAbsent(3, 2));
    checkCreatedListener(map, 14, 2, () -> map.putIfAbsent(14, 2, 2, TimeUnit.SECONDS));
    checkCreatedListener(map, 4, 1, () -> map.fastPutIfAbsent(4, 1));
    checkCreatedListener(map, 15, 2, () -> map.fastPutIfAbsent(15, 2, 2, TimeUnit.SECONDS));
    map.destroy();
    
    RMapCache<Integer, Integer> map2 = redisson.getMapCache("simple3", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
    checkCreatedListener(map2, 5, 10, () -> map2.addAndGet(5, 10));
    map2.destroy();
}
 
Example 4
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsValueTTL() throws InterruptedException {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple01");
    Assert.assertFalse(map.containsValue(new SimpleValue("34")));
    map.put(new SimpleKey("33"), new SimpleValue("44"), 1, TimeUnit.SECONDS);

    Assert.assertTrue(map.containsValue(new SimpleValue("44")));
    Assert.assertFalse(map.containsValue(new SimpleValue("34")));

    Thread.sleep(1000);

    Assert.assertFalse(map.containsValue(new SimpleValue("44")));
    map.destroy();
}
 
Example 5
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadAllEntrySet() throws InterruptedException {
    RMapCache<Integer, String> map = redisson.getMapCache("simple12");
    map.put(1, "12");
    map.put(2, "33", 10, TimeUnit.MINUTES, 60, TimeUnit.MINUTES);
    map.put(3, "43");
    
    assertThat(map.readAllEntrySet()).isEqualTo(map.entrySet());
    map.destroy();
}
 
Example 6
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testValuesByPatternTTL() {
    RMapCache<String, String> map = redisson.getMapCache("simple", StringCodec.INSTANCE);
    map.put("10", "100");
    map.put("20", "200", 1, TimeUnit.MINUTES);
    map.put("30", "300");

    assertThat(map.values("?0")).containsExactly("100", "200", "300");
    assertThat(map.values("1")).isEmpty();
    assertThat(map.values("10")).containsExactly("100");
    map.destroy();
}
 
Example 7
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeySetByPatternTTL() {
    RMapCache<String, String> map = redisson.getMapCache("simple", StringCodec.INSTANCE);
    map.put("10", "100");
    map.put("20", "200", 1, TimeUnit.MINUTES);
    map.put("30", "300");

    assertThat(map.keySet("?0")).containsExactly("10", "20", "30");
    assertThat(map.keySet("1")).isEmpty();
    assertThat(map.keySet("10")).containsExactly("10");
    map.destroy();
}
 
Example 8
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceOldValueSuccess() {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple");
    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());
    map.destroy();
}
 
Example 9
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntrySet() throws InterruptedException {
    RMapCache<Integer, String> map = redisson.getMapCache("simple12");
    map.put(1, "12");
    map.put(2, "33", 1, TimeUnit.SECONDS);
    map.put(3, "43");

    Map<Integer, String> expected = new HashMap<>();
    map.put(1, "12");
    map.put(3, "43");
    
    assertThat(map.entrySet()).containsAll(expected.entrySet());
    assertThat(map).hasSize(3);
    map.destroy();
}
 
Example 10
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearExpire() throws InterruptedException {
    RMapCache<String, String> cache = redisson.getMapCache("simple");
    cache.put("0", "8", 1, TimeUnit.SECONDS);

    cache.expireAt(System.currentTimeMillis() + 100);

    cache.clearExpire();

    Thread.sleep(500);

    Assert.assertEquals(1, cache.size());
    cache.destroy();
}
 
Example 11
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpiredIterator() throws InterruptedException {
    RMapCache<String, String> cache = redisson.getMapCache("simple");
    cache.put("0", "8");
    cache.put("1", "6", 1, TimeUnit.SECONDS);
    cache.put("2", "4", 3, TimeUnit.SECONDS);
    cache.put("3", "2", 4, TimeUnit.SECONDS);
    cache.put("4", "4", 1, TimeUnit.SECONDS);

    Thread.sleep(1000);

    assertThat(cache.keySet()).containsOnly("0", "2", "3");
    cache.destroy();
}
 
Example 12
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveValueFail() {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple");
    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());
    map.destroy();
}
 
Example 13
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemovedListener() {
    RMapCache<Integer, Integer> map = redisson.getMapCache("simple");

    map.put(1, 1);
    checkRemovedListener(map, 1, 1, () -> map.remove(1, 1));
    
    map.put(10, 1);
    checkRemovedListener(map, 10, 1, () -> map.remove(10));
    
    map.put(2, 1);
    checkRemovedListener(map, 2, 1, () -> map.fastRemove(2));
    map.destroy();
}
 
Example 14
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceValueTTL() throws InterruptedException {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple");
    map.put(new SimpleKey("1"), new SimpleValue("2"), 1, TimeUnit.SECONDS);

    Thread.sleep(1000);
    
    SimpleValue res = map.replace(new SimpleKey("1"), new SimpleValue("3"));
    assertThat(res).isNull();

    SimpleValue val1 = map.get(new SimpleKey("1"));
    assertThat(val1).isNull();
    map.destroy();
}
 
Example 15
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRMapCacheValues() {
    final RMapCache<String, String> map = redisson.getMapCache("testRMapCacheValues");
    map.put("1234", "5678", 1, TimeUnit.MINUTES, 60, TimeUnit.MINUTES);
    assertThat(map.values()).containsOnly("5678");
    map.destroy();
}
 
Example 16
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriterFastPutIfAbsentTTL() {
    Map<String, String> store = new HashMap<>();
    RMapCache<String, String> map = (RMapCache<String, String>) getWriterTestMap("test", store);

    map.fastPutIfAbsent("1", "11", 10, TimeUnit.SECONDS);
    map.fastPutIfAbsent("1", "00", 10, TimeUnit.SECONDS);
    map.fastPutIfAbsent("2", "22", 10, TimeUnit.SECONDS);
    
    Map<String, String> expected = new HashMap<>();
    expected.put("1", "11");
    expected.put("2", "22");
    assertThat(store).isEqualTo(expected);
    map.destroy();
}
 
Example 17
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceOldValueFail() {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple");
    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());
    map.destroy();
}
 
Example 18
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriterPutIfAbsentTTL() {
    Map<String, String> store = new HashMap<>();
    RMapCache<String, String> map = (RMapCache<String, String>) getWriterTestMap("test", store);

    map.putIfAbsent("1", "11", 10, TimeUnit.SECONDS);
    map.putIfAbsent("1", "00", 10, TimeUnit.SECONDS);
    map.putIfAbsent("2", "22", 10, TimeUnit.SECONDS);
    
    Map<String, String> expected = new HashMap<>();
    expected.put("1", "11");
    expected.put("2", "22");
    assertThat(store).isEqualTo(expected);
    map.destroy();
}
 
Example 19
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutAllGetTTL() throws InterruptedException {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple06");
    Assert.assertNull(map.get(new SimpleKey("33")));
    Assert.assertNull(map.get(new SimpleKey("55")));

    Map<SimpleKey, SimpleValue> entries = new HashMap<>();
    entries.put(new SimpleKey("33"), new SimpleValue("44"));
    entries.put(new SimpleKey("55"), new SimpleValue("66"));
    map.putAll(entries, 2, TimeUnit.SECONDS);

    SimpleValue val1 = map.get(new SimpleKey("33"));
    Assert.assertEquals("44", val1.getValue());
    SimpleValue val2 = map.get(new SimpleKey("55"));
    Assert.assertEquals("66", val2.getValue());

    Thread.sleep(1000);

    Assert.assertEquals(2, map.size());
    SimpleValue val3 = map.get(new SimpleKey("33"));
    Assert.assertEquals("44", val3.getValue());
    SimpleValue val4 = map.get(new SimpleKey("55"));
    Assert.assertEquals("66", val4.getValue());
    Assert.assertEquals(2, map.size());

    Thread.sleep(1000);

    Assert.assertNull(map.get(new SimpleKey("33")));
    Assert.assertNull(map.get(new SimpleKey("55")));
    map.destroy();
}
 
Example 20
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testRemoveValueTTL() throws InterruptedException {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("simple");
    map.put(new SimpleKey("1"), new SimpleValue("2"), 1, TimeUnit.SECONDS);

    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());
    
    map.put(new SimpleKey("3"), new SimpleValue("4"), 1, TimeUnit.SECONDS);

    Thread.sleep(1000);
    
    assertThat(map.remove(new SimpleKey("3"), new SimpleValue("4"))).isFalse();

    assertThat(map.get(new SimpleKey("3"))).isNull();
    map.destroy();
}