Java Code Examples for org.redisson.api.RSetCache#add()

The following examples show how to use org.redisson.api.RSetCache#add() . 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: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testAdd() {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = transaction.getSetCache("test");
    assertThat(set.add("4")).isTrue();
    assertThat(set.add("3")).isFalse();
    assertThat(set.contains("4")).isTrue();
    
    assertThat(s.contains("4")).isFalse();
    
    transaction.commit();
    
    assertThat(s.size()).isEqualTo(3);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isTrue();
    assertThat(s.contains("4")).isTrue();
}
 
Example 2
Source File: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddTTL() throws InterruptedException {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = transaction.getSetCache("test");
    assertThat(set.add("4", 2, TimeUnit.SECONDS)).isTrue();
    assertThat(set.add("3")).isFalse();
    assertThat(set.contains("4")).isTrue();
    
    assertThat(s.contains("4")).isFalse();
    
    transaction.commit();
    
    assertThat(s.size()).isEqualTo(3);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isTrue();
    assertThat(s.contains("4")).isTrue();
    
    Thread.sleep(2000);
    
    assertThat(s.contains("4")).isFalse();
}
 
Example 3
Source File: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemove() {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = transaction.getSetCache("test");
    assertThat(set.contains("1")).isTrue();
    assertThat(set.remove("3")).isTrue();
    assertThat(set.remove("3")).isFalse();
    assertThat(set.remove("3")).isFalse();
    
    assertThat(s.contains("3")).isTrue();
    
    transaction.commit();
    
    assertThat(s.size()).isEqualTo(1);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isFalse();
}
 
Example 4
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testToArray() throws InterruptedException {
    RSetCache<String> set = redisson.getSetCache("set");
    set.add("1");
    set.add("4");
    set.add("2", 1, TimeUnit.SECONDS);
    set.add("5");
    set.add("3");

    Thread.sleep(1500);

    assertThat(set.toArray()).containsOnly("1", "4", "5", "3");

    String[] strs = set.toArray(new String[0]);
    assertThat(strs).containsOnly("1", "4", "5", "3");
    set.destroy();
}
 
Example 5
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testIteratorRemoveHighVolume() throws InterruptedException {
    RSetCache<Integer> set = redisson.getSetCache("set");
    for (int i = 1; i <= 5000; i++) {
        set.add(i);
        set.add(i*100000, 20, TimeUnit.SECONDS);
    }
    int cnt = 0;

    Iterator<Integer> iterator = set.iterator();
    while (iterator.hasNext()) {
        Integer integer = iterator.next();
        iterator.remove();
        cnt++;
    }
    Assert.assertEquals(10000, cnt);
    Assert.assertEquals(0, set.size());
    set.destroy();
}
 
Example 6
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemove() throws InterruptedException, ExecutionException {
    RSetCache<Integer> set = redisson.getSetCache("simple");
    set.add(1, 1, TimeUnit.SECONDS);
    set.add(3, 2, TimeUnit.SECONDS);
    set.add(7, 3, TimeUnit.SECONDS);

    Assert.assertTrue(set.remove(1));
    Assert.assertFalse(set.contains(1));
    assertThat(set).containsOnly(3, 7);

    Assert.assertFalse(set.remove(1));
    assertThat(set).containsOnly(3, 7);

    Assert.assertTrue(set.remove(3));
    Assert.assertFalse(set.contains(3));
    assertThat(set).containsOnly(7);
    Assert.assertEquals(1, set.size());
    set.destroy();
}
 
Example 7
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSize() {
    RSetCache<Integer> set = redisson.getSetCache("set");
    set.add(1);
    set.add(2);
    set.add(3);
    set.add(3);
    set.add(4);
    set.add(5);
    set.add(5);

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

    Thread.sleep(1000);

    assertThat(cache).contains("0", "2", "3");
    cache.destroy();
}
 
Example 9
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicates() {
    RSetCache<TestObject> set = redisson.getSetCache("set");

    set.add(new TestObject("1", "2"));
    set.add(new TestObject("1", "2"));
    set.add(new TestObject("2", "3"));
    set.add(new TestObject("3", "4"));
    set.add(new TestObject("5", "6"));

    Assert.assertEquals(4, set.size());
    set.destroy();
}
 
