예제 #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         FlushAsync().Wait();
         fifow.Dispose();
     }
     fifow               = null;
     batchEstimator      = null;
     objPoolList         = null;
     objPoolMemoryStream = null;
     currentBatch        = null;
     typeModel           = null;
 }
예제 #2
0
        public void AddWorkItem_Cancels(int totThreads)
        {
            MockWorker mw = new MockWorker();
            CancellationTokenSource ts       = new CancellationTokenSource();
            List <MockWorkOut>      doneWork = new List <MockWorkOut>();
            var cfg = new FIFOWorkerConfig(totThreads);
            FIFOWorker <MockWorkIn, MockWorkOut> fifo = new FIFOWorker <MockWorkIn, MockWorkOut>(cfg, mw.DoMockWorkBlocking);
            int countTask = fifo.AddWorkItem(new MockWorkIn(1), ts.Token).Count();

            mw.TriggerOnBlockedWork(() => ts.Cancel());

            Assert.Throws <TaskCanceledException>(() =>
            {
                try
                {
                    fifo.Dispose();
                }
                catch (AggregateException ag)
                {
                    throw ag.GetBaseException();
                }
            });
            Assert.AreEqual(1, mw.doneWork.Count(f => f.Item1));
            Assert.AreEqual(1, mw.doneWork.Count());
        }
예제 #3
0
        public void Dispose_ExceptionInWorkerPropagates(int totThreads)
        {
            TaskCompletionSource <object> taskBlocker1 = new TaskCompletionSource <object>();

            MockWorkOut DoMockWorkBlocking(MockWorkIn work, CancellationToken token)
            {
                taskBlocker1.Task.Wait();
                throw new MockException();
            }

            CancellationTokenSource ts       = new CancellationTokenSource();
            List <MockWorkOut>      doneWork = new List <MockWorkOut>();
            var cfg = new FIFOWorkerConfig(totThreads);
            FIFOWorker <MockWorkIn, MockWorkOut> fifo = new FIFOWorker <MockWorkIn, MockWorkOut>(cfg, DoMockWorkBlocking);
            int count = fifo.AddWorkItem(new MockWorkIn(1), ts.Token).Count();

            Assert.Throws <MockException>(() =>
            {
                try
                {
                    taskBlocker1.SetResult(null);
                    fifo.Dispose();
                }
                catch (AggregateException ag)
                {
                    throw ag.GetBaseException();
                }
            });
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         FlushAsync().Wait();
         fifow?.Dispose();
         if (currentBatch != null)
         {
             objPoolOutputBatch?.Return(currentBatch);
         }
     }
     w_opts = null;
     objPoolBufferWriterBodies      = null;
     objPoolBufferWriterBodyLengths = null;
     objPoolOutputBatch             = null;
     fifow          = null;
     batchEstimator = null;
     currentBatch   = null;
     formatterT     = null;
 }
예제 #5
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         fifow.Dispose();
     }
     fifow = null;
     objPoolBufferWriterSerializedBatch = null;
     objPoolList = null;
     typeModel   = null;
     t_ParallelServices_ArrayWrapper = null;
 }
예제 #6
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         fifow?.Dispose();
     }
     fifow  = null;
     r_opts = null;
     objPoolBufferWriterBodies      = null;
     objPoolBufferWriterBodyLengths = null;
     arrPoolOutputBatch             = null;
 }
예제 #7
0
        public void Dispose_ThrowsOnCancelledTasks(int totThreads)
        {
            TaskCompletionSource <object> taskBlocker1 = new TaskCompletionSource <object>();
            TaskCompletionSource <object> taskBlocker2 = new TaskCompletionSource <object>();
            bool completed = false;

            int totBlockCalled = 0;

            MockWorkOut DoMockWorkBlocking(MockWorkIn work, CancellationToken token)
            {
                Interlocked.Increment(ref totBlockCalled);
                taskBlocker2.SetResult(null);
                taskBlocker1.Task.Wait();
                Task.Delay(1, token).Wait();
                completed = true;
                return(new MockWorkOut(work));
            }

            CancellationTokenSource ts       = new CancellationTokenSource();
            List <MockWorkOut>      doneWork = new List <MockWorkOut>();
            var cfg = new FIFOWorkerConfig(totThreads);
            FIFOWorker <MockWorkIn, MockWorkOut> fifo = new FIFOWorker <MockWorkIn, MockWorkOut>(cfg, DoMockWorkBlocking);
            int count = fifo.AddWorkItem(new MockWorkIn(1), ts.Token).Count();

            taskBlocker2.Task.Wait();
            ts.Cancel();

            Assert.Throws <TaskCanceledException>(() =>
            {
                try
                {
                    taskBlocker1.SetResult(null);
                    fifo.Dispose();
                }
                catch (AggregateException ag)
                {
                    throw ag.GetBaseException();
                }
            });
            Assert.AreEqual(1, totBlockCalled);
            Assert.AreEqual(0, count);
            Assert.AreEqual(false, completed);
        }