Exemplo n.º 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());
        }
Exemplo n.º 2
0
        public async Task TestItemAggregation()
        {
            var aggregate = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectAggregate <int, int> >(Guid.NewGuid());
            await aggregate.SetFunction(new SerializableFunc <int, int>(_ => _));

            var itemsToSend = new List <int> {
                1, 5, 32, -12
            };

            var provider       = GrainClient.GetStreamProvider(StreamProvider);
            var inputAggregate = new StreamMessageSenderComposite <int>(provider, 2);

            await aggregate.SetInput(await inputAggregate.GetOutputStreams());

            Assert.AreEqual(2, (await aggregate.GetOutputStreams()).Count);

            var consumerAggregate = new TestTransactionalTransactionalStreamConsumerAggregate <int>(provider);
            await consumerAggregate.SetInput(await aggregate.GetOutputStreams());

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

            await inputAggregate.SendMessage(new ItemMessage <int>(itemsToSend));

            await inputAggregate.EndTransaction(tid);

            var resultItems = consumerAggregate.Items;

            Assert.AreEqual(4, resultItems.Count);
            CollectionAssert.AreEquivalent(itemsToSend, resultItems);

            Assert.IsFalse(await consumerAggregate.AllConsumersTearDownCalled());
            await inputAggregate.TearDown();

            Assert.IsTrue(await consumerAggregate.AllConsumersTearDownCalled());
        }