Search in sources :

Example 1 with DelayQueue

use of java.util.concurrent.DelayQueue in project intellij-community by JetBrains.

the class LightPlatformTestCase method checkJavaSwingTimersAreDisposed.

private static void checkJavaSwingTimersAreDisposed() throws Exception {
    Class<?> TimerQueueClass = Class.forName("javax.swing.TimerQueue");
    Method sharedInstance = ReflectionUtil.getMethod(TimerQueueClass, "sharedInstance");
    Object timerQueue = sharedInstance.invoke(null);
    DelayQueue delayQueue = ReflectionUtil.getField(TimerQueueClass, timerQueue, DelayQueue.class, "queue");
    Delayed timer = delayQueue.peek();
    if (timer != null) {
        long delay = timer.getDelay(TimeUnit.MILLISECONDS);
        String text = "(delayed for " + delay + "ms)";
        Method getTimer = ReflectionUtil.getDeclaredMethod(timer.getClass(), "getTimer");
        Timer swingTimer = (Timer) getTimer.invoke(timer);
        text = "Timer (listeners: " + Arrays.asList(swingTimer.getActionListeners()) + ") " + text;
        throw new AssertionFailedError("Not disposed java.swing.Timer: " + text + "; queue:" + timerQueue);
    }
}
Also used : Delayed(java.util.concurrent.Delayed) Method(java.lang.reflect.Method) AssertionFailedError(junit.framework.AssertionFailedError) DelayQueue(java.util.concurrent.DelayQueue)

Example 2 with DelayQueue

use of java.util.concurrent.DelayQueue in project hive by apache.

the class TestLlapTaskSchedulerService method testLocalityDelayTaskOrdering.

@Test(timeout = 10000)
public void testLocalityDelayTaskOrdering() throws InterruptedException, IOException {
    LlapTaskSchedulerService.LocalityDelayConf localityDelayConf = new LlapTaskSchedulerService.LocalityDelayConf(3000);
    ControlledClock clock = new ControlledClock(new MonotonicClock());
    clock.setTime(clock.getTime());
    DelayQueue<LlapTaskSchedulerService.TaskInfo> delayedQueue = new DelayQueue<>();
    LlapTaskSchedulerService.TaskInfo taskInfo1 = new LlapTaskSchedulerService.TaskInfo(localityDelayConf, clock, new Object(), new Object(), mock(Priority.class), mock(Resource.class), null, null, clock.getTime());
    clock.setTime(clock.getTime() + 1000);
    LlapTaskSchedulerService.TaskInfo taskInfo2 = new LlapTaskSchedulerService.TaskInfo(localityDelayConf, clock, new Object(), new Object(), mock(Priority.class), mock(Resource.class), null, null, clock.getTime());
    delayedQueue.add(taskInfo1);
    delayedQueue.add(taskInfo2);
    assertEquals(taskInfo1, delayedQueue.peek());
}
Also used : Priority(org.apache.hadoop.yarn.api.records.Priority) Resource(org.apache.hadoop.yarn.api.records.Resource) ControlledClock(org.apache.hadoop.hive.llap.testhelpers.ControlledClock) MonotonicClock(org.apache.hadoop.hive.llap.tezplugins.helpers.MonotonicClock) DelayQueue(java.util.concurrent.DelayQueue) Test(org.junit.Test)

Example 3 with DelayQueue

use of java.util.concurrent.DelayQueue in project hadoop by apache.

the class TaskRunner method start.

@SuppressWarnings("unchecked")
public void start() {
    if (executor != null) {
        throw new IllegalStateException("Already started");
    }
    DelayQueue preStartQueue = queue;
    queue = new DelayQueue();
    executor = new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 0, TimeUnit.MILLISECONDS, queue);
    executor.prestartAllCoreThreads();
    startTimeMS = System.currentTimeMillis();
    for (Object d : preStartQueue) {
        schedule((Task) d, startTimeMS);
    }
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) DelayQueue(java.util.concurrent.DelayQueue)

Aggregations

DelayQueue (java.util.concurrent.DelayQueue)3 Method (java.lang.reflect.Method)1 Delayed (java.util.concurrent.Delayed)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AssertionFailedError (junit.framework.AssertionFailedError)1 ControlledClock (org.apache.hadoop.hive.llap.testhelpers.ControlledClock)1 MonotonicClock (org.apache.hadoop.hive.llap.tezplugins.helpers.MonotonicClock)1 Priority (org.apache.hadoop.yarn.api.records.Priority)1 Resource (org.apache.hadoop.yarn.api.records.Resource)1 Test (org.junit.Test)1