private PoolController<int, ThreadWorker> CreateThreadPoolControllerInstance() { var workerActions = new ObjectActionsBasedOnDelegateOrInterface<ThreadWorker>(new ExplicitlyDefinedObjectActions<ThreadWorker>()); var objectUtilizer = new ObjectUtilizer<int, ThreadWorker>(); var basicPoolSettings = new PoolItemsStorageSettings { AllowOnlyOneUserPerObject = true, BalancingStrategy = _settings.BalancingStrategy, MaxObjectsCountPerKey = _settings.MaxWorkersCount, ThrowIfCantCreateObjectBecauseOfReachedLimit = false, }; var basicPool = new PoolItemsStorage<int, ThreadWorker>(basicPoolSettings, workerActions, objectUtilizer); var stateMonitoringSettings = new PWObjectStateMonitoringSettings { MaxObjectIdleTimeSpanInSeconds = _settings.MaxObjectIdleTimeSpanInSeconds, MaxObjectLifetimeInSeconds = _settings.MaxObjectIdleTimeSpanInSeconds, TimeSpanBetweenRevivalsInSeconds = _settings.MonitorTimeSpanInSeconds, }; var stateMonitoringPool = new PWObjectStateMonitoringWrapper<int, ThreadWorker>(stateMonitoringSettings, basicPool, workerActions, objectUtilizer); var singleUsePool = new PWSingleUseEnforcingWrapper<int, ThreadWorker>(stateMonitoringPool); var autoReleasingPool = new PWAutoReleasingWrapper<int, ThreadWorker>(singleUsePool); var poolControllerSettings = new PoolControllerSettings { CallingReleaseOperationWillHappen = true, }; var controller = new PoolController<int, ThreadWorker>(poolControllerSettings, autoReleasingPool); autoReleasingPool.SetPoolController(controller); return controller; }
public void SetUp() { _settings = new PWObjectStateMonitoringSettings { TimeSpanBetweenRevivalsInSeconds = 5, MaxObjectLifetimeInSeconds = 3, MaxObjectIdleTimeSpanInSeconds = 2, }; _baseSuccessfulPoolMock = Mocks.Pool.GetNewReturningDifferentObjects(); _baseSameObjectPoolMock = Mocks.Pool.GetNewReturningSameObject(); _baseNoObjectPoolMock = Mocks.Pool.GetNewReturningNoObject(); _baseThrowingPoolMock = Mocks.Pool.GetNewThrowing(); _successfulObjectActionsMock = Mocks.ObjectActions.GetNewSuccessful(); _failingOnPingObjectActionsMock = Mocks.ObjectActions.GetNewFailingOnPing(); _objectUtilizerMock = Mocks.ObjectUtilizer.GetNew(); }