public void WorkerPool_Validate_Maximum_Size() { IList <IWorker> workers = new List <IWorker>(); try { // Arrange int workerCount = 0; IWorker currentWorker = null; // Act while ((currentWorker = _testedPool.Peek()) != null) { workerCount++; workers.Add(currentWorker); } // Assert Assert.AreEqual(10, workerCount); } finally { foreach (var worker in workers) { _testedPool.Return(worker, false); } } }
public override Image CaptureUrl(string baseUrl, TimeSpan timeOut) { IWorker currentWorker = null; bool workerCompromise = false; try { // Wait for an available worker currentWorker = _workerPool.BlockingPeek(); // Bound all the request parameters to RemoteTask var remoteTask = CreateTask(baseUrl, timeOut); var taskResult = currentWorker.PerformTask(remoteTask); // When taskResult returns null, means that remoteworker is compromised and cannot be reused if (taskResult == null) { workerCompromise = true; throw new CaptureEngineException("RemoteWorker has shutdown", CaptureEngineState.InternalError); } if (taskResult.Error) { throw taskResult.Exception; } using (var memoryStream = new MemoryStream(taskResult.PayLoad)) { return(Image.FromStream(memoryStream)); } } finally { if (currentWorker != null) { _workerPool.Return(currentWorker, workerCompromise); } } }