Example 10
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpire() throws InterruptedException {
    RSetCache<String> cache = redisson.getSetCache("simple");
    cache.add("8", 1, TimeUnit.SECONDS);

    cache.expire(100, TimeUnit.MILLISECONDS);

    Thread.sleep(500);

    Assert.assertEquals(0, cache.size());
    cache.destroy();
}
 
Example 11
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsAll() {
    RSetCache<Integer> set = redisson.getSetCache("set");
    for (int i = 0; i < 200; i++) {
        set.add(i);
    }

    Assert.assertTrue(set.containsAll(Collections.emptyList()));
    Assert.assertTrue(set.containsAll(Arrays.asList(30, 11)));
    Assert.assertFalse(set.containsAll(Arrays.asList(30, 711, 11)));
    set.destroy();
}
 
Example 12
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetainAll() throws InterruptedException {
    RSetCache<Integer> set = redisson.getSetCache("set");
    for (int i = 0; i < 10000; i++) {
        set.add(i);
        set.add(i*10, 15, TimeUnit.SECONDS);
    }

    Assert.assertTrue(set.retainAll(Arrays.asList(1, 2)));
    Thread.sleep(500);
    assertThat(set).containsOnly(1, 2);
    Assert.assertEquals(2, set.size());
    set.destroy();
}
 
Example 13
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testIteratorSequence() {
    RSetCache<Long> set = redisson.getSetCache("set");
    for (int i = 0; i < 1000; i++) {
        set.add(Long.valueOf(i));
    }

    Set<Long> setCopy = new HashSet<Long>();
    for (int i = 0; i < 1000; i++) {
        setCopy.add(Long.valueOf(i));
    }

    checkIterator(set, setCopy);
    set.destroy();
}
 
Example 14
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearExpire() throws InterruptedException {
    RSetCache<String> cache = redisson.getSetCache("simple");
    cache.add("8", 1, TimeUnit.SECONDS);

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

    cache.clearExpire();

    Thread.sleep(500);

    Assert.assertEquals(1, cache.size());
    cache.destroy();
}
 
Example 15
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddBigBean() {
    RSetCache<Map<Integer, Integer>> set = redisson.getSetCache("simple");
    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (int i = 0; i < 150; i++) {
        map.put(i, i);
    }
    set.add(map);
    map.remove(0);
    set.add(map);
    set.iterator().next();
    set.destroy();
}
 
Example 16
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelete() {
    RSetCache<Integer> set = redisson.getSetCache("set");
    assertThat(set.delete()).isFalse();
    set.add(1, 1, TimeUnit.SECONDS);
    assertThat(set.delete()).isTrue();
    assertThat(set.delete()).isFalse();
    set.destroy();
}
 
Example 17
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveAll() {
    RSetCache<Integer> set = redisson.getSetCache("set");
    set.add(1);
    set.add(2, 10, TimeUnit.SECONDS);
    set.add(3);
    
    assertThat(set.removeAll(Arrays.asList(1, 3))).isTrue();
    assertThat(set.removeAll(Arrays.asList(1, 3))).isFalse();
    assertThat(set).containsOnly(2);
    set.destroy();
}
 
Example 18
Source File: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeySet() {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = t.getSetCache("test");
    set.remove("3");
    assertThat(set).containsOnly("1");
    
    assertThat(s).containsOnly("1", "3");
}
 
Example 19
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetainAllEmpty() {
    RSetCache<Integer> set = redisson.getSetCache("set");
    set.add(1);
    set.add(2);
    set.add(3);
    set.add(4);
    set.add(5);

    Assert.assertTrue(set.retainAll(Collections.<Integer>emptyList()));
    Assert.assertEquals(0, set.size());
    set.destroy();
}
 
Example 20
Source File: RedissonSetCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadAllExpired() throws InterruptedException {
    RSetCache<Integer> set = redisson.getSetCache("set");
    set.add(1, 1, TimeUnit.SECONDS);
    Thread.sleep(1005);
    assertThat(set.readAll()).isEmpty();
    set.destroy();
}