public JobExecutionModule(EntityArea area, JobModuleSettings settings = null) : base(area, "JobRunner", version: CurrentVersion) { RegisterEntities(typeof(IJob), typeof(IJobRun), typeof(IJobSchedule)); _settings = settings ?? new JobModuleSettings(); _activitiesCounter = new ThreadSafeCounter(); App.RegisterConfig(_settings); App.RegisterService <IJobInformationService>(this); App.RegisterService <IJobExecutionService>(this); App.RegisterService <IJobDiagnosticsService>(this); }
internal void InitializedOnlyOnceFromMultipleThreads(string dbgWayToCallDesc, Func <LazyContextualInit <string>, Func <string>, string> wayToCall) { var counter = new ThreadSafeCounter(); var ctxLazy = new LazyContextualInit <string>(); var numberOfThreads = Math.Max(Environment.ProcessorCount, 2); var threadIndexesAndValues = new ConcurrentBag <ValueTuple <int, string> >(); var barrier = new Barrier(numberOfThreads); var expectedThreadIndexes = Enumerable.Range(1, numberOfThreads); var threads = expectedThreadIndexes.Select(i => new Thread(() => EachThreadDo(i))).ToList(); foreach (var thread in threads) { thread.Start(); } foreach (var thread in threads) { thread.Join(); } ctxLazy.IsInited.Should().BeTrue($"{nameof(dbgWayToCallDesc)}: {dbgWayToCallDesc}"); counter.Value.Should().Be(1); threadIndexesAndValues.Should().HaveCount(numberOfThreads); var actualThreadIndexes = new HashSet <int>(); foreach (var(threadIndex, value) in threadIndexesAndValues) { value.Should().Be("1"); actualThreadIndexes.Add(threadIndex); } actualThreadIndexes.Should().HaveCount(numberOfThreads); foreach (var expectedThreadIndex in expectedThreadIndexes) { actualThreadIndexes.Should().Contain(expectedThreadIndex); } void EachThreadDo(int threadIndex) { barrier.SignalAndWait(); var value = wayToCall(ctxLazy, () => counter.Increment().ToString()); threadIndexesAndValues.Add((threadIndex, value)); } }
/// <summary> /// Initialize a new Map /// </summary> /// <param name="dynamicID">Key to identify map</param> /// <param name="id">Dmap value of map. Used for all movement checks</param> public Map(uint _dynamicID, uint _id) { Objects = new ConcurrentDictionary <uint, ILocatableObject>(); ItemCounter = new ThreadSafeCounter(100000, 150000); SobCounter = new ThreadSafeCounter(150000, 200000); MobCounter = new ThreadSafeCounter(400000, 500000); PetCounter = new ThreadSafeCounter(500000, 600000); MapInfo = ServerDatabase.Context.Maps.GetById(_id); ID = _id; DynamicID = _dynamicID; var dNpcs = ServerDatabase.Context.Npcs.GetNpcsByMap((ushort)_dynamicID); if (dNpcs.Count > 0) { foreach (var dNpc in dNpcs) { Insert(new Npc(dNpc, this)); } } var dSpawns = ServerDatabase.Context.Spawns.GetSpawnsByMap((ushort)_dynamicID); Spawns = new List <SpawnManager>(); if (dSpawns.Count > 0) { foreach (var dSpawn in dSpawns) { Spawns.Add(new SpawnManager(dSpawn, this)); } } foreach (var dSob in ServerDatabase.Context.SOB.GetSOBByMap((ushort)_dynamicID)) { Insert(new SOB(dSob)); } if (MapInfo.Type.HasFlag(MapTypeFlags.MineEnable)) { _mineRules = ServerDatabase.Context.DropRules.GetRulesByMonsterType(ID).ToList(); } Console.WriteLine("Map ID {0} loaded {1} npcs and {2} spawns", _dynamicID, dNpcs.Count, dSpawns.Count); }
internal void InitializedOnlyOnceOnFirstAccess(string dbgWayToCallDesc, Func <LazyContextualInit <string>, Func <string>, string> wayToCall) { var counter = new ThreadSafeCounter(); var ctxLazy = new LazyContextualInit <string>(); ctxLazy.IsInited.Should().BeFalse(); ctxLazy.IfNotInited.Should().NotBeNull(); var val1 = wayToCall(ctxLazy, () => counter.Increment().ToString()); ctxLazy.IsInited.Should().BeTrue($"{nameof(dbgWayToCallDesc)}: {dbgWayToCallDesc}"); ctxLazy.IfNotInited.Should().BeNull(); val1.Should().Be("1"); counter.Value.Should().Be(1); var val2 = wayToCall(ctxLazy, () => counter.Increment().ToString()); ctxLazy.IsInited.Should().BeTrue(); val2.Should().Be("1"); counter.Value.Should().Be(1); }
// TODO: Redesign validator so it uses actual handlers. /// <summary> /// Validates ILoadTest scenario correctness by executing single test iteration /// from ScenarioSetup to ScenarioTearDown on the same thread. /// Exceptions are not handled on purpose to ease problem identification while developing. /// </summary> /// <param name="scenario">ILoadTestScenario object</param> /// <param name="threadId">TheardId to set in TestContext</param> /// <param name="threadIterationId">ThreadIterationId to set in TestContext</param> /// <param name="globalIterationId">GlobalIterationId to set in TestContext</param> /// <returns>Raw result from single iteration</returns> public static IterationResult Validate(this IScenario scenario, int threadId = 0, int threadIterationId = 0, int globalIterationId = 0) { ExecutionTimer timer = new ExecutionTimer(); ThreadSafeCounter errorsCounter = new ThreadSafeCounter(); GlobalCounters globalCounters = new GlobalCounters(errorsCounter, new MockedIdGenerator(globalIterationId)); IIterationControl context = new IterationContext(threadId, timer); ScenarioHandler handler = new ScenarioHandler(globalCounters, new MockedIdGenerator(threadIterationId), scenario, context); timer.Start(); handler.Init(); handler.PrepareNext(); handler.Execute(); IterationResult result = new IterationResult(context, new WorkerThreadStats()); handler.Cleanup(); timer.Stop(); return(result); }
public static IterationResult Validate <TData>(this IReplayScenario <TData> scenario, DataItem data, int threadId = 0, int threadIterationId = 0, int globalIterationId = 0) { ExecutionTimer timer = new ExecutionTimer(); ThreadSafeCounter errorsCounter = new ThreadSafeCounter(); GlobalCounters globalCounters = new GlobalCounters(errorsCounter, new MockedIdGenerator(globalIterationId)); IIterationControl context = new IterationContext(threadId, timer); ReplayScenarioHandler <TData> handler = new ReplayScenarioHandler <TData>(globalCounters, new MockedIdGenerator(threadIterationId), scenario, context); timer.Start(); handler.Init(); handler.PrepareNext(); handler.SetData(data.Value, data.TimeStamp); handler.Execute(); IterationResult result = new IterationResult(context, new WorkerThreadStats()); handler.Cleanup(); timer.Stop(); return(result); }