Beispiel #1
0
        public async Task TestTearDownStreamBroken()
        {
            var source = new StreamMessageSenderComposite <int>(_provider, 2);

            var factory = new DefaultStreamProcessorAggregateFactory(GrainFactory);
            var query   = await source.Select(x => x, factory);

            var queryOutputStreams = await query.GetOutputStreams();

            var resultConsumer = new TestTransactionalTransactionalStreamConsumerAggregate <int>(_provider);
            await resultConsumer.SetInput(queryOutputStreams);

            Assert.AreEqual(2, queryOutputStreams.Count);
            Assert.AreEqual(0, resultConsumer.Items.Count);

            Assert.IsFalse(await resultConsumer.AllConsumersTearDownCalled());

            await query.TearDown();

            await resultConsumer.TearDown();

            Assert.IsTrue(await resultConsumer.AllConsumersTearDownCalled());

            await source.SendMessage(new ItemMessage <int>(new List <int>()
            {
                2, 3
            }));

            Assert.AreEqual(0, resultConsumer.Items.Count);
            Assert.IsTrue(await resultConsumer.AllConsumersTearDownCalled());
        }
Beispiel #2
0
        public async Task TestOneLevelSelectManyDataPass()
        {
            var inputChunks = new List <int>()
            {
                5, 213, 23, -21, 23, 99
            }.BatchIEnumerable(2).ToList();
            var outputChunks = inputChunks.SelectMany(i => i).Select(i => (i > 0) ? Enumerable.Range(0, i).ToList() : i.SingleValueToList()).ToList();

            var source  = new StreamMessageSenderComposite <int>(_provider, 2);
            var factory = new DefaultStreamProcessorAggregateFactory(GrainFactory);
            var query   = await source.SimpleSelectMany(i => (i > 0)?Enumerable.Range(0, i) : i.SingleValueToList(), factory);

            var queryOutputStreams = await query.GetOutputStreams();

            var resultConsumer = new TestTransactionalTransactionalStreamConsumerAggregate <int>(_provider);
            await resultConsumer.SetInput(queryOutputStreams);

            Assert.AreEqual(2, queryOutputStreams.Count);
            Assert.AreEqual(0, resultConsumer.Items.Count);

            for (int i = 0; i < inputChunks.Count; i++)
            {
                var input          = inputChunks[i];
                var expectedOutput = new List <int>();
                expectedOutput.AddRange(outputChunks[2 * i]);
                expectedOutput.AddRange(outputChunks[2 * i + 1]);

                var tid = TransactionGenerator.GenerateTransactionId();
                await source.StartTransaction(tid);

                await source.SendMessage(new ItemMessage <int>(input));

                await source.EndTransaction(tid);

                CollectionAssert.AreEquivalent(expectedOutput, resultConsumer.Items);
                resultConsumer.Items.Clear();
            }

            await query.TearDown();

            await resultConsumer.TearDown();
        }
Beispiel #3
0
        private async Task TestMultiLevelDataPass <TIn, TOut>(
            Func <StreamMessageSenderComposite <TIn>, DefaultStreamProcessorAggregateFactory, Task <IStreamProcessorChain <TOut, DefaultStreamProcessorAggregateFactory> > >
            createStreamProcessingChainFunc, List <List <TIn> > inputChunks, List <List <TOut> > outputChunks,
            Action <List <TOut>, List <TOut> > resultAssertion)
        {
            if (inputChunks.Count != outputChunks.Count)
            {
                throw new ArgumentException();
            }

            var source = new StreamMessageSenderComposite <TIn>(_provider, 2);

            var query = await createStreamProcessingChainFunc(source, _factory);

            var queryOutputStreams = await query.GetOutputStreams();

            var resultConsumer = new TestTransactionalTransactionalStreamConsumerAggregate <TOut>(_provider);
            await resultConsumer.SetInput(queryOutputStreams);

            Assert.AreEqual(2, queryOutputStreams.Count);
            Assert.AreEqual(0, resultConsumer.Items.Count);

            for (int i = 0; i < inputChunks.Count; i++)
            {
                var input          = inputChunks[i];
                var expectedOutput = outputChunks[i];

                var tid = TransactionGenerator.GenerateTransactionId();
                await source.StartTransaction(tid);

                await source.SendMessage(new ItemMessage <TIn>(input));

                await source.EndTransaction(tid);

                resultAssertion(expectedOutput, resultConsumer.Items);
                resultConsumer.Items.Clear();
            }

            await query.TearDown();

            await resultConsumer.TearDown();
        }