private void checkSystemStateMethods(int enterCount) throws Exception { thread1.callAndAssertReturns(enterCount != 0, "isOccupied"); thread1.callAndAssertReturns(enterCount != 0, "isOccupiedByCurrentThread"); thread1.callAndAssertReturns(enterCount, "getOccupiedDepth"); thread2.callAndAssertReturns(enterCount != 0, "isOccupied"); thread2.callAndAssertReturns(false, "isOccupiedByCurrentThread"); thread2.callAndAssertReturns(0, "getOccupiedDepth"); }
public final void testTryEnter() throws Exception { thread1.callAndAssertReturns(true, tryEnter()); thread2.callAndAssertReturns(false, tryEnter()); thread1.callAndAssertReturns(true, tryEnter()); thread2.callAndAssertReturns(false, tryEnter()); thread1.callAndAssertReturns(leave()); thread2.callAndAssertReturns(false, tryEnter()); thread1.callAndAssertReturns(leave()); thread2.callAndAssertReturns(true, tryEnter()); }
public final void testTryEnterIf_initiallyFalse() throws Exception { TestGuard guard = new TestGuard(false); thread1.callAndAssertReturns(false, tryEnterIf(), guard); thread2.callAndAssertReturns(enter()); }
public final void testTryEnterIf_alreadyOccupied() throws Exception { TestGuard guard = new TestGuard(true); thread2.callAndAssertReturns(enter()); thread1.callAndAssertReturns(false, tryEnterIf(), guard); }
public final void testEnterIf_initiallyFalse() throws Exception { TestGuard guard = new TestGuard(false); thread1.callAndAssertReturns(false, enterIf(), guard); thread2.callAndAssertReturns(enter()); }
public final void testWaitFor_initiallyTrue() throws Exception { TestGuard guard = new TestGuard(true); thread1.callAndAssertReturns(enter()); thread1.callAndAssertReturns(waitFor(), guard); }
public final void testEnterWhen_initiallyTrue() throws Exception { TestGuard guard = new TestGuard(true); thread1.callAndAssertReturns(enterWhen(), guard); // same as above but with the new syntax thread1.callAndAssertReturns(enterWhen(), monitor.newGuard(() -> true)); }
public final void testSystemStateMethods() throws Exception { checkSystemStateMethods(0); thread1.callAndAssertReturns(enter()); checkSystemStateMethods(1); thread1.callAndAssertReturns(enter()); checkSystemStateMethods(2); thread1.callAndAssertReturns(leave()); checkSystemStateMethods(1); thread1.callAndAssertReturns(leave()); checkSystemStateMethods(0); }
public final void testMutualExclusion() throws Exception { thread1.callAndAssertReturns(enter()); thread2.callAndAssertBlocks(enter()); thread1.callAndAssertReturns(leave()); thread2.assertPriorCallReturns(enter()); }
public final void testEnterWhen_alreadyOccupied() throws Exception { TestGuard guard = new TestGuard(true); thread2.callAndAssertReturns(enter()); thread1.callAndAssertBlocks(enterWhen(), guard); thread2.callAndAssertReturns(leave()); thread1.assertPriorCallReturns(enterWhen()); }
public final void testEnterIf_alreadyOccupied() throws Exception { TestGuard guard = new TestGuard(true); thread2.callAndAssertReturns(enter()); thread1.callAndAssertBlocks(enterIf(), guard); thread2.callAndAssertReturns(leave()); thread1.assertPriorCallReturns(true, enterIf()); }
public final void testEnterIf_initiallyTrue() throws Exception { TestGuard guard = new TestGuard(true); thread1.callAndAssertReturns(true, enterIf(), guard); thread2.callAndAssertBlocks(enter()); }
public final void testTryEnterIf_initiallyTrue() throws Exception { TestGuard guard = new TestGuard(true); thread1.callAndAssertReturns(true, tryEnterIf(), guard); thread2.callAndAssertBlocks(enter()); }
public final void testWaitFor_initiallyFalse() throws Exception { TestGuard guard = new TestGuard(false); thread1.callAndAssertReturns(enter()); thread1.callAndAssertWaits(waitFor(), guard); monitor.enter(); guard.setSatisfied(true); monitor.leave(); thread1.assertPriorCallReturns(waitFor()); }
public final void testEnterIf_initiallyFalse() throws Exception { TestGuard guard = new TestGuard(false); thread1.callAndAssertReturns(false, enterIf(), guard); thread2.callAndAssertReturns(enter()); }
public final void testWaitFor_initiallyTrue() throws Exception { TestGuard guard = new TestGuard(true); thread1.callAndAssertReturns(enter()); thread1.callAndAssertReturns(waitFor(), guard); }
public final void testEnterWhen_initiallyTrue() throws Exception { TestGuard guard = new TestGuard(true); thread1.callAndAssertReturns(enterWhen(), guard); // same as above but with the new syntax thread1.callAndAssertReturns(enterWhen(), monitor.newGuard(() -> true)); }
public final void testEnterWhen_alreadyOccupied() throws Exception { TestGuard guard = new TestGuard(true); thread2.callAndAssertReturns(enter()); thread1.callAndAssertBlocks(enterWhen(), guard); thread2.callAndAssertReturns(leave()); thread1.assertPriorCallReturns(enterWhen()); }
public final void testEnterIf_alreadyOccupied() throws Exception { TestGuard guard = new TestGuard(true); thread2.callAndAssertReturns(enter()); thread1.callAndAssertBlocks(enterIf(), guard); thread2.callAndAssertReturns(leave()); thread1.assertPriorCallReturns(true, enterIf()); }
public final void testTryEnterIf_initiallyTrue() throws Exception { TestGuard guard = new TestGuard(true); thread1.callAndAssertReturns(true, tryEnterIf(), guard); thread2.callAndAssertBlocks(enter()); }