### Question:
CountDownEvent { public void await() throws InterruptedException { this.lock.lock(); try { while (this.state > 0) { this.busyCond.await(); } } finally { this.lock.unlock(); } }  Object getAttachment(); void setAttachment(final Object attachment); int incrementAndGet(); void countDown(); void await();  }### Answer:
@Test public void testAwait() throws Exception { CountDownEvent e = new CountDownEvent(); e.incrementAndGet(); e.incrementAndGet(); AtomicLong cost = new AtomicLong(0); CountDownLatch latch = new CountDownLatch(1); Utils.runInThread(new Runnable() { @Override public void run() { try { long start = System.currentTimeMillis(); e.await(); cost.set(System.currentTimeMillis() - start); } catch (Exception e) { e.printStackTrace(); } latch.countDown(); } }); Thread.sleep(1000); e.countDown(); Thread.sleep(1000); e.countDown(); latch.await(); assertEquals(2000, cost.get(), 50); }