示例#1
0
        public async Task If_time_window_is_expired_quering_the_status_should_succeed()
        {
            TimeSpan MAX_BATCH_TIME_WINDOW = TimeSpan.FromMilliseconds(300);
            var      batcher = new TimeWindowedBatcher <string>(batch =>
            {
                var j = string.Join(" ", batch.Items);
                return(new SuccessBatchResponse <string>(j));
            }, MAX_BATCH_TIME_WINDOW);

            var one = batcher.Add("one");
            var two = batcher.Add("two");

            await Task.Delay(400); // ms

            var batchExecution = batcher.Query(one);

            Assert.IsTrue(batchExecution.IsCompleted, "Execution should be completed!");
        }
示例#2
0
        public async Task If_time_window_is_NOT_expired_quering_the_status_should_throw()
        {
            TimeSpan MAX_BATCH_TIME_WINDOW = TimeSpan.FromSeconds(5);
            var      batcher = new TimeWindowedBatcher <string>(batch =>
            {
                var j = string.Join(" ", batch.Items);
                return(new SuccessBatchResponse <string>(j));
            }, MAX_BATCH_TIME_WINDOW);

            var one = batcher.Add("one");
            var two = batcher.Add("two");

            await Task.Delay(300); // ms

            try
            {
                var batchExecution = batcher.Query(one);
                Assert.Fail("Quering the batch-execution should have thrown before!");
            }
            catch (BatchWaitingForExecutionException)
            {
                // Just an exception of this type is expected.
            }
        }