public void signalAll() { for (SingleConsumerCondition condition : conditions) { condition.signal(); } } }
@Test(timeout=10000) public void shouldNotBlockIfSignalAvailable() { SingleConsumerCondition condition = new SingleConsumerCondition(Thread.currentThread()); // given condition.signal(); // then condition.await(100000); }
@Test(timeout=10000) public void shouldNotBlockIfSignalAvailableDifferentThread() throws InterruptedException { final SingleConsumerCondition condition = new SingleConsumerCondition(Thread.currentThread()); Thread consumer = new Thread() { @Override public void run() { condition.signal(); } }; consumer.start(); consumer.join(); // then condition.await(100000); }
public FetchAndLockHandlerImpl() { this.condition = new SingleConsumerCondition(handlerThread); }
protected void suspendAcquisition(long millis) { try { if (queue.isEmpty() && isRunning) { LOG.log(Level.FINEST, "Suspend acquisition for {0}ms", millis); condition.await(millis); LOG.log(Level.FINEST, "Acquisition woke up"); } } finally { if (handlerThread.isInterrupted()) { Thread.currentThread().interrupt(); } } }
@Test public void cannotAwaitFromDifferentThread() { // given SingleConsumerCondition condition = new SingleConsumerCondition(new Thread()); // when then try { condition.await(0); Assert.fail("expected exception"); } catch (RuntimeException e) { // expected } }
@Test public void cannotCreateWithNull() { try { new SingleConsumerCondition(null); Assert.fail("expected exception"); } catch (IllegalArgumentException e) { // expected } }
protected void suspendAcquisition(long millis) { try { if (queue.isEmpty() && isRunning) { LOG.log(Level.FINEST, "Suspend acquisition for {0}ms", millis); condition.await(millis); LOG.log(Level.FINEST, "Acquisition woke up", millis); } } finally { if (handlerThread.isInterrupted()) { Thread.currentThread().interrupt(); } } }
public void signalAll() { for (SingleConsumerCondition condition : conditions) { condition.signal(); } } }
@Test(timeout=10000) public void shouldNotBlockIfSignalAvailable() { SingleConsumerCondition condition = new SingleConsumerCondition(Thread.currentThread()); // given condition.signal(); // then condition.await(100000); }
@Test(timeout=10000) public void shouldNotBlockIfSignalAvailableDifferentThread() throws InterruptedException { final SingleConsumerCondition condition = new SingleConsumerCondition(Thread.currentThread()); Thread consumer = new Thread() { @Override public void run() { condition.signal(); } }; consumer.start(); consumer.join(); // then condition.await(100000); }
public FetchAndLockHandlerImpl() { this.condition = new SingleConsumerCondition(handlerThread); }
@Override public void run() { condition.signal(); } };
@Test public void cannotAwaitFromDifferentThread() { // given SingleConsumerCondition condition = new SingleConsumerCondition(new Thread()); // when then try { condition.await(0); Assert.fail("expected exception"); } catch (RuntimeException e) { // expected } }
@Test public void cannotCreateWithNull() { try { new SingleConsumerCondition(null); Assert.fail("expected exception"); } catch (IllegalArgumentException e) { // expected } }
@Override public void shutdown() { try { ProcessEngineImpl.EXT_TASK_CONDITIONS.removeConsumer(condition); } finally { isRunning = false; condition.signal(); } try { handlerThread.join(); } catch (InterruptedException e) { LOG.log(Level.WARNING, "Shutting down the handler thread failed: {0}", e); } }
protected void addRequest(FetchAndLockRequest request) { if (!queue.offer(request)) { AsyncResponse asyncResponse = request.getAsyncResponse(); errorTooManyRequests(asyncResponse); } condition.signal(); }
@Test public void shouldSignalConditionOnTaskCreate() { // when rule.getRuntimeService() .startProcessInstanceByKey("theProcess"); // then verify(condition, times(1)).signal(); }
@Test public void shouldSignalConditionOnTaskCreateMultipleTimes() { // when rule.getRuntimeService() .startProcessInstanceByKey("theProcess"); rule.getRuntimeService() .startProcessInstanceByKey("theProcess"); // then verify(condition, times(2)).signal(); }
public void signalAll() { for (SingleConsumerCondition condition : conditions) { condition.signal(); } } }