Java 类java.util.concurrent.LinkedTransferQueue 实例源码

项目:centraldogma    文件:ZooKeeperCommandExecutor.java   
private ZooKeeperCommandExecutor(String replicaId, CommandExecutor delegate, CuratorFramework curator,
                                 String zkPath, boolean createPathIfNotExist, File revisionFile,
                                 int numWorkers, int maxLogCount, long minLogAgeMillis) {
    super(replicaId);

    this.delegate = delegate;
    this.revisionFile = revisionFile;
    this.curator = curator;
    this.zkPath = zkPath;
    this.createPathIfNotExist = createPathIfNotExist;
    this.maxLogCount = maxLogCount;
    this.minLogAgeMillis = minLogAgeMillis;

    final ThreadPoolExecutor executor = new ThreadPoolExecutor(
            numWorkers, numWorkers,
            60, TimeUnit.SECONDS, new LinkedTransferQueue<>(),
            new DefaultThreadFactory("zookeeper-command-executor", true));
    executor.allowCoreThreadTimeOut(true);
    this.executor = executor;

    logWatcher = new PathChildrenCache(curator, absolutePath(LOG_PATH), true);
    logWatcher.getListenable().addListener(this, MoreExecutors.directExecutor());
    oldLogRemover = new OldLogRemover();
    leaderSelector = new LeaderSelector(curator, absolutePath(LEADER_PATH), oldLogRemover);
    leaderSelector.autoRequeue();
}
项目:jdk8u-jdk    文件:RemovePollRace.java   
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
项目:openjdk-jdk10    文件:RemoveContains.java   
public static void main(String[] args) {
    final Comparator<String> firstChar = new Comparator<>() {
        public int compare(String x, String y) {
            return x.charAt(0) - y.charAt(0); }};

    test(new PriorityQueue<String>(firstChar));
    test(new PriorityQueue<String>(10, firstChar));
    test(new PriorityBlockingQueue<String>(10, firstChar));
    test(new ArrayBlockingQueue<String>(10));
    test(new LinkedBlockingQueue<String>(10));
    test(new LinkedBlockingDeque<String>(10));
    test(new LinkedTransferQueue<String>());
    test(new ArrayDeque<String>(10));

    System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
    if (failed > 0) throw new Error("Some tests failed");
}
项目:openjdk-jdk10    文件:SingleProducerMultipleConsumerLoops.java   
public static void main(String[] args) throws Exception {
     final int maxConsumers = (args.length > 0)
         ? Integer.parseInt(args[0])
         : 5;

     pool = Executors.newCachedThreadPool();
     for (int i = 1; i <= maxConsumers; i += (i+1) >>> 1) {
         // Adjust iterations to limit typical single runs to <= 10 ms;
         // Notably, fair queues get fewer iters.
         // Unbounded queues can legitimately OOME if iterations
         // high enough, but we have a sufficiently low limit here.
         run(new ArrayBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingDeque<Integer>(100), i, 1000);
         run(new LinkedTransferQueue<Integer>(), i, 700);
         run(new PriorityBlockingQueue<Integer>(), i, 1000);
         run(new SynchronousQueue<Integer>(), i, 300);
         run(new SynchronousQueue<Integer>(true), i, 200);
         run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
     }
     pool.shutdown();
     if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
         throw new Error();
     pool = null;
}
项目:openjdk-jdk10    文件:ProducerConsumerLoops.java   
public static void main(String[] args) throws Exception {
     final int maxPairs = (args.length > 0)
         ? Integer.parseInt(args[0])
         : 5;
     int iters = 10000;

     pool = Executors.newCachedThreadPool();
     for (int i = 1; i <= maxPairs; i += (i+1) >>> 1) {
         // Adjust iterations to limit typical single runs to <= 10 ms;
         // Notably, fair queues get fewer iters.
         // Unbounded queues can legitimately OOME if iterations
         // high enough, but we have a sufficiently low limit here.
         run(new ArrayBlockingQueue<Integer>(100), i, 500);
         run(new LinkedBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingDeque<Integer>(100), i, 1000);
         run(new LinkedTransferQueue<Integer>(), i, 1000);
         run(new PriorityBlockingQueue<Integer>(), i, 1000);
         run(new SynchronousQueue<Integer>(), i, 400);
         run(new SynchronousQueue<Integer>(true), i, 300);
         run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
     }
     pool.shutdown();
     if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
         throw new Error();
     pool = null;
}
项目:openjdk-jdk10    文件:ConcurrentQueueLoops.java   
Collection<Queue<Integer>> concurrentQueues() {
    List<Queue<Integer>> queues = new ArrayList<>();
    queues.add(new ConcurrentLinkedDeque<Integer>());
    queues.add(new ConcurrentLinkedQueue<Integer>());
    queues.add(new ArrayBlockingQueue<Integer>(items, false));
    //queues.add(new ArrayBlockingQueue<Integer>(count, true));
    queues.add(new LinkedBlockingQueue<Integer>());
    queues.add(new LinkedBlockingDeque<Integer>());
    queues.add(new LinkedTransferQueue<Integer>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Integer>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
项目:openjdk-jdk10    文件:RemovePollRace.java   
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
项目:openjdk-jdk10    文件:WhiteBox.java   
/**
 * Checks that traversal operations collapse a random pattern of
 * dead nodes as could normally only occur with a race.
 */
@Test(dataProvider = "traversalActions")
public void traversalOperationsCollapseRandomNodes(
    Consumer<LinkedTransferQueue> traversalAction) {
    LinkedTransferQueue q = new LinkedTransferQueue();
    int n = rnd.nextInt(6);
    for (int i = 0; i < n; i++) q.add(i);
    ArrayList nulledOut = new ArrayList();
    for (Object p = head(q); p != null; p = next(p))
        if (rnd.nextBoolean()) {
            nulledOut.add(item(p));
            ITEM.setVolatile(p, null);
        }
    traversalAction.accept(q);
    int c = nodeCount(q);
    assertEquals(q.size(), c - (q.contains(n - 1) ? 0 : 1));
    for (int i = 0; i < n; i++)
        assertTrue(nulledOut.contains(i) ^ q.contains(i));
}
项目:openjdk-jdk10    文件:WhiteBox.java   
@Test(dataProvider = "pollActions")
public void pollActionsOneNodeSlack(
    Consumer<LinkedTransferQueue> pollAction) {
    LinkedTransferQueue q = new LinkedTransferQueue();
    int n = 1 + rnd.nextInt(5);
    for (int i = 0; i < n; i++) q.add(i);
    assertEquals(nodeCount(q), n + 1);
    for (int i = 0; i < n; i++) {
        int c = nodeCount(q);
        boolean slack = item(head(q)) == null;
        if (slack) assertNotNull(item(next(head(q))));
        pollAction.accept(q);
        assertEquals(nodeCount(q), q.isEmpty() ? 1 : c - (slack ? 2 : 0));
    }
    assertInvariants(q);
}
项目:openjdk-jdk10    文件:WhiteBox.java   
@Test(dataProvider = "addActions")
public void addActionsOneNodeSlack(
    Consumer<LinkedTransferQueue> addAction) {
    LinkedTransferQueue q = new LinkedTransferQueue();
    int n = 1 + rnd.nextInt(9);
    for (int i = 0; i < n; i++) {
        boolean slack = next(tail(q)) != null;
        addAction.accept(q);
        if (slack)
            assertNull(next(tail(q)));
        else {
            assertNotNull(next(tail(q)));
            assertNull(next(next(tail(q))));
        }
        assertInvariants(q);
    }
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * Queue contains all elements of the collection it is initialized by
 */
public void testConstructor5() {
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i) {
        ints[i] = i;
    }
    List intList = Arrays.asList(ints);
    LinkedTransferQueue q
        = new LinkedTransferQueue(intList);
    assertEquals(q.size(), intList.size());
    assertEquals(q.toString(), intList.toString());
    assertTrue(Arrays.equals(q.toArray(),
                                 intList.toArray()));
    assertTrue(Arrays.equals(q.toArray(new Object[0]),
                             intList.toArray(new Object[0])));
    assertTrue(Arrays.equals(q.toArray(new Object[SIZE]),
                             intList.toArray(new Object[SIZE])));
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(ints[i], q.poll());
    }
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * retainAll(c) retains only those elements of c and reports true
 * if changed
 */
public void testRetainAll() {
    LinkedTransferQueue q = populatedQueue(SIZE);
    LinkedTransferQueue p = populatedQueue(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.remove();
    }
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * iterator iterates through all elements
 */
public void testIterator() throws InterruptedException {
    LinkedTransferQueue q = populatedQueue(SIZE);
    Iterator it = q.iterator();
    int i;
    for (i = 0; it.hasNext(); i++)
        assertTrue(q.contains(it.next()));
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);

    it = q.iterator();
    for (i = 0; it.hasNext(); i++)
        assertEquals(it.next(), q.take());
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * iterator.remove() removes current element
 */
public void testIteratorRemove() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    q.add(two);
    q.add(one);
    q.add(three);

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertSame(it.next(), one);
    assertSame(it.next(), three);
    assertFalse(it.hasNext());
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * offer transfers elements across Executor tasks
 */
public void testOfferInExecutor() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                long startTime = System.nanoTime();
                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
            }});

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertSame(one, q.take());
                checkEmpty(q);
            }});
    }
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * timed poll retrieves elements across Executor threads
 */
