109110111112113114115116117118119
try { FailoverValve valve = new FailoverValve (); valve.enter(); valve.leave(); valve.leave(); // extra leave call, should throw an exception fail("Valve.close didn't generate an exception, Valve is not safe!"); } catch (Throwable e) {
110111112113114115116117118119120
try { FailoverValve valve = new FailoverValve (); valve.enter(); valve.leave(); valve.leave(); // extra leave call, should throw an exception fail("Valve.close didn't generate an exception, Valve is not safe!"); } catch (Throwable e) { //e.printStackTrace();
152153154155156157158159160161162
// valve cannot be closed at this time Object o = slot.poll(5000); assertNull(o); // exit the valve valve.leave(); o = slot.take(); assertNotNull(o); assertEquals("CLOSED", o); }
166167168169170171172173174175176
final Slot slot = new Slot(); // flip-flop the valve valve.enter(); valve.leave(); new Thread(new Runnable() { public void run() {
247248249250251252253254255256257
Object o = slot[i].peek(); assertNull(o); } log.info("leaving the valve"); valve.leave(); // the valve should be "closeable", so all waiting threads, plus a new one, should be able // to close it final Slot loneSlot = new Slot();