Java Code Examples for org.redisson.api.RSortedSet#clear()
The following examples show how to use
org.redisson.api.RSortedSet#clear() .
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: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testTrySetComparator() { RSortedSet<Integer> set = redisson.getSortedSet("set"); boolean setRes = set.trySetComparator(Collections.reverseOrder()); Assert.assertTrue(setRes); Assert.assertTrue(set.add(1)); Assert.assertTrue(set.add(2)); Assert.assertTrue(set.add(3)); Assert.assertTrue(set.add(4)); Assert.assertTrue(set.add(5)); assertThat(set).containsExactly(5, 4, 3, 2, 1); boolean setRes2 = set.trySetComparator(Collections.reverseOrder(Collections.reverseOrder())); Assert.assertFalse(setRes2); assertThat(set).containsExactly(5, 4, 3, 2, 1); set.clear(); boolean setRes3 = set.trySetComparator(Collections.reverseOrder(Collections.reverseOrder())); Assert.assertTrue(setRes3); set.add(3); set.add(1); set.add(2); assertThat(set).containsExactly(1, 2, 3); }
Example 2
Source File: ConcurrentRedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testAdd_SingleInstance() throws InterruptedException { final String name = "testAdd_SingleInstance"; RedissonClient r = BaseTest.createInstance(); RSortedSet<Integer> map = r.getSortedSet(name); map.clear(); int length = 5000; final List<Integer> elements = new ArrayList<Integer>(); for (int i = 1; i < length + 1; i++) { elements.add(i); } Collections.shuffle(elements); final AtomicInteger counter = new AtomicInteger(-1); testSingleInstanceConcurrency(length, rc -> { RSortedSet<Integer> set = rc.getSortedSet(name); int c = counter.incrementAndGet(); Integer element = elements.get(c); Assert.assertTrue(set.add(element)); }); Collections.sort(elements); Integer[] p = elements.toArray(new Integer[elements.size()]); assertThat(map).containsExactly(p); map.clear(); r.shutdown(); }
Example 3
Source File: ConcurrentRedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testAddRemove_SingleInstance() throws InterruptedException, NoSuchAlgorithmException { final String name = "testAddNegative_SingleInstance"; RedissonClient r = BaseTest.createInstance(); RSortedSet<Integer> map = r.getSortedSet(name); map.clear(); int length = 1000; for (int i = 0; i < length; i++) { map.add(i); } final AtomicInteger counter = new AtomicInteger(length); final Random rnd = SecureRandom.getInstanceStrong(); testSingleInstanceConcurrency(length, rc -> { RSortedSet<Integer> set = rc.getSortedSet(name); int c = counter.incrementAndGet(); Assert.assertTrue(set.add(c)); set.remove(rnd.nextInt(length)); }); Assert.assertEquals(counter.get(), length*2); Integer prevVal = null; for (Integer val : map) { if (prevVal == null) { prevVal = val; continue; } if (val < prevVal) { Assert.fail(); } } r.shutdown(); }