public void testPollInExecutor() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertNull(q.poll());
                threadsStarted.await();
                long startTime = System.nanoTime();
                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
                checkEmpty(q);
            }});

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                q.put(one);
            }});
    }
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * drainTo(c) empties queue into another collection c
 */
public void testDrainTo() {
    LinkedTransferQueue q = populatedQueue(SIZE);
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(SIZE, l.size());
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, l.get(i));
    }
    q.add(zero);
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(zero));
    assertTrue(q.contains(one));
    l.clear();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(2, l.size());
    for (int i = 0; i < 2; ++i) {
        assertEquals(i, l.get(i));
    }
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * drainTo(c, n) empties first min(n, size) elements of queue into c
 */
public void testDrainToN() {
    LinkedTransferQueue q = new LinkedTransferQueue();
    for (int i = 0; i < SIZE + 2; ++i) {
        for (int j = 0; j < SIZE; j++) {
            assertTrue(q.offer(j));
        }
        ArrayList l = new ArrayList();
        q.drainTo(l, i);
        int k = (i < SIZE) ? i : SIZE;
        assertEquals(k, l.size());
        assertEquals(SIZE - k, q.size());
        for (int j = 0; j < k; ++j)
            assertEquals(j, l.get(j));
        do {} while (q.poll() != null);
    }
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * transfer waits until a poll occurs. The transfered element
 * is returned by the associated poll.
 */
public void testTransfer2() throws InterruptedException {
    final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
    final CountDownLatch threadStarted = new CountDownLatch(1);

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            threadStarted.countDown();
            q.transfer(five);
            checkEmpty(q);
        }});

    threadStarted.await();
    Callable<Boolean> oneElement
        = new Callable<Boolean>() { public Boolean call() {
            return !q.isEmpty() && q.size() == 1; }};
    waitForThreadToEnterWaitState(t, oneElement);

    assertSame(five, q.poll());
    checkEmpty(q);
    awaitTermination(t);
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * transfer waits until a poll occurs, at which point the polling
 * thread returns the element
 */
