/** {@inheritDoc} */ @Override public int getActiveCount() { return exec.activeStripesCount(); }
/** {@inheritDoc} */ @Override public long getTotalCompletedTasksCount() { return exec.completedTasks(); }
/** {@inheritDoc} */ @Override public boolean detectStarvation() { return exec.detectStarvation(); }
awaitLatch = new CountDownLatch(stripes()); range(0, stripes()).forEach(idx -> execute(idx, awaitLatch::countDown)); execute(idx, awaitLatch::countDown); ", awaitLatch=" + awaitLatch.getCount() + ", stripes=" + (stripes.length == 0 ? Arrays.toString(range(0, stripes()).toArray()) : Arrays.toString(stripes)) + ", queueSize=" + Arrays.toString(stripesQueueSizes()) + ", activeStatus=" + Arrays.toString(stripesActiveStatuses()));
/** * @throws Exception If failed. */ @Test public void testStarvationDetected() throws Exception { final int stripeIdx = 0; stripedExecSvc.execute(stripeIdx, new TestRunnable(true)); sleepASec(); assertFalse(GridTestUtils.waitForCondition(() -> stripedExecSvc.activeStripesCount() == 0, 2000)); stripedExecSvc.execute(stripeIdx, new TestRunnable()); assertTrue(GridTestUtils.waitForCondition(() -> stripedExecSvc.activeStripesCount() == 1, 10000)); assertTrue(stripedExecSvc.detectStarvation()); }
/** * Execute command. * * @param idx Index. * @param cmd Command. */ public void execute(int idx, Runnable cmd) { if (idx == -1) execute(cmd); else { assert idx >= 0 : idx; stripes[idx % stripes.length].execute(cmd); } }
/** * @throws Exception If failed. */ @Test public void testCompletedTasks() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable()); sleepASec(); assertEquals(2, stripedExecSvc.completedTasks()); }
/** * @throws Exception If failed. */ @Test public void testActiveStripesCount() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable(true)); sleepASec(); assertEquals(1, stripedExecSvc.activeStripesCount()); }
/** * @throws Exception If failed. */ @Test public void testStripesQueueSizes() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(0, new TestRunnable(true)); stripedExecSvc.execute(0, new TestRunnable(true)); stripedExecSvc.execute(1, new TestRunnable(true)); stripedExecSvc.execute(1, new TestRunnable(true)); stripedExecSvc.execute(1, new TestRunnable(true)); sleepASec(); int[] queueSizes = stripedExecSvc.stripesQueueSizes(); assertEquals(1, queueSizes[0]); assertEquals(2, queueSizes[1]); assertEquals(0, queueSizes[2]); }
/** * @throws Exception If failed. */ @Test public void testStripesActiveStatuses() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable(true)); sleepASec(); boolean[] statuses = stripedExecSvc.stripesActiveStatuses(); assertFalse(statuses[0]); assertTrue(statuses[1]); assertFalse(statuses[0]); }
/** * @throws Exception If failed. */ @Test public void testStripesCompletedTasks() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable()); sleepASec(); long[] completedTaks = stripedExecSvc.stripesCompletedTasks(); assertEquals(1, completedTaks[0]); assertEquals(1, completedTaks[1]); assertEquals(0, completedTaks[2]); }
/** * @return Number of active tasks. */ public int activeStripesCount() { int res = 0; for (boolean status : stripesActiveStatuses()) { if (status) res++; } return res; }
/** {@inheritDoc} */ @Override public void beforeTest() { stripedExecSvc = new StripedExecutor(3, "foo name", "pool name", new JavaLogger(), new IgniteInClosure<Throwable>() { @Override public void apply(Throwable throwable) {} }, null, 2000); }
/** {@inheritDoc} */ @Override public int[] getStripesQueueSizes() { return exec.stripesQueueSizes(); } }
/** {@inheritDoc} */ @Override public int getTotalQueueSize() { return exec.queueSize(); }
/** {@inheritDoc} */ @Override public long[] getStripesCompletedTasksCounts() { return exec.stripesCompletedTasks(); }
/** * @param exec Striped executor. * @param applyError Check error reference. */ private void awaitApplyComplete( StripedExecutor exec, AtomicReference<IgniteCheckedException> applyError ) throws IgniteCheckedException { if (applyError.get() != null) throw applyError.get(); // Fail-fast check. else { try { // Await completion apply tasks in all stripes. exec.awaitComplete(); } catch (InterruptedException e) { throw new IgniteInterruptedException(e); } // Checking error after all task applied. if (applyError.get() != null) throw applyError.get(); } }
/** * @param thread Thread. * @param c Closure. */ public void runLocalWithThreadPolicy(IgniteThread thread, Runnable c) { assert thread.stripe() >= 0 || thread.policy() != GridIoPolicy.UNDEFINED : thread; if (thread.stripe() >= 0) ctx.getStripedExecutorService().execute(thread.stripe(), c); else { try { ctx.pools().poolForPolicy(thread.policy()).execute(c); } catch (IgniteCheckedException e) { U.error(log, "Failed to get pool for policy: " + thread.policy(), e); } } }