Java Code Examples for java.util.concurrent.ConcurrentSkipListSet#pollFirst()

The following examples show how to use java.util.concurrent.ConcurrentSkipListSet#pollFirst() . 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: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    ConcurrentSkipListSet q = populatedSet(SIZE);
    ConcurrentSkipListSet p = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.pollFirst();
    }
}
 
Example 2
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    ConcurrentSkipListSet q = populatedSet(SIZE);
    ConcurrentSkipListSet p = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.pollFirst();
    }
}
 
Example 3
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    ConcurrentSkipListSet q = new ConcurrentSkipListSet();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.pollFirst();
    q.pollFirst();
    assertTrue(q.isEmpty());
}
 
Example 4
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * size changes when elements added and removed
 */
public void testSize() {
    ConcurrentSkipListSet q = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.pollFirst();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
Example 5
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * contains(x) reports true when elements added but not yet removed
 */
public void testContains() {
    ConcurrentSkipListSet q = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.contains(new Integer(i)));
        q.pollFirst();
        assertFalse(q.contains(new Integer(i)));
    }
}
 
Example 6
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        ConcurrentSkipListSet q = populatedSet(SIZE);
        ConcurrentSkipListSet p = populatedSet(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer)(p.pollFirst());
            assertFalse(q.contains(x));
        }
    }
}
 
Example 7
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    ConcurrentSkipListSet q = new ConcurrentSkipListSet();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.pollFirst();
    q.pollFirst();
    assertTrue(q.isEmpty());
}
 
Example 8
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * size changes when elements added and removed
 */
public void testSize() {
    ConcurrentSkipListSet q = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.pollFirst();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
Example 9
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * contains(x) reports true when elements added but not yet removed
 */
public void testContains() {
    ConcurrentSkipListSet q = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.contains(new Integer(i)));
        q.pollFirst();
        assertFalse(q.contains(new Integer(i)));
    }
}
 
Example 10
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        ConcurrentSkipListSet q = populatedSet(SIZE);
        ConcurrentSkipListSet p = populatedSet(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer)(p.pollFirst());
            assertFalse(q.contains(x));
        }
    }
}
 
Example 11
Source File: HybridDBStorage.java    From copper-engine with Apache License 2.0 5 votes vote down vote up
QueueElement _poll(String ppoolId) {
    logger.trace("_poll({})", ppoolId);
    ConcurrentSkipListSet<QueueElement> queue = _findQueue(ppoolId);
    QueueElement qe = queue.pollFirst();
    if (qe != null) {
        logger.debug("dequeued for ppoolId={}: wfId={}", ppoolId, qe.wfId);
    }
    return qe;
}
 
Example 12
Source File: HybridDBStorage.java    From copper-engine with Apache License 2.0 5 votes vote down vote up
QueueElement _take(String ppoolId) throws InterruptedException {
    logger.trace("_take({})", ppoolId);
    ConcurrentSkipListSet<QueueElement> queue = _findQueue(ppoolId);
    synchronized (queue) {
        for (;;) {
            QueueElement qe = queue.pollFirst();
            if (qe != null) {
                logger.debug("dequeued for ppoolId={}: wfId={}", ppoolId, qe.wfId);
                return qe;
            }
            queue.wait(10L);
        }
    }
}
 
Example 13
Source File: SortedListForAsyncQueueJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testIfTheKeyToSeqNumIsKeptSortedWithoutConflation() throws Exception {
  byte[] k1 = new byte[] { 1};
  byte[] k2 = new byte[] { 2};
  byte[] k3 = new byte[] { 3};
  byte[] k4 = new byte[] { 4};
  
  KeyToSeqNumObject keyToSeq1 = new KeyToSeqNumObject(k1, new Long(2));
  KeyToSeqNumObject keyToSeq2 = new KeyToSeqNumObject(k1, new Long(5));
  KeyToSeqNumObject keyToSeq3 = new KeyToSeqNumObject(k1, new Long(8));
  KeyToSeqNumObject keyToSeq4 = new KeyToSeqNumObject(k2, new Long(3));
  KeyToSeqNumObject keyToSeq5 = new KeyToSeqNumObject(k2, new Long(7));
  
  ConcurrentSkipListSet<KeyToSeqNumObject> list = new ConcurrentSkipListSet<HDFSBucketRegionQueue.KeyToSeqNumObject>();
  list.add(keyToSeq4);
  list.add(keyToSeq3);
  list.add(keyToSeq5);
  list.add(keyToSeq1);
  list.add(keyToSeq2);
  list.add(keyToSeq5);
  KeyToSeqNumObject k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq3));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq2));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq1));
  list.remove(k);
  
  list.add(keyToSeq4);
  list.add(keyToSeq3);
  list.add(keyToSeq5);
  list.add(keyToSeq1);
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq3));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq1));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq5));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq4));
  
  list.remove(k);
}
 
Example 14
Source File: SortedListForAsyncQueueJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testIfTheKeyToSeqNumIsKeptSortedWithoutConflation() throws Exception {
  byte[] k1 = new byte[] { 1};
  byte[] k2 = new byte[] { 2};
  byte[] k3 = new byte[] { 3};
  byte[] k4 = new byte[] { 4};
  
  KeyToSeqNumObject keyToSeq1 = new KeyToSeqNumObject(k1, new Long(2));
  KeyToSeqNumObject keyToSeq2 = new KeyToSeqNumObject(k1, new Long(5));
  KeyToSeqNumObject keyToSeq3 = new KeyToSeqNumObject(k1, new Long(8));
  KeyToSeqNumObject keyToSeq4 = new KeyToSeqNumObject(k2, new Long(3));
  KeyToSeqNumObject keyToSeq5 = new KeyToSeqNumObject(k2, new Long(7));
  
  ConcurrentSkipListSet<KeyToSeqNumObject> list = new ConcurrentSkipListSet<HDFSBucketRegionQueue.KeyToSeqNumObject>();
  list.add(keyToSeq4);
  list.add(keyToSeq3);
  list.add(keyToSeq5);
  list.add(keyToSeq1);
  list.add(keyToSeq2);
  list.add(keyToSeq5);
  KeyToSeqNumObject k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq3));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq2));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq1));
  list.remove(k);
  
  list.add(keyToSeq4);
  list.add(keyToSeq3);
  list.add(keyToSeq5);
  list.add(keyToSeq1);
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq3));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq1));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq5));
  list.remove(k);
  
  k = list.pollFirst();
  this.c.getLoggerI18n().fine(" KeyToSeqNumObject  byte: " + k.getRegionkey()[0] + " seq num: " + k.getSeqNum());
  assertTrue ("Order of elements in Concurrent list is not correct ", k.equals(keyToSeq4));
  
  list.remove(k);
}