Example #1
0
        protected override void OnInitialize()
        {
            Logger.Debug("OnInitialize: Enter");
            if (ProcessContext == null)
            {
                throw new AwarenessException("ProcessContext == null");
            }

            if (DatapoolManager == null)
            {
                throw new AwarenessException("DatapoolManager == null");
            }

            string scriptName = GrinderContext.GetProperty(ScriptFileKey);

            if (string.IsNullOrWhiteSpace(scriptName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Missing property '{0}'", ScriptFileKey));
            }

            Logger.Trace(x => x("OnInitialize: scriptName = {0}", scriptName));
            ScriptWorker = CSScript.Evaluator.LoadFile(scriptName);
            if (!(ScriptWorker is IGrinderWorker))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Type '{0}', from script file '{1}', does not implement '{2}'", ScriptWorker.GetType(), scriptName, typeof(IGrinderWorker).FullName));
            }

            ProcessContext.InitializeAwareness(ScriptWorker);

            ((IGrinderWorker)ScriptWorker).Initialize();

            Logger.Debug(x => x("OnInitialize: Exit, ScriptWorker = {0}", ScriptWorker.GetType().FullName));
        }
Example #2
0
        private void InitializeBinPath()
        {
            Logger.Trace("InitializeBinPath: Enter");
            string binFolder = GrinderContext.GetProperty(Constants.BinFolderKey);

            BinPath = string.IsNullOrWhiteSpace(binFolder) ? new[] { ScriptFolder } : new[] { FixDirectorySuffix(binFolder), ScriptFolder };
            Logger.Trace("InitializeBinPath: Exit");
        }
Example #3
0
        private void InitializeRandom()
        {
            IsRandom = bool.Parse(GrinderContext.GetProperty(GetPropertyKey("random"), bool.TrueString));
            if (!IsRandom)
            {
                return;
            }

            Seed   = int.Parse(GrinderContext.GetProperty(GetPropertyKey("seed"), ((int)DateTime.Now.Ticks).ToString()));
            Random = new Random(Seed);
        }
Example #4
0
        private int GetTestPrRunFromProperty()
        {
            string valueString = GrinderContext.GetProperty(Constants.VerificationWorkerTestsPrRunKey, "1");
            int    result      = int.Parse(valueString, CultureInfo.CurrentCulture);

            if (result < 1)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Property '{0}' should be > 0, but was {1}", Constants.VerificationWorkerTestsPrRunKey, result));
            }

            return(result);
        }
        public void Initialize()
        {
            if (GrinderContext == null)
            {
                throw new AwarenessException("GrinderContext == null");
            }

            Logger = new LoggerFacade(GrinderContext.GetLogger(GetType()), GrinderContext);
            Logger.Trace("Initialize: Enter");
            TypeHelper = new TypeHelper(GrinderContext);
            OnInitialize();
            Logger.Trace("Initialize: Exit");
        }
Example #6
0
        public void CreateMissingDatapoolsFromProperties()
        {
            int firstElement = GetValidFirstElement();
            int lastElement  = GetValidLastElement(firstElement);

            for (int i = firstElement; i <= lastElement; i++)
            {
                string datapoolName = GrinderContext.GetProperty(GetFactoryPropertyKey(i.ToString()));
                if (!string.IsNullOrWhiteSpace(datapoolName))
                {
                    CreateMissingDatapoolFromProperties(datapoolName);
                }
            }
        }
Example #7
0
        private void InitializeDebugger()
        {
            Logger.Trace("InitializeDebugger: Enter");

            if (bool.Parse(GrinderContext.GetProperty(Constants.LaunchDebuggerKey, bool.FalseString)))
            {
                Logger.Trace("InitializeDebugger: Launching debugger...");
                System.Diagnostics.Debugger.Launch();
            }
            else
            {
                Logger.Trace("InitializeDebugger: Not launching debugger...");
            }

            Logger.Trace("InitializeDebugger: Exit");
        }
Example #8
0
        private void AddWorkerToCollectionByLoadFactor(int index)
        {
            string workerTypeName = GrinderContext.GetProperty(GetElementPropertyKey(index, "workerType"));

            if (!string.IsNullOrWhiteSpace(workerTypeName))
            {
                int loadFactor = GetIntProperty(GetElementPropertyKey(index, "loadFactor"), 1);
                Logger.Info(m => m("AddWorkerToCollectionByLoadFactor: Index = {0}, WorkerType = '{1}', LoadFactor = {2}", index, workerTypeName, loadFactor));
                for (int i = 0; i < loadFactor; i++)
                {
                    workers.Add(TypeHelper.CreateTargetTypeFromName <IGrinderWorker>(workerTypeName));
                }
            }
            else
            {
                Logger.Trace(m => m("AddWorkerToCollectionByLoadFactor: Property '{0}' not set", GetElementPropertyKey(index, "workerType")));
            }
        }
Example #9
0
        public void Run()
        {
            if (Metadata.BeforeTestAction != null)
            {
                Metadata.BeforeTestAction();
            }

            Underlying.Run();

            if (Metadata.SleepMillis > 0)
            {
                GrinderContext.Sleep(Metadata.SleepMillis);
            }

            if (Metadata.AfterTestAction != null)
            {
                Metadata.AfterTestAction();
            }
        }
Example #10
0
        public void CreateDatapool <T>(IDatapoolValuesFactory <T> datapoolValuesFactory, string name) where T : class
        {
            if (datapoolValuesFactory == null)
            {
                throw new ArgumentNullException("datapoolValuesFactory");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            IList <T> values            = datapoolValuesFactory.CreateValues(GrinderContext, name);
            bool      isRandom          = bool.Parse(GrinderContext.GetProperty(GetPropertyKey(name, "random"), bool.FalseString));
            int       seed              = int.Parse(GrinderContext.GetProperty(GetPropertyKey(name, "seed"), ((int)DateTime.Now.Ticks).ToString()));
            var       distributionMode  = (DatapoolThreadDistributionMode)Enum.Parse(typeof(DatapoolThreadDistributionMode), GrinderContext.GetProperty(GetPropertyKey(name, "distributionMode"), DatapoolThreadDistributionMode.ThreadShared.ToString()), false);
            bool      isCircular        = bool.Parse(GrinderContext.GetProperty(GetPropertyKey(name, "circular"), bool.TrueString));
            var       datapoolMetatdata = new DefaultDatapoolMetadata <T>(values, isRandom, seed, distributionMode, isCircular, name);

            CreateDatapool(datapoolMetatdata);
        }
Example #11
0
        private int GetIntProperty(string key, int defaultValue)
        {
            string valueString = GrinderContext.GetProperty(key, defaultValue.ToString(CultureInfo.InvariantCulture));

            return(int.Parse(valueString, CultureInfo.CurrentCulture));
        }
Example #12
0
 public Repository(GrinderContext context)
 {
     db    = context;
     dbSet = context.Set <T>();
 }