Java Code Examples for org.redisson.api.RBlockingQueue#drainTo()

The following examples show how to use org.redisson.api.RBlockingQueue#drainTo() . 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: 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 2
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 3
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 4
Source File: RedissonPriorityBlockingQueueTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testDrainToCollection() throws Exception {
    RBlockingQueue<Integer> queue1 = getQueue();
    queue1.put(1);
    queue1.put(2);
    queue1.put(3);

    ArrayList<Object> dst = new ArrayList<Object>();
    queue1.drainTo(dst);
    assertThat(dst).containsExactly(1, 2, 3);
    Assert.assertEquals(0, queue1.size());
}
 
Example 5
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 6
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());
}