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(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); }
@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(timeout=10000) public void shouldNotBlockIfSignalAvailable() { SingleConsumerCondition condition = new SingleConsumerCondition(Thread.currentThread()); // given condition.signal(); // then condition.await(100000); }
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(); } } }
@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); }
@Test(timeout=10000) public void shouldNotBlockIfSignalAvailable() { SingleConsumerCondition condition = new SingleConsumerCondition(Thread.currentThread()); // given condition.signal(); // then condition.await(100000); }
@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 } }