当前位置: 首页>>代码示例>>Java>>正文


Java LinkedBlockingDeque.add方法代码示例

本文整理汇总了Java中java.util.concurrent.LinkedBlockingDeque.add方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedBlockingDeque.add方法的具体用法?Java LinkedBlockingDeque.add怎么用?Java LinkedBlockingDeque.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.LinkedBlockingDeque的用法示例。


在下文中一共展示了LinkedBlockingDeque.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testIteratorRemove

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * iterator.remove removes current element
 */
public void testIteratorRemove() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
    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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:LinkedBlockingDequeTest.java

示例2: testDescendingIteratorOrdering

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * Descending iterator ordering is reverse FIFO
 */
public void testDescendingIteratorOrdering() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque();
    for (int iters = 0; iters < 100; ++iters) {
        q.add(new Integer(3));
        q.add(new Integer(2));
        q.add(new Integer(1));
        int k = 0;
        for (Iterator it = q.descendingIterator(); it.hasNext();) {
            assertEquals(++k, it.next());
        }

        assertEquals(3, k);
        q.remove();
        q.remove();
        q.remove();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:LinkedBlockingDequeTest.java

示例3: testDescendingIteratorRemove

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * descendingIterator.remove removes current element
 */
public void testDescendingIteratorRemove() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque();
    for (int iters = 0; iters < 100; ++iters) {
        q.add(new Integer(3));
        q.add(new Integer(2));
        q.add(new Integer(1));
        Iterator it = q.descendingIterator();
        assertEquals(it.next(), new Integer(1));
        it.remove();
        assertEquals(it.next(), new Integer(2));
        it = q.descendingIterator();
        assertEquals(it.next(), new Integer(2));
        assertEquals(it.next(), new Integer(3));
        it.remove();
        assertFalse(it.hasNext());
        q.remove();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:LinkedBlockingDequeTest.java

示例4: testOfferInExecutor

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * offer transfers elements across Executor tasks
 */
public void testOfferInExecutor() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
    q.add(one);
    q.add(two);
    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 {
                assertFalse(q.offer(three));
                threadsStarted.await();
                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }});

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertSame(one, q.take());
            }});
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:LinkedBlockingDequeTest.java

示例5: testDrainTo

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * drainTo(c) empties deque into another collection c
 */
