internal T NextValue(IGrinderContext grinderContext) { T result = null; spinLocked.DoLocked(() => { NextOffset++; if (NextOffset > EndOffset) { if (!IsCircular) { throw new IllegalStateException(string.Format( CultureInfo.CurrentCulture, "Non circular {0}thread unique datapool '{1}' is drained: Agent number '{2}', process number '{3}' ({4}), thread number '{5}', run number '{6}'", IsThreadUnique ? string.Empty : "non ", Name, grinderContext.AgentNumber, grinderContext.ProcessNumber, grinderContext.ProcessName, grinderContext.ThreadNumber, grinderContext.RunNumber )); } NextOffset = StartOffset; } result = Values[NextOffset]; }); return(result); }
private void SetupLoggerEnabledValueResolvers(IGrinderContext grinderContext) { long loggerEnableCacheTtl = long.Parse(grinderContext.GetProperty(Constants.LoggerEnabledCacheTtlKey, "-1")); if (loggerEnableCacheTtl < 0) { IsErrorEnabledResolver = new ValueResolverOnce <bool>(() => underlying.IsErrorEnabled); IsWarnEnabledResolver = new ValueResolverOnce <bool>(() => underlying.IsWarnEnabled); IsInfoEnabledResolver = new ValueResolverOnce <bool>(() => underlying.IsInfoEnabled); IsDebugEnabledResolver = new ValueResolverOnce <bool>(() => underlying.IsDebugEnabled); IsTraceEnabledResolver = new ValueResolverOnce <bool>(() => underlying.IsTraceEnabled); } else if ((loggerEnableCacheTtl == 0)) { IsErrorEnabledResolver = new ValueResolverAlways <bool>(() => underlying.IsErrorEnabled); IsWarnEnabledResolver = new ValueResolverAlways <bool>(() => underlying.IsWarnEnabled); IsInfoEnabledResolver = new ValueResolverAlways <bool>(() => underlying.IsInfoEnabled); IsDebugEnabledResolver = new ValueResolverAlways <bool>(() => underlying.IsDebugEnabled); IsTraceEnabledResolver = new ValueResolverAlways <bool>(() => underlying.IsTraceEnabled); } else { IsErrorEnabledResolver = new ValueResolverTimed <bool>(() => underlying.IsErrorEnabled, loggerEnableCacheTtl); IsWarnEnabledResolver = new ValueResolverTimed <bool>(() => underlying.IsWarnEnabled, loggerEnableCacheTtl); IsInfoEnabledResolver = new ValueResolverTimed <bool>(() => underlying.IsInfoEnabled, loggerEnableCacheTtl); IsDebugEnabledResolver = new ValueResolverTimed <bool>(() => underlying.IsDebugEnabled, loggerEnableCacheTtl); IsTraceEnabledResolver = new ValueResolverTimed <bool>(() => underlying.IsTraceEnabled, loggerEnableCacheTtl); } this.Info(x => x("SetupLoggerEnabledValueResolvers: loggerEnableCacheTtl = '{0}'", loggerEnableCacheTtl)); }
public IList <T> CreateValues(IGrinderContext context, string name) { IList <TestValue> result = testValues ?? new List <TestValue> { new TestValue() }; return((IList <T>)result); }
public ScriptEngineBridge(IGrinderContext grinderContext) { if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } GrinderContext = grinderContext; }
public DatapoolManager(IGrinderContext grinderContext) { if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } GrinderContext = grinderContext; }
public TypeHelper(IGrinderContext grinderContext) { if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } Logger = new LoggerFacade(grinderContext.GetLogger(typeof(TypeHelper)), grinderContext); GrinderContext = grinderContext; }
public IList <T> CreateValues(IGrinderContext grinderContext) { if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } string name = typeof(T).Name; return(CreateValues(grinderContext, name)); }
public LoggerFacade(IGrinderLogger underlying, IGrinderContext grinderContext) { if (underlying == null) { throw new ArgumentNullException("underlying"); } if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } this.underlying = underlying; SetupLoggerEnabledValueResolvers(grinderContext); }
public IList <T> CreateValues(IGrinderContext grinderContext, string name) { if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("name"); } string fileName = grinderContext.GetProperty(DatapoolFactory.GetPropertyKey(name, "csvFile"), string.Format("{0}.csv", name)); return(CreateValues(fileName)); }
public Test(ITestMetadata metadata, IGrinderContext grinderContext) { if (metadata == null) { throw new ArgumentNullException("metadata"); } if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } Metadata = metadata; GrinderContext = grinderContext; Underlying = grinderContext.CreateTest(metadata.TestNumber, metadata.TestDescription, new TestActionWrapper(metadata.TestAction)); }
public DatapoolFactory(IGrinderContext grinderContext, IDatapoolManager datapoolManager) { if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } if (datapoolManager == null) { throw new ArgumentNullException("datapoolManager"); } GrinderContext = grinderContext; DatapoolManager = datapoolManager; TypeHelper = new TypeHelper(GrinderContext); }
internal static ProcessContext CreateProcessContext( string binFolder = null, IDatapoolFactory datapoolFactory = null, IDatapoolManager datapoolManager = null, IGrinderContext grinderContext = null) { var processContext = new ProcessContext { BinFolder = binFolder, DatapoolFactory = datapoolFactory ?? new Mock <IDatapoolFactory>().Object, DatapoolManager = datapoolManager ?? new Mock <IDatapoolManager>().Object, GrinderContext = grinderContext ?? CreateContextMock().Object }; processContext.Freeze(); return(processContext); }
internal static ProcessContext CreateProcessContext( string binFolder = null, IDatapoolFactory datapoolFactory = null, IDatapoolManager datapoolManager = null, IGrinderContext grinderContext = null) { var processContext = new ProcessContext { BinFolder = binFolder, DatapoolFactory = datapoolFactory ?? new Mock<IDatapoolFactory>().Object, DatapoolManager = datapoolManager ?? new Mock<IDatapoolManager>().Object, GrinderContext = grinderContext ?? CreateContextMock().Object }; processContext.Freeze(); return processContext; }
public Datapool(IGrinderContext grinderContext, IDatapoolMetatdata <T> datapoolMetadata) { if (grinderContext == null) { throw new ArgumentNullException("grinderContext"); } if (datapoolMetadata == null) { throw new ArgumentNullException("datapoolMetadata"); } GrinderContext = grinderContext; distributionMode = datapoolMetadata.DistributionMode; PhysicalSize = datapoolMetadata.Values.Count; int minCapacity; int agentCount = int.Parse(GrinderContext.GetProperty(Constants.AgentCountKey, "1")); int processCount = int.Parse(GrinderContext.GetProperty(Constants.ProcessCountKey, "1")); int agentOffset = GrinderContext.AgentNumber; int processOffset = GrinderContext.ProcessNumber - GrinderContext.FirstProcessNumber; threadCount = int.Parse(GrinderContext.GetProperty(Constants.ThreadCountKey, "1")); if (distributionMode == DatapoolThreadDistributionMode.ThreadUnique) { if (!(agentCount > GrinderContext.AgentNumber)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot ceate thread unique datapool '{0}', because property '{1}' = '{2}'. Current AgentNumber = '{3}' and indicates that '{1}' must be at least '{4}' for thread uniqueness to work correctly", datapoolMetadata.Name, Constants.AgentCountKey, agentCount, GrinderContext.AgentNumber, GrinderContext.AgentNumber + 1)); } if (processOffset < 0) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot ceate thread unique datapool '{0}', because thread offset negative ({1}). FirstProcessNumber = {2}, ProcessNumber = {3}", datapoolMetadata.Name, processOffset, GrinderContext.FirstProcessNumber, GrinderContext.ProcessNumber)); } if (!(processCount > processOffset)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Cannot ceate thread unique datapool '{0}', because thread offset = '{1}' is not less than property 'grinder.threads' = '{2}'. FirstProcessNumber = {3}, ProcessNumber = {4}", datapoolMetadata.Name, processOffset, processCount, GrinderContext.FirstProcessNumber, GrinderContext.ProcessNumber)); } minCapacity = agentCount * processCount * threadCount; } else { minCapacity = 1; } if (PhysicalSize < minCapacity) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "To low capacity for datapool '{0}', expected at least '{1}', but was '{2}'", datapoolMetadata.Name, minCapacity, PhysicalSize)); } T[] values = datapoolMetadata.Values.ToArray(); if (datapoolMetadata.IsRandom && PhysicalSize > 1) { var random = new Random(datapoolMetadata.Seed); for (int i = 0; i < PhysicalSize; i++) { int swapWith = random.Next(PhysicalSize); T orgValue = values[i]; values[i] = values[swapWith]; values[swapWith] = orgValue; } } Tuple <int, int> agentSlice = GetSubtupleInTupleSlicedBy(agentOffset, new Tuple <int, int>(0, PhysicalSize - 1), agentCount); Tuple <int, int> processSlice = GetSubtupleInTupleSlicedBy(processOffset, agentSlice, processCount); if (distributionMode == DatapoolThreadDistributionMode.ThreadShared) { nonThreadUniqueValueBucket = new ValueBucket { Values = values, Name = datapoolMetadata.Name, StartOffset = 0, EndOffset = PhysicalSize - 1, NextOffset = -1, IsThreadUnique = false, IsCircular = datapoolMetadata.IsCircular, LogicalSize = processSlice.Item2 - processSlice.Item1 + 1 }; } else { threadUniqueValueBuckets = new ValueBucket[threadCount]; for (int i = 0; i < threadCount; i++) { Tuple <int, int> threadSlice = distributionMode == DatapoolThreadDistributionMode.ThreadUnique ? GetSubtupleInTupleSlicedBy(i, processSlice, threadCount) : new Tuple <int, int>(0, PhysicalSize - 1); threadUniqueValueBuckets[i] = new ValueBucket { Values = values, Name = datapoolMetadata.Name, StartOffset = threadSlice.Item1, EndOffset = threadSlice.Item2, NextOffset = threadSlice.Item1 - 1, IsThreadUnique = true, IsCircular = datapoolMetadata.IsCircular, LogicalSize = threadSlice.Item2 - threadSlice.Item1 + 1 }; } } }
private void SetupLoggerEnabledValueResolvers(IGrinderContext grinderContext) { long loggerEnableCacheTtl = long.Parse(grinderContext.GetProperty(Constants.LoggerEnabledCacheTtlKey, "-1")); if (loggerEnableCacheTtl < 0) { IsErrorEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsErrorEnabled); IsWarnEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsWarnEnabled); IsInfoEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsInfoEnabled); IsDebugEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsDebugEnabled); IsTraceEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsTraceEnabled); } else if ((loggerEnableCacheTtl == 0)) { IsErrorEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsErrorEnabled); IsWarnEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsWarnEnabled); IsInfoEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsInfoEnabled); IsDebugEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsDebugEnabled); IsTraceEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsTraceEnabled); } else { IsErrorEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsErrorEnabled, loggerEnableCacheTtl); IsWarnEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsWarnEnabled, loggerEnableCacheTtl); IsInfoEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsInfoEnabled, loggerEnableCacheTtl); IsDebugEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsDebugEnabled, loggerEnableCacheTtl); IsTraceEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsTraceEnabled, loggerEnableCacheTtl); } this.Info(x => x("SetupLoggerEnabledValueResolvers: loggerEnableCacheTtl = '{0}'", loggerEnableCacheTtl)); }
public static IGrinderScriptEngine CreateBridge(IGrinderContext grinderContext) { return new ScriptEngineBridge(grinderContext); }
public static IGrinderScriptEngine CreateBridge(IGrinderContext grinderContext) { return(new ScriptEngineBridge(grinderContext)); }