예제 #1
0
        public async Task GetCurrentIntervalQueriesRanCount_ShouldResetOnNextInterval()
        {
            var queryQueue = new QueryQueue();

            queryQueue.SetIntervalKey(() => DateTime.UtcNow.Millisecond);

            var query1 = new TestQuery(1, QueryFunctionType.SingleQuote);
            var query2 = new TestQuery(2, QueryFunctionType.IntraDay);
            var query3 = new TestQuery(3, QueryFunctionType.Weekly);

            queryQueue.Enqueue(query1);
            queryQueue.Enqueue(query2);
            queryQueue.Enqueue(query3);

            queryQueue.Dequeue(2);
            queryQueue.MarkAsExecuted(query1);
            queryQueue.MarkAsExecuted(query2);

            Assert.Equal(2, queryQueue.GetCurrentIntervalQueriesRanCount());

            await Task.Delay(10);

            Assert.Equal(0, queryQueue.GetCurrentIntervalQueriesRanCount());
        }
예제 #2
0
        public QueryEventBusTests()
        {
            _querySubscriptions = new QuerySubscriptions();

            _queryQueue = new QueryQueue();

            // Will allow same queries to be queued again after a  millisecond
            _queryQueue.SetIntervalKey(() => DateTime.UtcNow.Millisecond);

            _mockContextFactory = new Mock <IQueryContextFactory>();

            var priorityRule = new QuerySubscriptionCountRule(
                contextFactory: _mockContextFactory.Object,
                _querySubscriptions,
                (new Mock <ILogger <QuerySubscriptionCountRule> >()).Object
                );

            _queryEventBus = new QueryEventBus(
                queryQueue: _queryQueue,
                queryContextFactory: _mockContextFactory.Object,
                queuePriorityRule: priorityRule,
                logger: (new Mock <ILogger <QueryEventBus> >()).Object
                );
        }