public void testDrainTo() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(SIZE, l.size());
    for (int i = 0; i < SIZE; ++i)
        assertEquals(l.get(i), new Integer(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(l.get(i), new Integer(i));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:LinkedBlockingDequeTest.java

示例6: testEmpty

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    LinkedBlockingDeque q = new LinkedBlockingDeque();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.removeFirst();
    q.removeFirst();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:LinkedBlockingDequeTest.java

示例7: testSize

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * size changes when elements added and removed
 */
public void testSize() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.removeFirst();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LinkedBlockingDequeTest.java

示例8: testEmptyFull

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * Deque transitions from empty to full when elements added
 */
public void testEmptyFull() {
    LinkedBlockingDeque q = new LinkedBlockingDeque(2);
    assertTrue(q.isEmpty());
    assertEquals("should have room for 2", 2, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    assertFalse(q.isEmpty());
    assertEquals(0, q.remainingCapacity());
    assertFalse(q.offer(three));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LinkedBlockingDequeTest.java

示例9: testAdd

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * add succeeds if not full; throws IllegalStateException if full
 */
public void testAdd() {
    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
    for (int i = 0; i < SIZE; ++i)
        assertTrue(q.add(new Integer(i)));
    assertEquals(0, q.remainingCapacity());
    try {
        q.add(new Integer(SIZE));
        shouldThrow();
    } catch (IllegalStateException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:LinkedBlockingDequeTest.java

示例10: testClear

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * clear removes all elements
 */
public void testClear() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    assertEquals(SIZE, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(one));
    q.clear();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:LinkedBlockingDequeTest.java

示例11: testContainsAll

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * containsAll(c) is true when c contains a subset of elements
 */
public void testContainsAll() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    LinkedBlockingDeque p = new LinkedBlockingDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.containsAll(p));
        assertFalse(p.containsAll(q));
        p.add(new Integer(i));
    }
    assertTrue(p.containsAll(q));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:LinkedBlockingDequeTest.java

示例12: testIteratorOrdering

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * iterator ordering is FIFO
 */
public void testIteratorOrdering() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
    q.add(one);
    q.add(two);
    q.add(three);
    assertEquals(0, q.remainingCapacity());
    int k = 0;
    for (Iterator it = q.iterator(); it.hasNext();) {
        assertEquals(++k, it.next());
    }
    assertEquals(3, k);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:LinkedBlockingDequeTest.java

示例13: testWeaklyConsistentIteration

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LinkedBlockingDequeTest.java

示例14: testDelayedCheck

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
@Test
public void testDelayedCheck() throws InterruptedException, KafkaCruiseControlException {
  LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
  AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
  BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
  GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
  ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
  ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
  KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);

  EasyMock.expect(mockAnomalyNotifier.onBrokerFailure(EasyMock.isA(BrokerFailures.class)))
         .andReturn(AnomalyNotificationResult.check(1000L));

  // Starting periodic goal violation detection.
  EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
                                                            EasyMock.anyLong(),
                                                            EasyMock.eq(3000L),
                                                            EasyMock.eq(TimeUnit.MILLISECONDS)))
          .andReturn(null);

  // Starting anomaly handler
  EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
          .andDelegateTo(executorService);
  // Schedule a delayed check
  EasyMock.expect(mockDetectorScheduler.schedule(EasyMock.isA(Runnable.class),
                                                 EasyMock.eq(1000L),
                                                 EasyMock.eq(TimeUnit.MILLISECONDS)))
          .andReturn(null);
  mockDetectorScheduler.shutdown();
  EasyMock.expectLastCall().andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);

  // The following state are used to test the delayed check when executor is busy.
  EasyMock.expect(mockKafkaCruiseControl.state())
          .andReturn(new KafkaCruiseControlState(ExecutorState.noTaskInProgress(), null, null));

  EasyMock.replay(mockAnomalyNotifier);
  EasyMock.replay(mockBrokerFailureDetector);
  EasyMock.replay(mockGoalViolationDetector);
  EasyMock.replay(mockDetectorScheduler);
  EasyMock.replay(mockKafkaCruiseControl);

  AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
                                                        mockGoalViolationDetector, mockBrokerFailureDetector,
                                                        mockDetectorScheduler);

  try {
    anomalyDetector.startDetection();
    anomalies.add(new BrokerFailures(Collections.singletonMap(0, 100L)));
    while (!anomalies.isEmpty()) {
      // just wait for the anomalies to be drained.
    }
    anomalyDetector.shutdown();
    assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
    EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
  } finally {
    executorService.shutdown();
  }
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:61,代码来源:AnomalyDetectorTest.java

示例15: testFix

import java.util.concurrent.LinkedBlockingDeque; //导入方法依赖的package包/类
@Test
public void testFix() throws InterruptedException, KafkaCruiseControlException {
  LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
  AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
  BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
  GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
  ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
  ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
  KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);

  EasyMock.expect(mockAnomalyNotifier.onGoalViolation(EasyMock.isA(GoalViolations.class)))
          .andReturn(AnomalyNotificationResult.fix());

  // Starting periodic goal violation detection.
  EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
                                                            EasyMock.anyLong(),
                                                            EasyMock.eq(3000L),
                                                            EasyMock.eq(TimeUnit.MILLISECONDS)))
          .andReturn(null);

  // Starting anomaly handler
  EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
          .andDelegateTo(executorService);

  mockDetectorScheduler.shutdown();
  EasyMock.expectLastCall().andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);

  // The following state are used to test the delayed check when executor is busy.
  EasyMock.expect(mockKafkaCruiseControl.state())
          .andReturn(new KafkaCruiseControlState(ExecutorState.noTaskInProgress(), null, null));
  EasyMock.expect(mockKafkaCruiseControl.rebalance(Collections.emptyList(), false, null))
          .andReturn(null);

  EasyMock.replay(mockAnomalyNotifier);
  EasyMock.replay(mockBrokerFailureDetector);
  EasyMock.replay(mockGoalViolationDetector);
  EasyMock.replay(mockDetectorScheduler);
  EasyMock.replay(mockKafkaCruiseControl);

  AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
                                                        mockGoalViolationDetector, mockBrokerFailureDetector,
                                                        mockDetectorScheduler);

  try {
    anomalyDetector.startDetection();
    anomalies.add(new GoalViolations());
    while (!anomalies.isEmpty()) {
      // Just wait for the anomalies to be drained.
    }
    anomalyDetector.shutdown();
    assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
    EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
  } finally {
    executorService.shutdown();
  }
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:59,代码来源:AnomalyDetectorTest.java


注:本文中的java.util.concurrent.LinkedBlockingDeque.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。