org.redisson.api.RBlockingDeque Java Examples
The following examples show how to use
org.redisson.api.RBlockingDeque.
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: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testTakeLastAwait() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getBlockingDeque("queue:take"); Executors.newSingleThreadScheduledExecutor().schedule(() -> { RBlockingDeque<Integer> deque1 = redisson.getBlockingDeque("queue:take"); try { deque1.putFirst(1); deque1.putFirst(2); deque1.putLast(3); deque1.putLast(4); }catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }, 10, TimeUnit.SECONDS); long s = System.currentTimeMillis(); assertThat(deque.takeLast()).isEqualTo(1); assertThat(System.currentTimeMillis() - s).isGreaterThan(9000); Thread.sleep(50); assertThat(deque.takeLast()).isEqualTo(4); assertThat(deque.takeLast()).isEqualTo(3); assertThat(deque.takeLast()).isEqualTo(2); }
Example #2
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testTakeFirstAwait() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getBlockingDeque("queue:take"); Executors.newSingleThreadScheduledExecutor().schedule(() -> { RBlockingDeque<Integer> deque1 = redisson.getBlockingDeque("queue:take"); try { deque1.putFirst(1); deque1.putFirst(2); deque1.putLast(3); deque1.putLast(4); }catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }, 10, TimeUnit.SECONDS); long s = System.currentTimeMillis(); assertThat(deque.takeFirst()).isEqualTo(1); assertThat(System.currentTimeMillis() - s).isGreaterThan(9000); Thread.sleep(50); assertThat(deque.takeFirst()).isEqualTo(2); assertThat(deque.takeFirst()).isEqualTo(3); assertThat(deque.takeFirst()).isEqualTo(4); }
Example #3
Source File: RedissonPriorityBlockingDequeTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testTakeFirstAwait() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getPriorityBlockingDeque("queue:take"); Executors.newSingleThreadScheduledExecutor().schedule(() -> { RBlockingDeque<Integer> deque1 = redisson.getBlockingDeque("queue:take"); deque1.add(1); deque1.add(2); deque1.add(3); deque1.add(4); }, 10, TimeUnit.SECONDS); long s = System.currentTimeMillis(); assertThat(deque.takeFirst()).isEqualTo(1); assertThat(System.currentTimeMillis() - s).isGreaterThan(9000); Thread.sleep(50); assertThat(deque.takeFirst()).isEqualTo(2); assertThat(deque.takeFirst()).isEqualTo(3); assertThat(deque.takeFirst()).isEqualTo(4); }
Example #4
Source File: RedissonPriorityBlockingDequeTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testTakeLastAwait() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getPriorityBlockingDeque("queue:take"); Executors.newSingleThreadScheduledExecutor().schedule(() -> { RBlockingDeque<Integer> deque1 = redisson.getBlockingDeque("queue:take"); deque1.add(1); deque1.add(2); deque1.add(3); deque1.add(4); }, 10, TimeUnit.SECONDS); long s = System.currentTimeMillis(); assertThat(deque.takeLast()).isEqualTo(4); assertThat(System.currentTimeMillis() - s).isGreaterThan(9000); Thread.sleep(50); assertThat(deque.takeLast()).isEqualTo(3); assertThat(deque.takeLast()).isEqualTo(2); assertThat(deque.takeLast()).isEqualTo(1); }
Example #5
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testPollLastFromAny() throws InterruptedException { final RBlockingDeque<Integer> queue1 = redisson.getBlockingDeque("deque:pollany"); Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() { @Override public void run() { RBlockingDeque<Integer> queue2 = redisson.getBlockingDeque("deque:pollany1"); RBlockingDeque<Integer> queue3 = redisson.getBlockingDeque("deque:pollany2"); try { queue3.put(2); queue1.put(1); queue2.put(3); } catch (InterruptedException e) { Assert.fail(); } } }, 3, TimeUnit.SECONDS); long s = System.currentTimeMillis(); int l = queue1.pollLastFromAny(4, TimeUnit.SECONDS, "deque:pollany1", "deque:pollany2"); assertThat(l).isEqualTo(2); assertThat(System.currentTimeMillis() - s).isGreaterThan(2000); }
Example #6
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testPollLastAndOfferFirstTo() throws InterruptedException { RBlockingDeque<String> blockingDeque = redisson.getBlockingDeque("blocking_deque"); long start = System.currentTimeMillis(); String redisTask = blockingDeque.pollLastAndOfferFirstTo("deque", 1, TimeUnit.SECONDS); assertThat(System.currentTimeMillis() - start).isBetween(950L, 1100L); assertThat(redisTask).isNull(); }
Example #7
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testPollLast() throws InterruptedException { RBlockingDeque<Integer> queue1 = redisson.getBlockingDeque("queue1"); queue1.putLast(1); queue1.putLast(2); queue1.putLast(3); assertThat(queue1.pollLast(2, TimeUnit.SECONDS)).isEqualTo(3); assertThat(queue1.pollLast(2, TimeUnit.SECONDS)).isEqualTo(2); assertThat(queue1.pollLast(2, TimeUnit.SECONDS)).isEqualTo(1); long s = System.currentTimeMillis(); assertThat(queue1.pollLast(5, TimeUnit.SECONDS)).isNull(); assertThat(System.currentTimeMillis() - s).isGreaterThan(5000); }
Example #8
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testPollFirst() throws InterruptedException { RBlockingDeque<Integer> queue1 = redisson.getBlockingDeque("queue1"); queue1.put(1); queue1.put(2); queue1.put(3); assertThat(queue1.pollFirst(2, TimeUnit.SECONDS)).isEqualTo(1); assertThat(queue1.pollFirst(2, TimeUnit.SECONDS)).isEqualTo(2); assertThat(queue1.pollFirst(2, TimeUnit.SECONDS)).isEqualTo(3); long s = System.currentTimeMillis(); assertThat(queue1.pollFirst(5, TimeUnit.SECONDS)).isNull(); assertThat(System.currentTimeMillis() - s).isGreaterThan(5000); }
Example #9
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testTakeLast() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getBlockingDeque("queue:take"); deque.offerFirst(1); deque.offerFirst(2); deque.offerLast(3); deque.offerLast(4); assertThat(deque.takeLast()).isEqualTo(4); assertThat(deque.takeLast()).isEqualTo(3); assertThat(deque.takeLast()).isEqualTo(1); assertThat(deque.takeLast()).isEqualTo(2); assertThat(deque.size()).isZero(); }
Example #10
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testTakeFirst() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getBlockingDeque("queue:take"); deque.offerFirst(1); deque.offerFirst(2); deque.offerLast(3); deque.offerLast(4); assertThat(deque.takeFirst()).isEqualTo(2); assertThat(deque.takeFirst()).isEqualTo(1); assertThat(deque.takeFirst()).isEqualTo(3); assertThat(deque.takeFirst()).isEqualTo(4); assertThat(deque.size()).isZero(); }
Example #11
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testOfferFirstLast() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getBlockingDeque("deque"); deque.offerFirst(1); deque.offerFirst(2); deque.offerLast(3); deque.offerLast(4); assertThat(deque).containsExactly(2, 1, 3, 4); }
Example #12
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testFirstLast() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getBlockingDeque("deque"); deque.putFirst(1); deque.putFirst(2); deque.putLast(3); deque.putLast(4); assertThat(deque).containsExactly(2, 1, 3, 4); }
Example #13
Source File: RedissonPriorityBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testPollLast() throws InterruptedException { RBlockingDeque<Integer> queue1 = redisson.getPriorityBlockingDeque("queue1"); queue1.add(3); queue1.add(1); queue1.add(2); assertThat(queue1.pollLast(2, TimeUnit.SECONDS)).isEqualTo(3); assertThat(queue1.pollLast(2, TimeUnit.SECONDS)).isEqualTo(2); assertThat(queue1.pollLast(2, TimeUnit.SECONDS)).isEqualTo(1); long s = System.currentTimeMillis(); assertThat(queue1.pollLast(5, TimeUnit.SECONDS)).isNull(); assertThat(System.currentTimeMillis() - s).isGreaterThanOrEqualTo(5000); }
Example #14
Source File: RedissonPriorityBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testPollFirst() throws InterruptedException { RBlockingDeque<Integer> queue1 = redisson.getPriorityBlockingDeque("queue1"); queue1.put(1); queue1.put(2); queue1.put(3); assertThat(queue1.pollFirst(2, TimeUnit.SECONDS)).isEqualTo(1); assertThat(queue1.pollFirst(2, TimeUnit.SECONDS)).isEqualTo(2); assertThat(queue1.pollFirst(2, TimeUnit.SECONDS)).isEqualTo(3); long s = System.currentTimeMillis(); assertThat(queue1.pollFirst(5, TimeUnit.SECONDS)).isNull(); assertThat(System.currentTimeMillis() - s).isGreaterThan(4900); }
Example #15
Source File: RedissonPriorityBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testTakeLast() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getPriorityBlockingDeque("queue:take"); deque.add(1); deque.add(2); deque.add(3); deque.add(4); assertThat(deque.takeLast()).isEqualTo(4); assertThat(deque.takeLast()).isEqualTo(3); assertThat(deque.takeLast()).isEqualTo(2); assertThat(deque.takeLast()).isEqualTo(1); assertThat(deque.size()).isZero(); }
Example #16
Source File: RedissonPriorityBlockingDequeTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testTakeFirst() throws InterruptedException { RBlockingDeque<Integer> deque = redisson.getPriorityBlockingDeque("queue:take"); deque.add(1); deque.add(2); deque.add(3); deque.add(4); assertThat(deque.takeFirst()).isEqualTo(1); assertThat(deque.takeFirst()).isEqualTo(2); assertThat(deque.takeFirst()).isEqualTo(3); assertThat(deque.takeFirst()).isEqualTo(4); assertThat(deque.size()).isZero(); }
Example #17
Source File: RedissonBlockingDequeTest.java From redisson with Apache License 2.0 | 4 votes |
@Test(timeout = 3000) public void testShortPoll() throws InterruptedException { RBlockingDeque<Integer> queue = redisson.getBlockingDeque("queue:pollany"); queue.pollLastAsync(500, TimeUnit.MILLISECONDS); queue.pollFirstAsync(10, TimeUnit.MICROSECONDS); }
Example #18
Source File: TracingRBlockingDeque.java From java-redis-client with Apache License 2.0 | 4 votes |
public TracingRBlockingDeque(RBlockingDeque<V> deque, TracingRedissonHelper tracingRedissonHelper) { super(deque, tracingRedissonHelper); this.deque = deque; this.tracingRedissonHelper = tracingRedissonHelper; }
Example #19
Source File: RedissonPriorityBlockingDequeTest.java From redisson with Apache License 2.0 | 4 votes |
@Test(timeout = 3000) public void testShortPoll() throws InterruptedException { RBlockingDeque<Integer> queue = redisson.getPriorityBlockingDeque("queue:pollany"); queue.pollLastAsync(500, TimeUnit.MILLISECONDS); queue.pollFirstAsync(10, TimeUnit.MICROSECONDS); }
Example #20
Source File: BlockingDequeExamples.java From redisson-examples with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws InterruptedException { // connects to 127.0.0.1:6379 by default RedissonClient redisson = Redisson.create(); RBlockingDeque<String> deque = redisson.getBlockingDeque("myQueue"); deque.add("1"); deque.add("2"); deque.add("3"); deque.add("4"); deque.contains("1"); deque.peek(); deque.poll(); deque.element(); for (String string : deque) { // iteration through bulk loaded values } boolean removedValue = deque.remove("1"); deque.removeAll(Arrays.asList("1", "2", "3")); deque.containsAll(Arrays.asList("4", "1", "0")); List<String> secondList = new ArrayList<>(); secondList.add("4"); secondList.add("5"); deque.addAll(secondList); RQueue<String> secondQueue = redisson.getQueue("mySecondQueue"); deque.pollLastAndOfferFirstTo(secondQueue.getName()); deque.addLast("8"); deque.addFirst("9"); deque.addLast("30"); deque.addFirst("80"); String firstValue = deque.pollFirst(); String lastValue = deque.pollLast(); String peekFirstValue = deque.peekFirst(); String peekLastValue = deque.peekLast(); String firstRemoved = deque.removeFirst(); String lastRemoved = deque.removeLast(); Thread t = new Thread(() -> { try { String element1 = deque.poll(10, TimeUnit.SECONDS); String element2 = deque.take(); String element3 = deque.pollFirst(3, TimeUnit.SECONDS); String element4 = deque.pollLast(3, TimeUnit.SECONDS); String element5 = deque.takeFirst(); String element6 = deque.takeLast(); String element7 = deque.pollLastAndOfferFirstTo(secondQueue.getName(), 4, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } }); t.start(); t.join(); redisson.shutdown(); }
Example #21
Source File: TracingRedissonClient.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public <V> RBlockingDeque<V> getBlockingDeque(String name, Codec codec) { return new TracingRBlockingDeque<>(redissonClient.getBlockingDeque(name, codec), tracingRedissonHelper); }
Example #22
Source File: TracingRedissonClient.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public <V> RBlockingDeque<V> getBlockingDeque(String name) { return new TracingRBlockingDeque<>(redissonClient.getBlockingDeque(name), tracingRedissonHelper); }