org.redisson.api.RBlockingQueue Java Examples

The following examples show how to use org.redisson.api.RBlockingQueue. 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: FileConverQueueTask.java    From kkFileViewOfficeEdit with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    while (true) {
        try {
            final RBlockingQueue<String> queue = redissonClient.getBlockingQueue(FileConverQueueTask.queueTaskName);
            String url = queue.take();
            if(url!=null){
                FileAttribute fileAttribute=fileUtils.getFileAttribute(url);
                logger.info("正在处理转换任务,文件名称【{}】",fileAttribute.getName());
                FileType fileType=fileAttribute.getType();
                if(fileType.equals(FileType.compress) || fileType.equals(FileType.office)){
                    FilePreview filePreview=previewFactory.get(url);
                    filePreview.filePreviewHandle(url,new ExtendedModelMap());
                }
            }
        } catch (Exception e) {
            try {
                Thread.sleep(1000*10);
            }catch (Exception ex){
                ex.printStackTrace();
            }
            e.printStackTrace();
        }
    }
}
 
Example #2
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPollWithBrokenConnection() throws IOException, InterruptedException, ExecutionException {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .randomPort()
            .run();
    
    Config config = new Config();
    config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    final RBlockingQueue<Integer> queue1 = getQueue(redisson);
    RFuture<Integer> f = queue1.pollAsync(5, TimeUnit.SECONDS);
    
    Assert.assertFalse(f.await(1, TimeUnit.SECONDS));
    runner.stop();

    long start = System.currentTimeMillis();
    assertThat(f.get()).isNull();
    assertThat(System.currentTimeMillis() - start).isGreaterThan(3800);
    
    redisson.shutdown();
}
 
Example #3
Source File: RedissonDelayedQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAll() throws InterruptedException {
    RBlockingQueue<String> blockingFairQueue = redisson.getBlockingQueue("delay_queue");
    RDelayedQueue<String> delayedQueue = redisson.getDelayedQueue(blockingFairQueue);
    
    delayedQueue.offer("1_1_1", 3, TimeUnit.SECONDS);
    delayedQueue.offer("1_1_2", 7, TimeUnit.SECONDS);
    assertThat(delayedQueue.contains("1_1_1")).isTrue();
    assertThat(delayedQueue.contains("1_1_2")).isTrue();
    assertThat(delayedQueue.removeAll(Arrays.asList("1_1_1", "1_1_2"))).isTrue();
    assertThat(delayedQueue.contains("1_1_1")).isFalse();
    assertThat(delayedQueue.contains("1_1_2")).isFalse();
    
    Thread.sleep(9000);
    
    assertThat(blockingFairQueue.isEmpty()).isTrue();
}
 
Example #4
Source File: RedissonDelayedQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDealyedQueueRetainAll() {
    RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("test");
    RDelayedQueue<Integer> dealyedQueue = redisson.getDelayedQueue(queue1);
    dealyedQueue.offer(3, 5, TimeUnit.SECONDS);
    dealyedQueue.offer(1, 2, TimeUnit.SECONDS);
    dealyedQueue.offer(2, 1, TimeUnit.SECONDS);

    assertThat(dealyedQueue.retainAll(Arrays.asList(1, 2, 3))).isFalse();
    assertThat(dealyedQueue.retainAll(Arrays.asList(3, 1, 2, 8))).isFalse();
    assertThat(dealyedQueue.readAll()).containsExactly(3, 1, 2);
    
    assertThat(dealyedQueue.retainAll(Arrays.asList(1, 2))).isTrue();
    assertThat(dealyedQueue.readAll()).containsExactly(1, 2);
    
    dealyedQueue.destroy();
}
 
Example #5
Source File: RedissonPriorityBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDrainToCollectionLimited() throws Exception {
    RBlockingQueue<Integer> queue1 = getQueue();
    queue1.put(1);
    queue1.put(2);
    queue1.put(3);

    ArrayList<Object> dst = new ArrayList<Object>();
    queue1.drainTo(dst, 2);
    assertThat(dst).containsExactly(1, 2);
    Assert.assertEquals(1, queue1.size());

    dst.clear();
    queue1.drainTo(dst, 2);
    assertThat(dst).containsExactly(3);
}
 
