public void TestExecutivePauseResume() { DateTime startTime; System.Threading.Thread starter, pauser; IExecutive exec = ExecFactory.Instance.CreateExecutive(); InstrumentExecutiveStates(exec); // First get the duration w/o pause. startTime = DateTime.Now; starter = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(StartExec)); starter.Start(exec); starter.Join(); TimeSpan shortDuration = DateTime.Now - startTime; Debug.WriteLine("Duration w/o pause is " + shortDuration.TotalSeconds + " seconds."); exec.Reset(); // Now get the duration w/ pause. startTime = DateTime.Now; starter = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(StartExec)); pauser = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(PauseAndResumeExec)); starter.Start(exec); pauser.Start(exec); starter.Join(); TimeSpan pauseDuration = DateTime.Now - startTime; // Finally, assess the comparative durations to ensure the test passed. Debug.WriteLine("Total test duration was " + pauseDuration.TotalSeconds + " seconds."); TimeSpan minAcceptableDuration = shortDuration + TimeSpan.FromMilliseconds(1500); Assert.IsTrue(pauseDuration > minAcceptableDuration, "Test duration of less than " + minAcceptableDuration.TotalSeconds + " seconds indicates a failure to properly stop and restart."); }
public static void Run() { RandomServer rs = null; IExecutive exec = null; Activity fooActivity = null; Activity barActivity = null; int defaultBufferSize = 100; foreach (ulong hyperSeed in new ulong[] { 87654, 23456 }) { Console.WriteLine("Test with hyperSeed of {0}.", hyperSeed); rs = new RandomServer(hyperSeed, defaultBufferSize); exec = ExecFactory.Instance.CreateExecutive(); fooActivity = new Activity("fooActivity", 5, exec, rs, 12345); barActivity = new Activity("barActivity", 6, exec, rs, 10558); exec.Start(); } ulong _hyperSeed = 24680; Console.WriteLine("Test with hyperSeed of {0}. First, with no interference:", _hyperSeed); rs = new RandomServer(_hyperSeed, defaultBufferSize); exec = ExecFactory.Instance.CreateExecutive(); fooActivity = new Activity("fooActivity", 5, exec, rs, 12345); barActivity = new Activity("barActivity", 6, exec, rs, 10558); exec.Start(); exec.Reset(); Console.WriteLine("Test with hyperSeed of {0}. This time, we interfere with Bobby:", _hyperSeed); rs = new RandomServer(_hyperSeed, defaultBufferSize); exec = ExecFactory.Instance.CreateExecutive(); fooActivity = new Activity("fooActivity", 5, exec, rs, 12345); barActivity = new Activity("barActivity", 6, exec, rs, 10558); DateTime when = DateTime.Parse("1/1/0001 7:13:29 AM"); exec.RequestEvent( delegate(IExecutive _exec, object userData) { Console.WriteLine("{0} : Doubling barActivity's multiplier.", _exec.Now); barActivity.Multiplier = 2.0; }, when); exec.Start(); }
public static void Run() { IExecutive exec = ExecFactory.Instance.CreateExecutive(); exec.ExecutiveStarted += ExecStarted; // Allows you to register handler on every Run invocation. Else // second run invocation would result in two handlers, third, etc. exec.ExecutiveStarted_SingleShot += ExecStarted_SingleShot; Console.WriteLine("Starting the simulation. Executive is in state {0}.", exec.State); exec.Start(); Console.WriteLine("\r\nSimulation done. Executive is in state {0}.", exec.State); exec.Reset(); Console.WriteLine("\r\nReset the simulation. Executive is in state {0}.", exec.State); Console.WriteLine("\r\nRe-running the simulation. Executive is in state {0}.", exec.State); exec.Start(); }
public virtual void Reset() { if (s_diagnostics) { _Debug.WriteLine("Model.Reset() requested."); } if (IsCompleted) { IsRunning = false; IsReady = true; IsPaused = false; IsCompleted = false; } Exec.Reset(); Debug.Assert(Exec.State.Equals(ExecState.Stopped)); m_stateMachine.DoTransition(GetIdleEnum()); Debug.Assert(m_stateMachine.State.Equals(GetIdleEnum())); Resetting?.Invoke(this); }
private void InitTest() { m_tsut = new Exchange(m_exec); m_results = new ArrayList(); m_exec.Reset(); }