public void ResetLeakage() //TODO: didn't understand test name and description; copied from Java -K.X. { CyclicBarrier c = new CyclicBarrier(2); AtomicBoolean done = new AtomicBoolean(); Thread t = ThreadManager.StartAndAssertRegistered( "T1", delegate { while (!done.Value) { while (c.IsBroken) { c.Reset(); } var e = Assert.Catch(() => c.Await()); Assert.That(e, Is.InstanceOf <BrokenBarrierException>() .Or.InstanceOf <ThreadInterruptedException>()); } }); for (int i = 0; i < 4; i++) { Thread.Sleep(Delays.Short); t.Interrupt(); } done.Value = true; t.Interrupt(); ThreadManager.JoinAndVerify(); }
public void ResetReinitializeBarrierAfterExceptionInBarrierAction() { var e = new NullReferenceException(); CyclicBarrier start = new CyclicBarrier(3); CyclicBarrier barrier = new CyclicBarrier(3, () => { throw e; }); ThreadStart action = delegate { start.Await(); Assert.Catch <BrokenBarrierException>(() => barrier.Await()); }; for (int i = 0; i < 2; i++) { ThreadManager.StartAndAssertRegistered("T" + i + "-", action, action); start.Await(); while (barrier.NumberOfWaitingParties < 2) { Thread.Sleep(1); } Assert.That(Assert.Catch(() => barrier.Await()), Is.SameAs(e)); ThreadManager.JoinAndVerify(); Assert.IsTrue(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); barrier.Reset(); Assert.IsFalse(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); } }
public void ResetReinitializeBarrierAfterTimeout() { CyclicBarrier start = new CyclicBarrier(3); CyclicBarrier barrier = new CyclicBarrier(3); for (int i = 0; i < 2; i++) { ThreadManager.StartAndAssertRegistered( "T" + i + "-", delegate { start.Await(); Assert.Catch <TimeoutException>(() => barrier.Await(Delays.Short)); }, delegate { start.Await(); Assert.Catch <BrokenBarrierException>(() => barrier.Await()); }); start.Await(); ThreadManager.JoinAndVerify(); Assert.IsTrue(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); barrier.Reset(); Assert.IsFalse(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); } }
public void PartiesReturnsTheValueGiveinInConstructor([Values(1, 5)] int parties) { CyclicBarrier b = new CyclicBarrier(parties); Assert.AreEqual(parties, b.Parties); Assert.AreEqual(0, b.NumberOfWaitingParties); }
public void AwaitChokesWhenTimeOut() { CyclicBarrier c = new CyclicBarrier(2); ThreadManager.StartAndAssertRegistered( "T", () => Assert.Throws<TimeoutException>(() => c.Await(Delays.Short))); ThreadManager.JoinAndVerify(); }
public void AwaitChokesWhenTimeOut() { CyclicBarrier c = new CyclicBarrier(2); ThreadManager.StartAndAssertRegistered( "T", () => Assert.Throws <TimeoutException>(() => c.Await(Delays.Short))); ThreadManager.JoinAndVerify(); }
public void ResetBreaksBarrierWhenTheadWaiting([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(3); ThreadStart action = () => Assert.Throws <BrokenBarrierException>(() => AwaitOrTimedAwait(isTimed, c)); ThreadManager.StartAndAssertRegistered("T", action, action); Thread.Sleep(Delays.Short); c.Reset(); ThreadManager.JoinAndVerify(); }
public void TimeoutAwaitBreaksBarrier([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(3); ThreadManager.StartAndAssertRegistered( "T1", () => Assert.Throws <TimeoutException>(() => c.Await(Delays.Short))); ThreadManager.StartAndAssertRegistered( "T2", () => Assert.Throws <BrokenBarrierException>(() => AwaitOrTimedAwait(isTimed, c))); ThreadManager.JoinAndVerify(); }
public void ResetDoesNotBreakBarrierWhenNoThreadWaiting([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(3); ThreadStart action = () => AwaitOrTimedAwait(isTimed, c); c.Reset(); ThreadManager.StartAndAssertRegistered("T", action, action, action); ThreadManager.JoinAndVerify(); }
private static void AwaitOrTimedAwait(bool isTimed, CyclicBarrier c) { if (isTimed) { c.Await(Delays.Long); } else { c.Await(); } }
public void InterruptedAwaitBreaksBarrier([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(3); Thread t1 = ThreadManager.StartAndAssertRegistered( "T1", () => Assert.Throws<ThreadInterruptedException>(() => AwaitOrTimedAwait(isTimed, c))); ThreadManager.StartAndAssertRegistered( "T2", () => Assert.Throws<BrokenBarrierException>(() => AwaitOrTimedAwait(isTimed, c))); Thread.Sleep(Delays.Short); t1.Interrupt(); ThreadManager.JoinAndVerify(); }
public void AwaitChokesOnBrokenBarrier([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(2); ThreadManager.StartAndAssertRegistered( "T1", delegate { Assert.Throws<TimeoutException>(() => c.Await(Delays.Short)); Assert.Throws<BrokenBarrierException>(() => AwaitOrTimedAwait(isTimed, c)); }); ThreadManager.JoinAndVerify(); }
public void SuppliedRunnableIsRunAtBarries() { var runnable = MockRepository.GenerateStub <IRunnable>(); CyclicBarrier b = new CyclicBarrier(1, runnable); Assert.AreEqual(1, b.Parties); Assert.AreEqual(0, b.NumberOfWaitingParties); b.Await(); b.Await(); Assert.AreEqual(0, b.NumberOfWaitingParties); runnable.AssertWasCalled(r => r.Run(), m => m.Repeat.Twice()); }
public void SuppliedActionIsRunAtBarries() { var action = MockRepository.GenerateStub <Action>(); CyclicBarrier b = new CyclicBarrier(1, action); Assert.AreEqual(1, b.Parties); Assert.AreEqual(0, b.NumberOfWaitingParties); b.Await(); b.Await(Delays.Small); Assert.AreEqual(0, b.NumberOfWaitingParties); action.AssertWasCalled(a => a(), m => m.Repeat.Twice()); }
public void AwaitChokesOnBrokenBarrier([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(2); ThreadManager.StartAndAssertRegistered( "T1", delegate { Assert.Throws <TimeoutException>(() => c.Await(Delays.Short)); Assert.Throws <BrokenBarrierException>(() => AwaitOrTimedAwait(isTimed, c)); }); ThreadManager.JoinAndVerify(); }
public void InterruptedAwaitBreaksBarrier([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(3); Thread t1 = ThreadManager.StartAndAssertRegistered( "T1", () => Assert.Throws <ThreadInterruptedException>(() => AwaitOrTimedAwait(isTimed, c))); ThreadManager.StartAndAssertRegistered( "T2", () => Assert.Throws <BrokenBarrierException>(() => AwaitOrTimedAwait(isTimed, c))); Thread.Sleep(Delays.Short); t1.Interrupt(); ThreadManager.JoinAndVerify(); }
public void TwoPartieBarrierTriggersAfterBothInvokeAwait() { CyclicBarrier b = new CyclicBarrier(2); ThreadStart action = () => { b.Await(); b.Await(Delays.Small); b.Await(); b.Await(Delays.Small); }; ThreadManager.StartAndAssertRegistered("T", action, action); ThreadManager.JoinAndVerify(); }
public void SinglePartyBarrierTriggersAfterSingleAwait([Values(true, false)] bool isTimed) { CyclicBarrier b = new CyclicBarrier(1); Assert.AreEqual(1, b.Parties); Assert.AreEqual(0, b.NumberOfWaitingParties); if (isTimed) { b.Await(Delays.Small); b.Await(Delays.Small); } else { b.Await(); b.Await(); } Assert.AreEqual(0, b.NumberOfWaitingParties); }
public void ResetSucceedsOnNonBrokenBarrier() { CyclicBarrier start = new CyclicBarrier(3); CyclicBarrier barrier = new CyclicBarrier(3); ThreadStart action = () => { start.Await(); barrier.Await(); }; for (int i = 0; i < 3; i++) { ThreadManager.StartAndAssertRegistered("T" + i + "-", action, action); start.Await(); barrier.Await(); ThreadManager.JoinAndVerify(); Assert.IsFalse(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); if (i == 1) { barrier.Reset(); } Assert.IsFalse(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); } }
public void ResetReinitializeBarrierAfterExceptionInBarrierAction() { var e = new NullReferenceException(); CyclicBarrier start = new CyclicBarrier(3); CyclicBarrier barrier = new CyclicBarrier(3, () => { throw e; }); ThreadStart action = delegate { start.Await(); Assert.Catch<BrokenBarrierException>(() => barrier.Await()); }; for (int i = 0; i < 2; i++) { ThreadManager.StartAndAssertRegistered("T" + i + "-", action, action); start.Await(); while (barrier.NumberOfWaitingParties < 2) { Thread.Sleep(1); } Assert.That(Assert.Catch(()=>barrier.Await()), Is.SameAs(e)); ThreadManager.JoinAndVerify(); Assert.IsTrue(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); barrier.Reset(); Assert.IsFalse(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); } }
public void ResetReinitializeBarrierAfterTimeout() { CyclicBarrier start = new CyclicBarrier(3); CyclicBarrier barrier = new CyclicBarrier(3); for (int i = 0; i < 2; i++) { ThreadManager.StartAndAssertRegistered( "T" + i + "-", delegate { start.Await(); Assert.Catch<TimeoutException>(() => barrier.Await(Delays.Short)); }, delegate { start.Await(); Assert.Catch<BrokenBarrierException>(() => barrier.Await()); }); start.Await(); ThreadManager.JoinAndVerify(); Assert.IsTrue(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); barrier.Reset(); Assert.IsFalse(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); } }
public void ResetSucceedsOnNonBrokenBarrier() { CyclicBarrier start = new CyclicBarrier(3); CyclicBarrier barrier = new CyclicBarrier(3); ThreadStart action = () => { start.Await(); barrier.Await(); }; for (int i = 0; i < 3; i++) { ThreadManager.StartAndAssertRegistered("T" + i + "-", action, action); start.Await(); barrier.Await(); ThreadManager.JoinAndVerify(); Assert.IsFalse(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); if (i == 1) barrier.Reset(); Assert.IsFalse(barrier.IsBroken); Assert.AreEqual(0, barrier.NumberOfWaitingParties); } }
internal NACalibrationLoop(long endTime, NonAtomicInteger obj, CyclicBarrier b) { this.endTime = endTime; this.obj = obj; this.barrier = b; obj.set_Renamed(CASLoops.rng.next()); }
internal static long runVolatile(int n, long iters) { LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer(); CyclicBarrier b = new CyclicBarrier(n + 1, timer); VolatileInteger a = new VolatileInteger(); for (int j = 0; j < n; ++j) new SupportClass.ThreadClass(new System.Threading.ThreadStart(new VolatileLoop(iters, a, b).Run)).Start(); b.Await(); b.Await(); if (sum.Value == 0) System.Console.Out.Write(" "); return timer.Time; }
public void TimeoutAwaitBreaksBarrier([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(3); ThreadManager.StartAndAssertRegistered( "T1", () => Assert.Throws<TimeoutException>(()=>c.Await(Delays.Short))); ThreadManager.StartAndAssertRegistered( "T2", () => Assert.Throws<BrokenBarrierException>(() => AwaitOrTimedAwait(isTimed, c))); ThreadManager.JoinAndVerify(); }
private static void AwaitOrTimedAwait(bool isTimed, CyclicBarrier c) { if (isTimed) c.Await(Delays.Long); else c.Await(); }
public void ResetLeakage() { CyclicBarrier c = new CyclicBarrier(2); AtomicBoolean done = new AtomicBoolean(); Thread t = ThreadManager.StartAndAssertRegistered( "T1", delegate { while (!done.Value) { while (c.IsBroken) c.Reset(); var e = Assert.Catch(() => c.Await()); Assert.That(e, Is.InstanceOf<BrokenBarrierException>() .Or.InstanceOf<ThreadInterruptedException>()); } }); for (int i = 0; i < 4; i++) { Thread.Sleep(Delays.Short); t.Interrupt(); } done.Value = true; t.Interrupt(); ThreadManager.JoinAndVerify(); }
internal SynchedLoop(long iters, SynchedInteger obj, CyclicBarrier b) { this.iters = iters; this.obj = obj; this.barrier = b; obj.set_Renamed(CASLoops.rng.next()); }
public void PartiesReturnsTheValueGiveinInConstructor([Values(1,5)] int parties) { CyclicBarrier b = new CyclicBarrier(parties); Assert.AreEqual(parties, b.Parties); Assert.AreEqual(0, b.NumberOfWaitingParties); }
public void SuppliedRunnableIsRunAtBarries() { var runnable = MockRepository.GenerateStub<IRunnable>(); CyclicBarrier b = new CyclicBarrier(1, runnable); Assert.AreEqual(1, b.Parties); Assert.AreEqual(0, b.NumberOfWaitingParties); b.Await(); b.Await(); Assert.AreEqual(0, b.NumberOfWaitingParties); runnable.AssertWasCalled(r => r.Run(), m => m.Repeat.Twice()); }
internal static void runCalibration(int n, long nms) { long now = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; long endTime = now + nms; CyclicBarrier b = new CyclicBarrier(n + 1); totalIters.Value = (0); NonAtomicInteger a = new NonAtomicInteger(); for (int j = 0; j < n; ++j) new SupportClass.ThreadClass(new System.Threading.ThreadStart(new NACalibrationLoop(endTime, a, b).Run)).Start(); b.Await(); b.Await(); long ipt = totalIters.Value / n; if (ipt > loopIters[n]) loopIters[n] = ipt; if (sum.Value == 0) System.Console.Out.Write(" "); }
public void SuppliedActionIsRunAtBarries() { var action = MockRepository.GenerateStub<Action>(); CyclicBarrier b = new CyclicBarrier(1, action); Assert.AreEqual(1, b.Parties); Assert.AreEqual(0, b.NumberOfWaitingParties); b.Await(); b.Await(Delays.Small); Assert.AreEqual(0, b.NumberOfWaitingParties); action.AssertWasCalled(a => a(), m => m.Repeat.Twice()); }
internal AtomicLoop(long iters, AtomicInteger obj, CyclicBarrier b) { this.iters = iters; this.obj = obj; this.barrier = b; obj.Value = (CASLoops.rng.next()); }
internal NonAtomicLoop(long iters, NonAtomicInteger obj, CyclicBarrier b) { this.iters = iters; this.obj = obj; this.barrier = b; obj.set_Renamed(CASLoops.rng.next()); }
public void ResetBreaksBarrierWhenTheadWaiting([Values(true, false)] bool isTimed) { CyclicBarrier c = new CyclicBarrier(3); ThreadStart action = () => Assert.Throws<BrokenBarrierException>(() => AwaitOrTimedAwait(isTimed, c)); ThreadManager.StartAndAssertRegistered("T", action, action); Thread.Sleep(Delays.Short); c.Reset(); ThreadManager.JoinAndVerify(); }
internal VolatileLoop(long iters, VolatileInteger obj, CyclicBarrier b) { this.iters = iters; this.obj = obj; this.barrier = b; obj.set_Renamed(CASLoops.rng.next()); }