public async Task TestItemAggregation()
        {
            var aggregate = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectAggregate <int, int> >(Guid.NewGuid());
            await aggregate.SetFunction(_ => _);

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

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

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

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

            var consumerAggregate = new TestTransactionalStreamConsumerAggregate <int>(provider);
            await consumerAggregate.SetInput(await aggregate.GetStreamIdentities());

            var tid = await inputAggregate.SendItems(itemsToSend);

            var waitForTransaction = consumerAggregate.TransactionComplete(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());
        }
Пример #2
0
        public async Task TestTearDownStreamBroken()
        {
            var source = new MultiStreamProvider <int>(_provider, 2);

            var query = await source.Select(x => x, GrainClient.GrainFactory);

            var queryOutputStreams = await query.GetStreamIdentities();

            var resultConsumer = new TestTransactionalStreamConsumerAggregate <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.SendItems(new List <int>() { 2, 3 });

            Assert.AreEqual(0, resultConsumer.Items.Count);
            Assert.IsTrue(await resultConsumer.AllConsumersTearDownCalled());
        }
        public async Task TestAggregateCleanupSuccessful()
        {
            var aggregate = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectAggregate <int, int> >(Guid.NewGuid());
            await aggregate.SetFunction(_ => _);

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

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

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

            var streamIdentitiesProcessor = await aggregate.GetStreamIdentities();

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

            var consumerAggregate = new TestTransactionalStreamConsumerAggregate <int>(provider);
            await consumerAggregate.SetInput(await aggregate.GetStreamIdentities());

            var subscriptionHdl1 = await GetStreamSubscriptionHandles <IStreamMessage>(streamIdentitiesProcessor[0].StreamIdentifier);

            var subscriptionHdl2 = await GetStreamSubscriptionHandles <IStreamMessage>(streamIdentitiesProcessor[1].StreamIdentifier);

            Assert.AreEqual(1, subscriptionHdl1.Count);
            Assert.AreEqual(1, subscriptionHdl2.Count);

            await inputAggregate.TearDown();

            var tid = await inputAggregate.SendItems(itemsToSend);

            var taskCompleted = consumerAggregate.TransactionComplete(tid).Wait(TimeSpan.FromSeconds(5));

            Assert.IsFalse(taskCompleted);

            subscriptionHdl1 = await GetStreamSubscriptionHandles <IStreamMessage>(streamIdentitiesProcessor[0].StreamIdentifier);

            subscriptionHdl2 = await GetStreamSubscriptionHandles <IStreamMessage>(streamIdentitiesProcessor[1].StreamIdentifier);

            Assert.AreEqual(0, subscriptionHdl1.Count);
            Assert.AreEqual(0, subscriptionHdl2.Count);
        }
Пример #4
0
        private async Task TestMultiLevelDataPass <TIn, TOut>(
            Func <MultiStreamProvider <TIn>, IStreamProcessorAggregateFactory, Task <IStreamProcessorChain <TOut> > >
            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 MultiStreamProvider <TIn>(_provider, 2);

            var query = await createStreamProcessingChainFunc(source, new DefaultStreamProcessorAggregateFactory(GrainFactory));

            var queryOutputStreams = await query.GetStreamIdentities();

            var resultConsumer = new TestTransactionalStreamConsumerAggregate <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];
                await source.SendItems(input);

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

            await query.TearDown();

            await resultConsumer.TearDown();
        }