public void Should_result_in_an_exception() { var action = MockRepository.GenerateMock<Action>(); var queue = new ThreadPoolFiber(2, 0); queue.Enqueue(action); queue.Enqueue(action); try { queue.Enqueue(action); Assert.Fail("Should have thrown an exception"); } catch (FiberException ex) { ex.Message.Contains("Insufficient").ShouldBeTrue(); } }
public void Should_prevent_new_actions_from_being_queued() { Fiber fiber = new ThreadPoolFiber(); var called = new Future<bool>(); fiber.StopAcceptingActions(); Assert.Throws<FiberException>(() => fiber.Enqueue(() => called.Complete(true))); fiber.ExecuteAll(10.Seconds()); called.IsCompleted.ShouldBeFalse(); }
public void Should_be_passable_to_another_action_queue() { Fiber fiber = new ThreadPoolFiber(); var timer = Stopwatch.StartNew(); Stopwatch inner = new Stopwatch(); Stopwatch dep = new Stopwatch(); try { using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { inner.Start(); DependentTransaction dependentClone = Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete); dependentClone.TransactionCompleted += (sender,args) => { Trace.WriteLine("Completed"); }; fiber.Enqueue(() => { dep.Start(); try { //ThreadUtil.Sleep(20.Milliseconds()); Trace.WriteLine("complieing"); dependentClone.Complete(); dep.Stop(); Trace.WriteLine("done"); } catch (Exception ex) { dependentClone.Rollback(ex); } finally { dependentClone.Dispose(); Trace.WriteLine("clone disposed"); } }); scope.Complete(); Trace.WriteLine("scope complete"); } Trace.WriteLine("all done"); } catch (Exception ex) { } inner.Stop(); timer.Stop(); Trace.WriteLine("Timer: " + (int)timer.ElapsedMilliseconds); Trace.WriteLine("Inner: " + (int)inner.ElapsedMilliseconds); Trace.WriteLine("Dep: " + (int)dep.ElapsedMilliseconds); }
public void Should_result_in_no_waiting_actions_in_the_queue() { TraceLogProvider.Configure(LogLevel.Debug); Fiber fiber = new ThreadPoolFiber(); fiber.Enqueue(() => Thread.Sleep(1000)); var called = new Future<bool>(); fiber.Enqueue(() => called.Complete(true)); fiber.ExecuteAll(8.Seconds()); called.IsCompleted.ShouldBeTrue(); }