public void testTransfer4() throws InterruptedException {
    final LinkedTransferQueue q = new LinkedTransferQueue();

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            q.transfer(four);
            assertFalse(q.contains(four));
            assertSame(three, q.poll());
        }});

    while (q.isEmpty())
        Thread.yield();
    assertFalse(q.isEmpty());
    assertEquals(1, q.size());
    assertTrue(q.offer(three));
    assertSame(four, q.poll());
    awaitTermination(t);
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * transfer waits until a take occurs. The transfered element
 * is returned by the associated take.
 */
public void testTransfer5() throws InterruptedException {
    final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            q.transfer(four);
            checkEmpty(q);
        }});

    while (q.isEmpty())
        Thread.yield();
    assertFalse(q.isEmpty());
    assertEquals(1, q.size());
    assertSame(four, q.take());
    checkEmpty(q);
    awaitTermination(t);
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * If there is a consumer waiting in take, tryTransfer returns
 * true while successfully transfering object.
 */
public void testTryTransfer4() throws InterruptedException {
    final Object hotPotato = new Object();
    final LinkedTransferQueue q = new LinkedTransferQueue();

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            while (! q.hasWaitingConsumer())
                Thread.yield();
            assertTrue(q.hasWaitingConsumer());
            checkEmpty(q);
            assertTrue(q.tryTransfer(hotPotato));
        }});

    assertSame(q.take(), hotPotato);
    checkEmpty(q);
    awaitTermination(t);
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * tryTransfer gives up after the timeout and returns false
 */
public void testTryTransfer6() throws InterruptedException {
    final LinkedTransferQueue q = new LinkedTransferQueue();

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            long startTime = System.nanoTime();
            assertFalse(q.tryTransfer(new Object(),
                                      timeoutMillis(), MILLISECONDS));
            assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
            checkEmpty(q);
        }});

    awaitTermination(t);
    checkEmpty(q);
}
项目:openjdk-jdk10    文件:LinkedTransferQueueTest.java   
/**
 * tryTransfer waits for any elements previously in to be removed
 * before transfering to a poll or take
 */
