Ejemplo n.º 1
0
        public OrStepInstance(ProfileInstance profileInstance, StepInstance parentStepInstance, OrStep step)
            : base(profileInstance, parentStepInstance, step)
        {
            const string method = ".ctor";

            var currentPercentage = 0;
            var enabledSteps      = 0;

            foreach (var childStep in step)
            {
                currentPercentage += childStep.Percentage * 100;
                if (childStep.Enabled)
                {
                    ++enabledSteps;
                }

                _percentages.Add(currentPercentage);
            }

            // Check the percentages.

            if (currentPercentage != 10000)
            {
                throw new InvalidConfigurationValueException(GetType(), method, "percentage", currentPercentage / 100);
            }
            if (enabledSteps == 0)
            {
                throw new InvalidConfigurationValueException(GetType(), method, "enabled", false);
            }
        }
Ejemplo n.º 2
0
 protected StepInstance(ProfileInstance profileInstance, StepInstance parentStepInstance, Step step)
 {
     _profileInstance    = profileInstance;
     _parentStepInstance = parentStepInstance;
     _enabled            = step.Enabled;
     _iterations         = step.Iterations.Next;
 }
Ejemplo n.º 3
0
 public ComponentStepInstance(ProfileInstance profileInstance, StepInstance parentStepInstance, ComponentStep step, MethodInfo beginMethodInfo, MethodInfo endMethodInfo, StepCounters counters)
     : base(profileInstance, parentStepInstance, step)
 {
     _name            = step.Name;
     _beginMethodInfo = beginMethodInfo;
     _endMethodInfo   = endMethodInfo;
     _delay           = step.Delay;
     _counters        = counters;
 }
Ejemplo n.º 4
0
        private void StartIteration(ProfileInstance instance)
        {
            const string method = "StartIteration";

            if (EventSource.IsEnabled(Event.FlowEnter))
            {
                EventSource.Raise(Event.FlowEnter, method, "Starting profile '" + instance.Profile + "' for user " + instance.User + ".", Event.Arg("Profile", instance.Profile.Name), Event.Arg("User", instance.User));
            }

            var stopping = false;

            switch (WaitHandle.WaitAny(_pauseSignals, 0))
            {
            case 0:

                // Stopping.

                stopping = true;
                break;

            case 1:

                // Paused, wait for it to start again.

                switch (WaitHandle.WaitAny(_continueSignals))
                {
                case 0:

                    // Stopping.

                    stopping = true;
                    break;

                case 1:

                    // Continuing.

                    break;
                }

                break;

            case WaitHandle.WaitTimeout:

                break;
            }

            if (!stopping)
            {
                instance.SetUp();
                instance.StartTracking();
                Run(instance);
            }
        }
Ejemplo n.º 5
0
        private static void StopIteration(ProfileInstance instance, Exception ex)
        {
            const string method = "StopIteration";

            if (EventSource.IsEnabled(Event.Error))
            {
                EventSource.Raise(Event.Error, method, "An error has occurred trying to run a step.", ex);
            }

            instance.TrackError();
            instance.TearDown();
        }
Ejemplo n.º 6
0
        private static void StopIteration(ProfileInstance instance)
        {
            const string method = "StopIteration";

            instance.StopTracking();
            instance.TearDown();

            if (EventSource.IsEnabled(Event.FlowExit))
            {
                EventSource.Raise(Event.FlowExit, method, "Profile '" + instance.Profile + "' has ended for user " + instance.User + ".", Event.Arg("Profile", instance.Profile.Name), Event.Arg("User", instance.User));
            }
        }
Ejemplo n.º 7
0
        private void Run(ProfileInstance instance)
        {
            const string method = "Run";

            if (EventSource.IsEnabled(Event.MethodEnter))
            {
                EventSource.Raise(Event.MethodEnter, method);
            }

            for (; ;)
            {
                // Ask the current step for the next step.

                var nextStep = instance.CurrentStep.GetNextStep();
                if (nextStep == null)
                {
                    StopIteration(instance);

                    // All steps have been run, so start another.

                    StartIteration(instance.User);
                    break;
                }

                if (!_stopSignal.WaitOne(0))
                {
                    if (EventSource.IsEnabled(Event.Trace))
                    {
                        EventSource.Raise(Event.Trace, method, "Next step for user.", Event.Arg("Profile", instance.Profile), Event.Arg("User", instance.User), Event.Arg("CurrentStep", instance.CurrentStep), Event.Arg("Step", nextStep.Name));
                    }

                    instance.CurrentStep = nextStep;

                    // Always delay, even if it doesn't need to simply to make sure that
                    // another thread is used and stack overflow does not happen.

                    Delay(nextStep);
                    break;
                }
            }

            if (EventSource.IsEnabled(Event.MethodExit))
            {
                EventSource.Raise(Event.MethodExit, method);
            }
        }
Ejemplo n.º 8
0
        public void StartIteration(int user)
        {
            // Need to choose a profile to run for this instance.
            // Keep going until an enabled profile is chosen, there should be at least one.

            for (; ;)
            {
                var percentage = _random.Next(0, 10000);
                var index      = 0;
                for (; index < _profileData.Count; ++index)
                {
                    var data = _profileData[index];
                    if (percentage < data.Percentage)
                    {
                        // Create an instance.

                        var profile = data.Profile;
                        if (profile.Runnable)
                        {
                            var instance = new ProfileInstance(profile, data.Counters, user, _users);

                            // Only start another iteration if no maximum has been specified or if that maximum has not yet been reached.

                            if (profile.Iterations == 0 || data.IncrementIteration() <= profile.Iterations)
                            {
                                StartIteration(instance);
                            }
                            return;
                        }

                        // Not enabled so try again.

                        break;
                    }
                }
            }
        }
Ejemplo n.º 9
0
 protected StepInstanceList(ProfileInstance profileInstance, StepInstance parentStepInstance, Step step)
     : base(profileInstance, parentStepInstance, step)
 {
 }
Ejemplo n.º 10
0
 public AndStepInstance(ProfileInstance profileInstance, StepInstance parentStepInstance, AndStep step)
     : base(profileInstance, parentStepInstance, step)
 {
 }