public void Initialize(ITestState <ValidatingOrderProcessor> state) { state.GetMockFor <IInventory>() .Setup(i => i.IsQuantityAvailable("TestPart", 10)) .Returns(true) .Verifiable(); }
public void HeartBeat(ITestState state) { for (int i = 0; i < _strategies.Length; i++) { _strategies[i].HeartBeat(state); } }
public void Setup(ITestState state) { for (int i = 0; i < _strategies.Length; i++) { _strategies[i].Setup(state); } }
public void HeartBeat(ITestState state) { int batch = (int)(state.Timer.Value.Ticks / _interval.Ticks); if (batch != CurrentBatch) { CurrentBatch = batch; Interlocked.Exchange(ref _executedBatchIterations, 0); } }
public void GivenIHaveAnObservationContext() { this.testState = MockRepository.GenerateMock<ITestState<DummyClassWithSingleParameterisedConstructor>>(); this.subjectDependencyBuilder = MockRepository.GenerateMock<ISubjectDependencyBuilder>(); this.mockFactory = MockRepository.GenerateMock<IMockFactory>(); this.subjectFactory = MockRepository.GenerateMock<ISubjectFactory>(); this.subject = new ObservationContext<DummyClassWithSingleParameterisedConstructor>( this.testState, this.subjectDependencyBuilder, this.mockFactory, this.subjectFactory); }
public ObservationContext(ITestState <Subject> test_state_implementation, ISubjectDependencyBuilder subject_dependency_builder, IMockFactory mock_factory, ISubjectFactory subject_factory) { this.mock_factory = mock_factory; this.test_state = test_state_implementation; this.subject_dependency_builder = subject_dependency_builder; this.subject_factory = subject_factory; }
public bool StopTest(ITestState state) { for (int i = 0; i < _limits.Length; i++) { if (_limits[i].StopTest(state)) { return(true); } } return(false); }
protected Specification() { test_state = new TestState <TContract>(this, this.CreateSubject); var args = new ObservationContextArgs <TContract> { mock_factory = new TMockFactoryAdapter(), state = test_state, test = this }; observation_context = new ObservationContextFactory().create_from(args); }
public void HeartBeat(ITestState state) { if (!state.Timer.IsRunning) { _next = 0; } // Catch up _next if lagging behind timeline long deltaLag = state.Timer.Value.Ticks - _next; long threshold = 2 * _delayTicks; if (deltaLag > threshold && deltaLag > MinCatchupLagTicks) { Interlocked.Add(ref _next, deltaLag - _delayTicks); } }
public void HeartBeat(IThreadPool pool, ITestState state) { long index = state.Timer.Value.Ticks / _period.Ticks; int result; if (index < _threadCountValues.Length) { result = _threadCountValues[index]; } else { result = _lastValue; } pool.SetWorkerCountAsync(state, result); }
public static void SetWorkerCountAsync(this IThreadPool context, ITestState state, int threadCount) { int delta = threadCount - state.ThreadPool.CreatedThreadCount; if (delta != 0) { if (delta > 0) { context.StartWorkersAsync(delta); } else { context.StopWorkersAsync(-delta); } } }
public void HeartBeat(ITestState state) { if (_batchState == BatchState.Waiting) { IThreadPoolStats pool = state.ThreadPool; if (pool.CreatedThreadCount == pool.IdleThreadCount && pool.CreatedThreadCount >= _batchSize) { _executedInBatch = 0; _executeAt = state.Timer.Value.Add(ExecuteDelay); _batchState = BatchState.Executing; } } else if (_executedInBatch >= _batchSize) { _batchState = BatchState.Waiting; } }
public ITestState Start() { _threadPoolCounter = new ThreadPoolCounter(); PipeFactory <IResult> pipeFactory = new PipeFactory <IResult>(); _aggregator = new PipelineDataAggregator(_settings.Aggregators, pipeFactory); _aggregator.Start(); _globalCounters = GlobalCounters.CreateDefault(); _errorHandler = new ErrorHandler(); _limit = new LimitsHandler(_settings.Limits); _threading = _settings.Threading; _state = new TestState(_timer, _globalCounters, _threadPoolCounter); _speed = PriorityStrategyFactory.Create(_settings.Speeds, _timer); _speed.Setup(_state); IIterationContextFactory iterationContextFactory = CreateIterationContextFactory(); IScenarioHandlerFactory scenarioHandlerFactory = CreateScenarioHandlerFactory(); ISchedulerFactory schedulerFactory = CreateSchedulerFactory(); IDataCollectorFactory dataCollectorFactory = CreateDataCollectorFactory(pipeFactory, _threadPoolCounter); IScenarioThreadFactory scenarioThreadFactory = CreateScenarioThreadFactory(); IThreadFactory threadFactory = new ScenarioThreadFactory( iterationContextFactory, scenarioHandlerFactory, schedulerFactory, dataCollectorFactory, scenarioThreadFactory ); _pool = new ThreadPool(threadFactory, _threadPoolCounter); InitialThreadingSetup(); _timer.Start(); // This line also releases Worker-Threads from wait in IPrewait return(_state); }
/// <summary> /// TODO move the logic for each strategy into own class, or create different versions of the ConnectionService class? /// TODO prefer enum over string name /// </summary> private void Initailise(IStateTransitionStrategy stateTransitionStrategy) { switch(stateTransitionStrategy.Name) { case "CallbackToController": { _currentState = new DisconnectedState(_stateTransitionStrategy); _continue = true; break; } case "EventAggregator": { _currentState = new DisconnectedState(_stateTransitionStrategy); // Subscribe to the event aggregator for state transition events _eventAggregatorService.Subscribe<StateTransitionEventArgs>(OnStateTransitionRequest); _continue = true; break; } case "RaiseEvent": { _currentState = new DisconnectedState(_stateTransitionStrategy); // Subscribe to the state transition for events _stateTransitionStrategy.ChangeState += _stateTransitionStrategy_ChangeState; _continue = true; break; } case "SequentialState": { // Sequential _testStates = _testStates.OrderBy(x => x.Order); _currentState = _testStates.First(); _continue = true; break; } default: { _logger.Log("Unknown strategy: " + stateTransitionStrategy.Name); _continue = false; break; } } }
/// <summary> /// Factory method to create a new state object of the desired state /// </summary> public void MoveToState(ConnectionState desiredState) { switch (desiredState) { case ConnectionState.Connected: { _currentState = new ConnectedState(_stateTransitionStrategy); break; } case ConnectionState.Disconnected: { _currentState = new DisconnectedState(_stateTransitionStrategy); break; } default: { _logger.Log($"Unexpected ConnectionState: {desiredState}"); break; } } }
public void Initialize(ITestState <object> state) { state.GetMockFor <TextWriter>().Object.Write(_name); }
public bool StopTest(ITestState state) { return(_timeLimit <= state.Timer.Value); }
private void EngineOnStarted(IStrategyExecutor sender, ITestState state) { Started?.Invoke(sender, _engine.State); }
public void Setup(ITestState state) { _batchState = BatchState.Waiting; }
public void Initialize(ITestState <ValidatingOrderProcessor> state) { state.GetMockFor <IInventory>() .Setup(i => i.IsQuantityAvailable(It.IsAny <string>(), It.IsAny <int>())) .Returns(false); }
public new void HeartBeat(ITestState state) { HeartBeatInner(state.Timer.Value); base.HeartBeat(state); }
public void Setup(ITestState state) { CurrentBatch = 0; _executedBatchIterations = 0; }
public void Begin(ITestState testState) { Array.ForEach(_readers, r => r.Begin(testState)); }
public void MoveToNextState() { _currentStateIndex = (_currentStateIndex + 1) % _testStates.Count(); _currentState = _testStates.ElementAt(_currentStateIndex); }
public bool StopTest(ITestState state) { return(_readIndex + 1 >= _data.Length); }
public void Begin(ITestState testState) { _readIndex = -1; }
public void Initialize(ITestState <ValidatingOrderProcessor> state) { state.GetMockFor <IValidator <Order> >() .Setup(v => v.Validate(It.IsAny <Order>())) .Returns(false); }
public bool StopTest(ITestState state) { return(state.Counters.ErrorCount >= _errorsThreshold); }
bool ILimitStrategy.StopTest(ITestState state) { return(_iterationsLimit <= state.Counters.LastGlobalIterationId - state.ThreadPool.IdleThreadCount); }
public void HeartBeat(IThreadPool pool, ITestState state) { int threadCount = GetAllowedCreatedThreadCount(state.Timer.Value); pool.SetWorkerCountAsync(state, threadCount); }
public void Setup(ITestState state) { _timer = state.Timer; _next = -_delayTicks; }