public void testTryTransfer7() throws InterruptedException {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    assertTrue(q.offer(four));

    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            long startTime = System.nanoTime();
            assertTrue(q.tryTransfer(five, LONG_DELAY_MS, MILLISECONDS));
            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
            checkEmpty(q);
        }});

    while (q.size() != 2)
        Thread.yield();
    assertEquals(2, q.size());
    assertSame(four, q.poll());
    assertSame(five, q.poll());
    checkEmpty(q);
    awaitTermination(t);
}
项目:openjdk-systemtest    文件:LinkedTransferQueueTest.java   
public LinkedTransferQueueTestHelper(LinkedTransferQueue<GenericTestObject> queueIn, boolean isConsumerIn, boolean isProducerIn, boolean expectInterruptIn)
{
    queue = queueIn;
    isConsumer = isConsumerIn;
    isProducer = isProducerIn;
    expectInterrupt = expectInterruptIn;
}
项目:morpheus-core    文件:CsvSource.java   
/**
 * Constructor
 * @param options   the options
 */
CsvRequestHandler(CsvSourceOptions<R> options) {
    this.options = options;
    this.rowPredicate = options.getRowPredicate().orElse(null);
    this.rowKeyParser = options.getRowKeyParser().orElse(null);
    this.logBatchSize = options.getLogBatchSize();
    if (options.isParallel()) {
        this.countDownLatch = new CountDownLatch(1);
        this.queue = new LinkedTransferQueue<>();
        final Thread thread = new Thread(this, "DataFrameCsvReaderThread");
        thread.setDaemon(true);
        thread.start();
    }
}
项目:Java-9-Concurrency-Cookbook-Second-Edition    文件:ProducerConsumerTest.java   
/**
 * Creates the buffer
 */
