public class WeightBarrierTest extends BaseOtterTest {
@Test
public void test_simple() {
final WeightBarrier barrier = new WeightBarrier(10);
try {
barrier.await(10);// 可以成功通过
} catch (InterruptedException e1) {
want.fail();
}
try {
final CountDownLatch count = new CountDownLatch(1);
ExecutorService executor = Executors.newCachedThreadPool();
executor.submit(new Callable() {
public Object call() throws Exception {
Thread.sleep(1000);
barrier.single(11);
count.countDown();
return null;
}
});
barrier.await(11);// 会被阻塞
count.await();
executor.shutdown();
} catch (InterruptedException e) {
want.fail();
}