public FrameFormatterSerializationOptions(int totWorkerThreads, bool throwOnUnnasignedFrameDeserialization = true)
 {
     BatchSizeEstimatorConfig = new BatchSizeEstimatorConfig();
     FIFOWorkerConfig         = new FIFOWorkerConfig(totWorkerThreads);
     MthWorkerConfig          = new MultiThreadedWorkerConfig(totWorkerThreads);
     ThrowOnUnnasignedFrameDeserialization = throwOnUnnasignedFrameDeserialization;
 }
Example #2
0
        public void Dispose_ExceptionInWorkerPropagates(int totThreads)
        {
            TaskCompletionSource <object> taskBlocker1 = new TaskCompletionSource <object>();

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

            CancellationTokenSource ts = new CancellationTokenSource();
            var cfg = new MultiThreadedWorkerConfig(totThreads);
            MultiThreadedWorker <MockWorkIn> mtw = new MultiThreadedWorker <MockWorkIn>(cfg, DoMockWorkBlocking);

            mtw.AddWorkItem(new MockWorkIn(1), ts.Token);

            TestDelegate disposeDel = delegate()
            {
                try
                {
                    taskBlocker1.SetResult(null);
                    mtw.Dispose();
                }
                catch (AggregateException ex)
                {
                    throw ex.InnerException;
                }
            };

            Assert.Throws <MockException>(disposeDel);
        }
Example #3
0
        public void Dispose_CancelsPendingTasks(int totThreads, bool cancelsDuringWork)
        {
            TaskCompletionSource <object> taskBlocker1 = new TaskCompletionSource <object>();
            bool completed = false;

            void DoMockWorkBlocking(MockWorkIn work, CancellationToken token)
            {
                taskBlocker1.Task.Wait();
                Task.Delay(1, token).Wait();
                completed = true;
            }

            CancellationTokenSource ts = new CancellationTokenSource();
            var cfg = new MultiThreadedWorkerConfig(totThreads);
            MultiThreadedWorker <MockWorkIn> mtw = new MultiThreadedWorker <MockWorkIn>(cfg, DoMockWorkBlocking);

            mtw.AddWorkItem(new MockWorkIn(1), ts.Token);
            if (cancelsDuringWork)
            {
                ts.Cancel();
            }
            taskBlocker1.SetResult(null);

            Assert.DoesNotThrow(mtw.Dispose);

            Assert.AreEqual(!cancelsDuringWork, completed);
        }
 public FrameFormatterSerializationOptions(
     BatchSizeEstimatorConfig batchSizeEstimatorConfig,
     MultiThreadedWorkerConfig mthWorkerConfig,
     bool throwOnUnnasignedFrameDeserialization = true)
 {
     BatchSizeEstimatorConfig = batchSizeEstimatorConfig;
     FIFOWorkerConfig         = new FIFOWorkerConfig(Environment.ProcessorCount * 2);
     MthWorkerConfig          = mthWorkerConfig;
     ThrowOnUnnasignedFrameDeserialization = throwOnUnnasignedFrameDeserialization;
 }
 public FrameFormatterSerializationOptions(
     BatchSizeEstimatorConfig batchSizeEstimatorConfig,
     FIFOWorkerConfig fIFOWorkerConfig,
     MultiThreadedWorkerConfig mthWorkerConfig,
     bool throwOnUnnasignedFrameDeserialization = true)
 {
     BatchSizeEstimatorConfig = batchSizeEstimatorConfig;
     FIFOWorkerConfig         = fIFOWorkerConfig;
     MthWorkerConfig          = mthWorkerConfig;
     ThrowOnUnnasignedFrameDeserialization = throwOnUnnasignedFrameDeserialization;
 }
Example #6
0
        public void AddWorkItem_Cancels(int totThreads)
        {
            MockWorker mw = new MockWorker();
            CancellationTokenSource ts = new CancellationTokenSource();
            var cfg = new MultiThreadedWorkerConfig(totThreads);
            MultiThreadedWorker <MockWorkIn> mtw = new MultiThreadedWorker <MockWorkIn>(cfg, mw.DoMockWorkBlocking);

            mtw.AddWorkItem(new MockWorkIn(1), ts.Token);

            mw.TriggerOnBlockedWorkAsync(() => ts.Cancel()).Wait();

            Assert.AreEqual(1, mw.doneWork.Count(f => f.Item1));
            Assert.AreEqual(1, mw.doneWork.Count());
        }