예제 #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());
        }
예제 #2
0
        public async Task TestAggregateCleanupSuccessful()
        {
            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());

            var streamIdentitiesProcessor = await aggregate.GetOutputStreams();

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

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

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

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

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

            await inputAggregate.TearDown();

            var tId = Guid.NewGuid();
            await inputAggregate.StartTransaction(tId);

            await inputAggregate.EndTransaction(tId);

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

            Assert.IsFalse(taskCompleted);

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

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

            Assert.AreEqual(0, subscriptionHdl1.Count);
            Assert.AreEqual(0, subscriptionHdl2.Count);
        }
예제 #3
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();
        }
예제 #4
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();
        }
예제 #5
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());
        }