private Future<Void> makeWorkStuckAtSemaphore( int delta ) { semaphore.drainPermits(); Future<Void> concurrentWork = executor.submit( new CallableWork( new AddWork( delta ) ) ); assertThrows( TimeoutException.class, () -> concurrentWork.get( 10, TimeUnit.MILLISECONDS ) ); while ( !semaphore.hasQueuedThreads() ) { usleep( 1 ); } // good, the concurrent AddWork is now stuck on the semaphore return concurrentWork; }
@Test public void testFaultsDoNotGetToEvictionAdvisor() throws StoreAccessException { final Semaphore semaphore = new Semaphore(0); final OnHeapStoreForTests<String, String> store = newStore(SystemTimeSource.INSTANCE, noAdvice()); ExecutorService executor = Executors.newCachedThreadPool(); try { executor.submit(() -> store.getOrComputeIfAbsent("prime", key -> { semaphore.acquireUninterruptibly(); return new OnHeapValueHolder<String>(0, 0, false) { @Override public String get() { return key; } }; })); while (!semaphore.hasQueuedThreads()); store.put("boom", "boom"); } finally { semaphore.release(1); executor.shutdown(); } }
@Test public void testTableProcedureDeadLockAfterRestarting() throws Exception { // let the shared procedure run first, but let it have a greater procId so when loading it will // be loaded at last. long procId1 = procExec.submitProcedure(new TableSharedProcedureWithId()); long procId2 = procExec.submitProcedure(new TableExclusiveProcedureWithId()); procExec.startWorkers(); UTIL.waitFor(10000, () -> ((TableSharedProcedure) procExec.getProcedure(procId1)).latch.hasQueuedThreads()); ProcedureTestingUtility.restart(procExec); ((TableSharedProcedure) procExec.getProcedure(procId1)).latch.release(); ((TableExclusiveProcedure) procExec.getProcedure(procId2)).latch.release(); UTIL.waitFor(10000, () -> procExec.isFinished(procId1)); UTIL.waitFor(10000, () -> procExec.isFinished(procId2)); }
public boolean hasQueuedThreads() { return semaphore.hasQueuedThreads(); } }
public boolean hasQueuedThreads() { return semaphore.hasQueuedThreads(); } }
boolean isClosing(){ return runPermit.hasQueuedThreads(); }
boolean isClosing(){ return runPermit.hasQueuedThreads(); }
boolean isClosing(){ return runPermit.hasQueuedThreads(); }
@Override public final boolean isIdle() { if(concurrencyLevel > 0) { return !concurrencyThrottle.hasQueuedThreads() && concurrencyThrottle.availablePermits() >= concurrencyLevel; } else { return concurrencyThrottle.availablePermits() == Integer.MAX_VALUE; } }
public boolean isEmptyAndBlocked() { return numLeft.get() == 0 && semaphore.availablePermits() == 0 && semaphore.hasQueuedThreads(); }
@Override public String fulfilled() throws Exception { if (!waitBeforeUnlocking.hasQueuedThreads()) { return "no thread queued"; } return null; }
@Override public String fulfilled() throws Exception { if (!waitBeforeLocking.hasQueuedThreads()) { return "no thread queued"; } return null; }
/** Returns true when the queue is empty and all the permits were released. * * @return */ public boolean isDone() { return q.isEmpty() && ( !s.hasQueuedThreads() ) ; }
/** * This method is called by Spring during server shut-down. */ public void destroy() { final Semaphore semaphoreCopy = SHARED_SEMAPHORE; if (semaphoreCopy != null) { SHARED_SEMAPHORE = null; try { Thread.sleep(1); } catch (InterruptedException e) { // does not matter } while (semaphoreCopy.hasQueuedThreads()) { semaphoreCopy.release(); try { Thread.sleep(1); } catch (InterruptedException e) { // does not matter } } } } }
private boolean isQueueFull(Semaphore rateLimiter) { return (rateLimiter.availablePermits() == 0 && rateLimiter.hasQueuedThreads()); } }
public void stop() { super.stop(true); // shutdown now // enable blocked threads to finish // https://issues.apache.org/jira/browse/UIMA-3433 if ( semaphore != null ) { while ( semaphore.hasQueuedThreads()) { semaphore.release(); // permit any blocked threads to clean up try { Thread.sleep(1); // allow other thread to become unqueued } catch (InterruptedException e) { } } // semaphore.drainPermits(); // while ( semaphore.availablePermits() > 0) { // semaphore.release(); // } } this.cleanUp(); // dont kill jUnit tests if (isTopLevelComponent() && System.getProperty("dontKill") == null) { System.exit(0); } }
@Test public void cancel() throws Exception { // block gc call store.semaphore.acquireUninterruptibly(); Future<VersionGCStats> stats = gc(); boolean gcBlocked = false; for (int i = 0; i < 10; i ++) { if (store.semaphore.hasQueuedThreads()) { gcBlocked = true; break; } Thread.sleep(100); } assertTrue(gcBlocked); // now cancel the GC gc.cancel(); store.semaphore.release(); assertTrue(stats.get().canceled); }
@Test public void failParallelGC() throws Exception { // block gc call store.semaphore.acquireUninterruptibly(); Future<VersionGCStats> stats = gc(); boolean gcBlocked = false; for (int i = 0; i < 10; i ++) { if (store.semaphore.hasQueuedThreads()) { gcBlocked = true; break; } Thread.sleep(100); } assertTrue(gcBlocked); // now try to trigger another GC try { gc.gc(30, TimeUnit.MINUTES); fail("must throw an IOException"); } catch (IOException e) { assertTrue(e.getMessage().contains("already running")); } finally { store.semaphore.release(); stats.get(); } }
@Test public void asyncIndexerReindexAndPropertyIndexes() throws Exception{ defnb.async("async", "nrt"); defnb.indexRule("nt:base").property("foo").sync(); addIndex(indexPath, defnb); root.commit(); createPath("/a").setProperty("foo", "bar"); root.commit(); Semaphore s = new Semaphore(0); delayingEditorProvider.semaphore = s; AtomicReference<Throwable> th = new AtomicReference<>(); Thread t = new Thread(this::runAsyncIndex); t.setUncaughtExceptionHandler((t1, e) -> th.set(e)); t.start(); while (!s.hasQueuedThreads()) { Thread.yield(); } createPath("/b").setProperty("foo", "bar"); root.commit(); s.release(2); t.join(); if (th.get() != null) { throw new AssertionError(th.get()); } }
@Test public void testTableProcedureDeadLockAfterRestarting() throws Exception { // let the shared procedure run first, but let it have a greater procId so when loading it will // be loaded at last. long procId1 = procExec.submitProcedure(new TableSharedProcedureWithId()); long procId2 = procExec.submitProcedure(new TableExclusiveProcedureWithId()); procExec.startWorkers(); UTIL.waitFor(10000, () -> ((TableSharedProcedure) procExec.getProcedure(procId1)).latch.hasQueuedThreads()); ProcedureTestingUtility.restart(procExec); ((TableSharedProcedure) procExec.getProcedure(procId1)).latch.release(); ((TableExclusiveProcedure) procExec.getProcedure(procId2)).latch.release(); UTIL.waitFor(10000, () -> procExec.isFinished(procId1)); UTIL.waitFor(10000, () -> procExec.isFinished(procId2)); }