Java Code Examples for org.redisson.api.RMap#replace()

The following examples show how to use org.redisson.api.RMap#replace() . 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: BaseMapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceOldValueFail() {
    RMap<SimpleKey, SimpleValue> map = getMap("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());
    destroy(map);
}
 
Example 2
Source File: BaseMapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceOldValueSuccess() {
    RMap<SimpleKey, SimpleValue> map = getMap("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());
    destroy(map);
}
 
Example 3
Source File: BaseMapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceValue() {
    RMap<SimpleKey, SimpleValue> map = getMap("simple");
    map.put(new SimpleKey("1"), new SimpleValue("2"));

    SimpleValue res = map.replace(new SimpleKey("1"), new SimpleValue("3"));
    Assert.assertEquals("2", res.getValue());

    SimpleValue val1 = map.get(new SimpleKey("1"));
    Assert.assertEquals("3", val1.getValue());
    destroy(map);
}
 
Example 4
Source File: BaseMapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriterReplaceKeyValue() {
    Map<String, String> store = new HashMap<>();
    RMap<String, String> map = getWriterTestMap("test", store);

    map.put("1", "11");
    map.replace("1", "00");
    map.replace("2", "22");
    map.put("3", "33");
    
    Map<String, String> expected = new HashMap<>();
    expected.put("1", "00");
    expected.put("3", "33");
    assertThat(store).isEqualTo(expected);
}
 
Example 5
Source File: BaseMapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriterReplaceKeyOldNewValue() {
    Map<String, String> store = new HashMap<>();
    RMap<String, String> map = getWriterTestMap("test", store);

    map.put("1", "11");
    map.replace("1", "11", "00");
    map.put("3", "33");
    
    Map<String, String> expected = new HashMap<>();
    expected.put("1", "00");
    expected.put("3", "33");
    assertThat(store).isEqualTo(expected);
    destroy(map);
}
 
Example 6
Source File: TimeoutTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
public void testReplaceTimeout() throws InterruptedException, ExecutionException {
    RMap<Integer, Integer> map = redisson.getMap("simple");
    for (int i = 0; i < 1000; i++) {
        map.put(i, i * 1000);
        map.replace(i, i * 1000 + 1);
        Thread.sleep(1000);
        System.out.println(i);
    }

    for (int i = 0; i < 1000; i++) {
        Integer r = map.get(i);
        System.out.println(r);
    }
}