Example #6
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubscribeOnElements() throws InterruptedException {
    RBlockingQueue<Integer> q = redisson.getBlockingQueue("test");
    Set<Integer> values = new HashSet<>();
    int listnerId = q.subscribeOnElements(v -> {
        values.add(v);
    });

    for (int i = 0; i < 10; i++) {
        q.add(i);
    }

    Awaitility.await().atMost(Duration.ONE_SECOND).until(() -> {
        return values.size() == 10;
    });

    q.unsubscribe(listnerId);

    q.add(11);
    q.add(12);

    Thread.sleep(1000);

    assertThat(values).hasSize(10);
}
 
Example #7
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTakeInterrupted() throws InterruptedException {
    final AtomicBoolean interrupted = new AtomicBoolean();
    
    Thread t = new Thread() {
        public void run() {
            try {
                RBlockingQueue<Integer> queue1 = getQueue(redisson);
                queue1.take();
            } catch (InterruptedException e) {
                interrupted.set(true);
            }
        };
    };

    t.start();
    t.join(1000);

    t.interrupt();
    Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(interrupted);

    RBlockingQueue<Integer> q = getQueue(redisson);
    q.add(1);
    Thread.sleep(1000);
    assertThat(q.contains(1)).isTrue();
}
 
Example #8
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPollInterrupted() throws InterruptedException {
    final AtomicBoolean interrupted = new AtomicBoolean();
    
    Thread t = new Thread() {
        public void run() {
            try {
                RBlockingQueue<Integer> queue1 = getQueue(redisson);
                queue1.poll(10, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                interrupted.set(true);
            }
        };
    };
    
    t.start();
    t.join(1000);
    
    t.interrupt();
    Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(interrupted);
}
 
Example #9
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTakeAsyncCancel() {
    Config config = createConfig();
    config.useSingleServer().setConnectionMinimumIdleSize(1).setConnectionPoolSize(1);

    RedissonClient redisson = Redisson.create(config);
    RBlockingQueue<Integer> queue1 = getQueue(redisson);
    for (int i = 0; i < 10; i++) {
        RFuture<Integer> f = queue1.takeAsync();
        f.cancel(true);
    }
    assertThat(queue1.add(1)).isTrue();
    assertThat(queue1.add(2)).isTrue();
    assertThat(queue1.size()).isEqualTo(2);
    
    redisson.shutdown();
}
 
Example #10
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPollAsyncCancel() {
    Config config = createConfig();
    config.useSingleServer().setConnectionMinimumIdleSize(1).setConnectionPoolSize(1);

    RedissonClient redisson = Redisson.create(config);
    RBlockingQueue<Integer> queue1 = getQueue(redisson);
    for (int i = 0; i < 10; i++) {
        RFuture<Integer> f = queue1.pollAsync(1, TimeUnit.SECONDS);
        f.cancel(true);
    }
    assertThat(queue1.add(1)).isTrue();
    assertThat(queue1.add(2)).isTrue();
    assertThat(queue1.size()).isEqualTo(2);
    
    redisson.shutdown();
}
 
Example #11
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDrainToCollectionLimited() throws Exception {
    RBlockingQueue<Object> queue1 = getQueue();
    queue1.put(1);
    queue1.put(2L);
    queue1.put("e");

    ArrayList<Object> dst = new ArrayList<Object>();
    queue1.drainTo(dst, 2);
    assertThat(dst).containsExactly(1, 2L);
    Assert.assertEquals(1, queue1.size());

    dst.clear();
    queue1.drainTo(dst, 2);
    assertThat(dst).containsExactly("e");
}
 
Example #12
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPollFromAny() throws InterruptedException {
    final RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollany");
    Executors.newSingleThreadScheduledExecutor().schedule(() -> {
        RBlockingQueue<Integer> queue2 = redisson.getBlockingQueue("queue:pollany1");
        RBlockingQueue<Integer> queue3 = redisson.getBlockingQueue("queue: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.pollFromAny(4, TimeUnit.SECONDS, "queue:pollany1", "queue:pollany2");

    Assert.assertEquals(2, l);
    Assert.assertTrue(System.currentTimeMillis() - s > 2000);
}
 
Example #13
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTake() throws InterruptedException {
    RBlockingQueue<Integer> queue1 = getQueue();
    Executors.newSingleThreadScheduledExecutor().schedule(() -> {
        RBlockingQueue<Integer> queue = getQueue();
        try {
            queue.put(3);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }, 10, TimeUnit.SECONDS);

    long s = System.currentTimeMillis();
    int l = queue1.take();

    Assert.assertEquals(3, l);
    Assert.assertTrue(System.currentTimeMillis() - s > 9000);
}
 
Example #14
Source File: RedissonDelayedQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDealyedQueuePollLastAndOfferFirstTo() {
    RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("test");
    RDelayedQueue<Integer> dealyedQueue = redisson.getDelayedQueue(queue1);
    
    dealyedQueue.offer(3, 5, TimeUnit.SECONDS);
    dealyedQueue.offer(2, 2, TimeUnit.SECONDS);
    dealyedQueue.offer(1, 1, TimeUnit.SECONDS);

    RQueue<Integer> queue2 = redisson.getQueue("deque2");
    queue2.offer(6);
    queue2.offer(5);
    queue2.offer(4);

    assertThat(dealyedQueue.pollLastAndOfferFirstTo(queue2.getName())).isEqualTo(1);
    assertThat(queue2).containsExactly(1, 6, 5, 4);
    
    dealyedQueue.destroy();
}
 
Example #15
Source File: RedissonDelayedQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDelayedQueueOrder() {
    RBlockingQueue<String> queue = redisson.getBlockingQueue("test");
    RDelayedQueue<String> dealyedQueue = redisson.getDelayedQueue(queue);
    
    dealyedQueue.offer("1", 1, TimeUnit.SECONDS);
    dealyedQueue.offer("4", 4, TimeUnit.SECONDS);
    dealyedQueue.offer("3", 3, TimeUnit.SECONDS);
    dealyedQueue.offer("2", 2, TimeUnit.SECONDS);
    
    assertThat(dealyedQueue).containsExactly("1", "4", "3", "2");
    
    assertThat(dealyedQueue.poll()).isEqualTo("1");
    assertThat(dealyedQueue.poll()).isEqualTo("4");
    assertThat(dealyedQueue.poll()).isEqualTo("3");
    assertThat(dealyedQueue.poll()).isEqualTo("2");
    
    assertThat(queue.isEmpty()).isTrue();
    
    assertThat(queue.poll()).isNull();
    
    dealyedQueue.destroy();
}
 
Example #16
Source File: RedissonDelayedQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPollLimited() throws InterruptedException {
    RBlockingQueue<String> queue = redisson.getBlockingQueue("test");
    RDelayedQueue<String> dealyedQueue = redisson.getDelayedQueue(queue);

    dealyedQueue.offer("1", 1, TimeUnit.SECONDS);
    dealyedQueue.offer("2", 2, TimeUnit.SECONDS);
    dealyedQueue.offer("3", 3, TimeUnit.SECONDS);
    dealyedQueue.offer("4", 4, TimeUnit.SECONDS);

    assertThat(dealyedQueue.poll(3)).containsExactly("1", "2", "3");
    assertThat(dealyedQueue.poll(2)).containsExactly("4");
    assertThat(dealyedQueue.poll(2)).isEmpty();

    Thread.sleep(3000);
    assertThat(queue.isEmpty()).isTrue();

    assertThat(queue.poll()).isNull();
    assertThat(queue.poll()).isNull();

    dealyedQueue.destroy();
}
 
Example #17
Source File: RedissonDelayedQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPoll() throws InterruptedException {
    RBlockingQueue<String> queue = redisson.getBlockingQueue("test");
    RDelayedQueue<String> dealyedQueue = redisson.getDelayedQueue(queue);
    
    dealyedQueue.offer("1", 1, TimeUnit.SECONDS);
    dealyedQueue.offer("2", 2, TimeUnit.SECONDS);
    dealyedQueue.offer("3", 3, TimeUnit.SECONDS);
    dealyedQueue.offer("4", 4, TimeUnit.SECONDS);
    
    assertThat(dealyedQueue.poll()).isEqualTo("1");
    assertThat(dealyedQueue.poll()).isEqualTo("2");
    assertThat(dealyedQueue.poll()).isEqualTo("3");
    assertThat(dealyedQueue.poll()).isEqualTo("4");
    
    Thread.sleep(3000);
    assertThat(queue.isEmpty()).isTrue();
    
    assertThat(queue.poll()).isNull();
    assertThat(queue.poll()).isNull();
    
    dealyedQueue.destroy();
}
 
Example #18
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPollLastAndOfferFirstTo() throws InterruptedException {
    final RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("{queue}1");
    Executors.newSingleThreadScheduledExecutor().schedule(() -> {
        try {
            queue1.put(3);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }, 5, TimeUnit.SECONDS);

    RBlockingQueue<Integer> queue2 = redisson.getBlockingQueue("{queue}2");
    queue2.put(4);
    queue2.put(5);
    queue2.put(6);

    Integer value = queue1.pollLastAndOfferFirstTo(queue2.getName(), 5, TimeUnit.SECONDS);
    assertThat(value).isEqualTo(3);
    assertThat(queue2).containsExactly(3, 4, 5, 6);
}
 
Example #19
Source File: RedisQueueEventChannel.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public void registerMonitor(Set<Class> types, EventMonitor monitor) {
    for (Class type : types) {
        EventManager manager = managers.get(type);
        if (manager == null) {
            manager = new EventManager();
            managers.put(type, manager);
            // TODO 需要防止路径冲突
            RBlockingQueue<byte[]> events = getQueue(type);
            EventThread thread = new EventThread(type, manager, events);
            thread.start();
            threads.put(type, thread);
        }
        manager.attachMonitor(monitor);
    }
}
 
Example #20
Source File: SendMessage.java    From Almost-Famous with MIT License 6 votes vote down vote up
public void send(long rid, Resoult resoult) {
        String key = KeyPrefix.GameCoreRedisPrefix.ROLE_MESSAGE_QUEUE + rid;
//        RLock lock = redissonClient.getFairLock(key);
        try {
//            boolean isLock = lock.tryLock(300, 500, TimeUnit.MILLISECONDS);
//            if (isLock) {
            RBlockingQueue<Resoult> queue = redissonClient.getBlockingQueue(key);
            if (null == queue) {
                return;
            }
            queue.offer(resoult);
//            }
        } catch (Exception e) {
            log.error("SendMessage:", e);
        } finally {
//            lock.unlock();
        }
    }
 
Example #21
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDrainTo() {
    RBlockingQueue<Integer> queue = getQueue();
    for (int i = 0 ; i < 100; i++) {
        queue.offer(i);
    }
    Assert.assertEquals(100, queue.size());
    Set<Integer> batch = new HashSet<Integer>();
    int count = queue.drainTo(batch, 10);
    Assert.assertEquals(10, count);
    Assert.assertEquals(10, batch.size());
    Assert.assertEquals(90, queue.size());
    queue.drainTo(batch, 10);
    queue.drainTo(batch, 20);
    queue.drainTo(batch, 60);
    Assert.assertEquals(0, queue.size());
}
 
Example #22
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTakeLastAndOfferFirstTo() throws InterruptedException {
    final RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("{queue}1");
    Executors.newSingleThreadScheduledExecutor().schedule(() -> {
        try {
            queue1.put(3);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }, 3, TimeUnit.SECONDS);

    RBlockingQueue<Integer> queue2 = redisson.getBlockingQueue("{queue}2");
    queue2.put(4);
    queue2.put(5);
    queue2.put(6);

    long startTime = System.currentTimeMillis();
    Integer value = queue1.takeLastAndOfferFirstTo(queue2.getName());
    assertThat(System.currentTimeMillis() - startTime).isBetween(2900L, 3200L);
    assertThat(value).isEqualTo(3);
    assertThat(queue2).containsExactly(3, 4, 5, 6);
}
 
Example #23
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testTakeReattach() throws Exception {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .randomPort()
            .run();
    
    Config config = new Config();
    config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);

    RBlockingQueue<Integer> queue1 = getQueue(redisson);
    RFuture<Integer> f = queue1.takeAsync();
    f.await(1, TimeUnit.SECONDS);
    runner.stop();

    runner = new RedisRunner()
            .port(runner.getRedisServerPort())
            .nosave()
            .randomDir()
            .run();
    queue1.put(123);
    
    // check connection rotation
    for (int i = 0; i < 10; i++) {
        queue1.put(i + 10000);
    }
    assertThat(queue1.size()).isEqualTo(10);
    
    Integer result = f.get(1, TimeUnit.SECONDS);
    assertThat(result).isEqualTo(123);
    runner.stop();
    
    redisson.shutdown();
}
 
Example #24
Source File: DefaultRedisQueue.java    From SeimiCrawler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean push(Request req) {
    try {
        RBlockingQueue<Request> rBlockingQueue = getQueue(req.getCrawlerName());
        rBlockingQueue.put(req);
        return true;
    } catch (Exception e) {
        logger.warn(e.getMessage());
    }
    return false;
}
 
Example #25
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testDrainToCollection() throws Exception {
    RBlockingQueue<Object> queue1 = getQueue();
    queue1.put(1);
    queue1.put(2L);
    queue1.put("e");

    ArrayList<Object> dst = new ArrayList<Object>();
    queue1.drainTo(dst);
    assertThat(dst).containsExactly(1, 2L, "e");
    Assert.assertEquals(0, queue1.size());
}
 
Example #26
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testDrainToSingle() {
    RBlockingQueue<Integer> queue = getQueue();
    Assert.assertTrue(queue.add(1));
    Assert.assertEquals(1, queue.size());
    Set<Integer> batch = new HashSet<Integer>();
    int count = queue.drainTo(batch);
    Assert.assertEquals(1, count);
    Assert.assertEquals(1, batch.size());
    Assert.assertTrue(queue.isEmpty());
}
 
Example #27
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPollAsyncReattach() throws InterruptedException, IOException, ExecutionException, TimeoutException {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .randomPort()
            .run();
    
    Config config = new Config();
    config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    
    RBlockingQueue<Integer> queue1 = getQueue(redisson);
    RFuture<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
    f.await(1, TimeUnit.SECONDS);
    runner.stop();

    runner = new RedisRunner()
            .port(runner.getRedisServerPort())
            .nosave()
            .randomDir()
            .run();
    queue1.put(123);
    
    // check connection rotation
    for (int i = 0; i < 10; i++) {
        queue1.put(i);
    }
    assertThat(queue1.size()).isEqualTo(10);
    
    Integer result = f.get(1, TimeUnit.SECONDS);
    assertThat(result).isEqualTo(123);
    
    redisson.shutdown();
    runner.stop();
}
 
Example #28
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleCharAsKeyName() {
    String value = "Long Test Message;Long Test Message;Long Test Message;"
            + "Long Test Message;Long Test Message;Long Test Message;Long "
            + "Test Message;Long Test Message;Long Test Message;Long Test "
            + "Message;Long Test Message;Long Test Message;Long Test Messa"
            + "ge;Long Test Message;Long Test Message;Long Test Message;Lo"
            + "ng Test Message;Long Test Message;Long Test Message;Long Te"
            + "st Message;Long Test Message;Long Test Message;Long Test Me"
            + "ssage;Long Test Message;Long Test Message;Long Test Message"
            + ";Long Test Message;Long Test Message;Long Test Message;Long"
            + " Test Message;Long Test Message;Long Test Message;Long Test"
            + " Message;Long Test Message;Long Test Message;Long Test Mess"
            + "age;";
    try {
        for (int i = 0; i < 10; i++) {
            System.out.println("Iteration: " + i);
            RBlockingQueue<String> q = getQueue(String.valueOf(i));
            q.add(value);
            System.out.println("Message added to [" + i + "]");
            q.expire(1, TimeUnit.MINUTES);
            System.out.println("Expiry set to [" + i + "]");
            String poll = q.poll(1, TimeUnit.SECONDS);
            System.out.println("Message polled from [" + i + "]" + poll);
            Assert.assertEquals(value, poll);
        }
    } catch (Exception e) {
        Assert.fail(e.getLocalizedMessage());
    }
}
 
Example #29
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPoll() throws InterruptedException {
    RBlockingQueue<Integer> queue1 = getQueue();
    queue1.put(1);
    Assert.assertEquals((Integer)1, queue1.poll(2, TimeUnit.SECONDS));

    long s = System.currentTimeMillis();
    Assert.assertNull(queue1.poll(5, TimeUnit.SECONDS));
    Assert.assertTrue(System.currentTimeMillis() - s > 4900);
}
 
Example #30
Source File: RedissonBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testAwait() throws InterruptedException {
    RBlockingQueue<Integer> queue1 = getQueue();
    queue1.put(1);

    Assert.assertEquals((Integer)1, queue1.poll(10, TimeUnit.SECONDS));
}