public void WhenEnquedItemsFilterDeliveredTwiceMethodsAreCalled()
        {
            int handledItemsCount  = 0;
            int resolvedItemsCount = 0;

            PendingItemsHandled hpi = (count) =>
            {
                Interlocked.Increment(ref handledItemsCount);
            };
            GroupItemResolved rg = (resolvedGroupItem) =>
            {
                Interlocked.Increment(ref resolvedItemsCount);
            };
            var adf = new ADFilterPong();

            adf.RegisterResolvedGroupHandler(rg);
            var queryEngine = new QueryEngine(hpi, new ADFilterPong());

            queryEngine.Enque("a");
            queryEngine.Enque("b");
            while (Interlocked.CompareExchange(ref handledItemsCount, 2, 2) == 2)
            {
                System.Threading.Thread.Sleep(0);
            }

            queryEngine.Enque("c");
            while (Interlocked.CompareExchange(ref handledItemsCount, 3, 3) == 3)
            {
                System.Threading.Thread.Sleep(0);
            }

            queryEngine.Stop();
        }
        public QueryEngine(
            PendingItemsHandled handledPendingItems,
            IADFilter adFilter)
        {
            _semaphoreSlim       = new SemaphoreSlim(1);
            _stopToken           = new CancellationTokenSource();
            _canConsume          = new ManualResetEventSlim(false);
            _handledPendingItems = handledPendingItems;
            _adFilter            = adFilter;
            _pendingQueue        = new ConcurrentQueue <string>();

            _worker = new Thread(this.Run);
            _worker.Start();
        }
        public void StartStop()
        {
            PendingItemsHandled hpi = (count) =>
            {
            };
            GroupItemResolved rg = (resolvedGroupItem) =>
            {
            };
            var adf = new ADFilterPong();

            adf.RegisterResolvedGroupHandler(rg);
            var queryEngine = new QueryEngine(hpi, new ADFilterPong());

            queryEngine.Stop();
        }