public void UtilizationWasCalled_GoneObjectEventWithObjectDataIsRaised() { var utilizer = new ObjectUtilizer<string, string>(); var eventWasRaised = false; var keyFromEvent = string.Empty; var objectDataFromEvent = string.Empty; var reporter = new object(); object reporterFromEvent = null; utilizer.ObjectIsGone += (sender, args) => { eventWasRaised = true; keyFromEvent = args.Key; objectDataFromEvent = args.PoolObject; reporterFromEvent = args.Reporter; }; utilizer.Utilize(_key, _objectData, reporter); Assert.That(eventWasRaised, Is.True); Assert.That(keyFromEvent, Is.EqualTo(_key)); Assert.That(objectDataFromEvent, Is.EqualTo(_objectData)); Assert.That(reporterFromEvent, Is.EqualTo(reporter)); }
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; }