@Override
public void initialize() {
    super.initialize();
    queue=new LinkedTransferQueue<String>();
    System.out.printf("Test: The test has been initialized\n");
}
项目:jdk8u-jdk    文件:SpliteratorTraverseAddRemoveTest.java   
@Test(dataProvider = "spliteratorTraversers")
public void testQueue(String desc, Consumer<Queue<String>> c)
        throws InterruptedException {
    AtomicBoolean done = new AtomicBoolean(false);
    Queue<String> msgs = new LinkedTransferQueue<>();

    CompletableFuture<Void> traversalTask = CompletableFuture.runAsync(() -> {
        while (!done.get()) {
            // Traversal will fail if self-linked nodes of
            // LinkedTransferQueue are erroneously reported
            c.accept(msgs);
        }
    });
    CompletableFuture<Void> addAndRemoveTask = CompletableFuture.runAsync(() -> {
        while (!traversalTask.isDone()) {
            msgs.add("msg");
            msgs.remove("msg");
        }
    });

    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    done.set(true);

    addAndRemoveTask.join();
    Assert.assertTrue(traversalTask.isDone());
    traversalTask.join();
}
项目:morpheus-core    文件:ExcelSource.java   
ExcelSheetContentHandler(ExcelSourceOptions<R> options){
    this.options = options;
    this.rowPredicate = options.getRowPredicate().orElse(null);
    this.rowKeyParser = options.getRowKeyParser().orElse(null);
    this.logBatchSize = options.getLogBatchSize();
    this.output = new ParserOutput(new CsvParserSettings());
    if (options.isParallel()) {
        this.countDownLatch = new CountDownLatch(1);
        this.queue = new LinkedTransferQueue<>();
        final Thread thread = new Thread(this, "DataFrameExcelReaderThread");
        thread.setDaemon(true);
        thread.start();
    }
}
项目:openjdk-jdk10    文件:OfferDrainToLoops.java   
void test(String[] args) throws Throwable {
    test(new LinkedBlockingQueue());
    test(new LinkedBlockingQueue(2000));
    test(new LinkedBlockingDeque());
    test(new LinkedBlockingDeque(2000));
    test(new ArrayBlockingQueue(2000));
    test(new LinkedTransferQueue());
}
项目:openjdk-jdk10    文件:PollMemoryLeak.java   
void main() throws Throwable {
    test(new LinkedBlockingDeque(10));
    test(new LinkedBlockingQueue(10));
    test(new LinkedTransferQueue());
    test(new ArrayBlockingQueue(10));
    test(new PriorityBlockingQueue());
    test(new SynchronousQueue());
    test(new SynchronousQueue(true));
}
项目:openjdk-jdk10    文件:LastElement.java   
void test(String[] args) throws Throwable {
    testQueue(new LinkedBlockingQueue<Integer>());
    testQueue(new LinkedBlockingDeque<Integer>());
    testQueue(new ArrayBlockingQueue<Integer>(10, true));
    testQueue(new ArrayBlockingQueue<Integer>(10, false));
    testQueue(new LinkedTransferQueue<Integer>());
    testQueue(new PriorityBlockingQueue<Integer>());
}
项目:openjdk-jdk10    文件:IteratorWeakConsistency.java   
void test(String[] args) throws Throwable {
    test(new LinkedBlockingQueue());
    test(new LinkedBlockingQueue(20));
    test(new LinkedBlockingDeque());
    test(new LinkedBlockingDeque(20));
    test(new ConcurrentLinkedDeque());
    test(new ConcurrentLinkedQueue());
    test(new LinkedTransferQueue());
    test(new ArrayBlockingQueue(20));
}
项目:openjdk-jdk10    文件:OfferRemoveLoops.java   
void test(String[] args) throws Throwable {
    testQueue(new LinkedBlockingQueue(10));
    testQueue(new LinkedBlockingQueue());
    testQueue(new LinkedBlockingDeque(10));
    testQueue(new LinkedBlockingDeque());
    testQueue(new ArrayBlockingQueue(10));
    testQueue(new PriorityBlockingQueue(10));
    testQueue(new ConcurrentLinkedDeque());
    testQueue(new ConcurrentLinkedQueue());
    testQueue(new LinkedTransferQueue());
}
项目:openjdk-jdk10    文件:WhiteBox.java   
int nodeCount(LinkedTransferQueue q) {
    int i = 0;
    for (Object p = head(q); p != null; ) {
        i++;
        if (p == (p = next(p))) p = head(q);
    }
    return i;
}
项目:openjdk-jdk10    文件:WhiteBox.java   
int tailCount(LinkedTransferQueue q) {
    int i = 0;
    for (Object p = tail(q); p != null; ) {
        i++;
        if (p == (p = next(p))) p = head(q);
    }
    return i;
}
项目:openjdk-jdk10    文件:WhiteBox.java   
Object findNode(LinkedTransferQueue q, Object e) {
    for (Object p = head(q); p != null; ) {
        if (item(p) != null && e.equals(item(p)))
            return p;
        if (p == (p = next(p))) p = head(q);
    }
    throw new AssertionError("not found");
}
项目:openjdk-jdk10    文件:WhiteBox.java   
@Test
public void addRemove() {
    LinkedTransferQueue q = new LinkedTransferQueue();
    assertInvariants(q);
    assertNull(next(head(q)));
    assertNull(item(head(q)));
    q.add(1);
    assertEquals(nodeCount(q), 2);
    assertInvariants(q);
    q.remove(1);
    assertEquals(nodeCount(q), 1);
    assertInvariants(q);
}
项目:openjdk-jdk10    文件:WhiteBox.java   
/**
 * Traversal actions that visit every node and do nothing, but
 * have side effect of squeezing out dead nodes.
 */
@DataProvider
public Object[][] traversalActions() {
    return List.<Consumer<LinkedTransferQueue>>of(
        q -> q.forEach(e -> {}),
        q -> assertFalse(q.contains(new Object())),
        q -> assertFalse(q.remove(new Object())),
        q -> q.spliterator().forEachRemaining(e -> {}),
        q -> q.stream().collect(toList()),
        q -> assertFalse(q.removeIf(e -> false)),
        q -> assertFalse(q.removeAll(List.of())))
        .stream().map(x -> new Object[]{ x }).toArray(Object[][]::new);
}
项目:openjdk-jdk10    文件:WhiteBox.java   
@Test(dataProvider = "traversalActions")
public void traversalOperationsCollapseLeadingNodes(
    Consumer<LinkedTransferQueue> traversalAction) {
    LinkedTransferQueue q = new LinkedTransferQueue();
    Object oldHead;
    int n = 1 + rnd.nextInt(5);
    for (int i = 0; i < n; i++) q.add(i);
    assertEquals(nodeCount(q), n + 1);
    oldHead = head(q);
    traversalAction.accept(q);
    assertInvariants(q);
    assertEquals(nodeCount(q), n);
    assertIsSelfLinked(oldHead);
}