public PoolControllerTests() { _key = new TestKey { Identifier = 48635, }; _settings = new PoolControllerSettings { CallingReleaseOperationWillHappen = true, }; _noObjectDirection = new DirectionIfNoObjectIsAvailable<TestKey, TestResource>(); }
public ThreadPool(ThreadPoolSettings settings, IThreadPoolTaskResultNotifier taskResultNotifier = null) { _settings = settings; _taskResultNotifier = taskResultNotifier; _poolController = CreateThreadPoolControllerInstance(); _noIdleWorkerDirection = new DirectionIfNoObjectIsAvailable<int, ThreadWorker> { CreateDelegateIfNoObjectIsAvailable = CreateWorker, AttemptsNumber = _settings.WaitingSettings != null ? _settings.WaitingSettings.WaitingsNumber + 1 : 1, OneIntervalBetweenAttemptsInSeconds = _settings.WaitingSettings != null ? _settings.WaitingSettings.OneWaitingTimespanInSeconds : 0, }; _managerThread = new Thread(AssignTasksToWorkers) { Name = ConfigurationManager.AppSettings["managerThreadName"], IsBackground = true, }; _managerThread.Start(); }
public void ReleasingWasNotPromised_ControllerIgnoresDirectionToWaitAndOrderPoolToCreateNewObject() { _settings.CallingReleaseOperationWillHappen = false; _controller = new PoolController<TestKey, TestResource>(_settings, _successPoolMock.Object); Func<TestKey, TestResource> createDelegate = key => new TestResource(Mocks.Pool.ResourceValueAfterWaitings); var directionToWaitForAvailableObject = new DirectionIfNoObjectIsAvailable<TestKey, TestResource> { AttemptsNumber = 5, OneIntervalBetweenAttemptsInSeconds = 10, CreateDelegateIfNoObjectIsAvailable = createDelegate, }; _controller.Obtain(_key, out _outPoolObject, directionToWaitForAvailableObject); _successPoolMock.Verify(x => x.TryObtain(_key, out _outPoolObject, createDelegate), Times.Once); _successPoolMock.Verify(x => x.TryObtain(_key, out _outPoolObject, null), Times.Never); }