public async Task TestItemTransfer() { var processorNodeGuid = Guid.NewGuid(); var processor = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectNodeGrain <int, int> >(processorNodeGuid); await processor.SetFunction(new SerializableFunc <int, int>(_ => _)); var itemsToSend = new List <int> { -1, 5, 30 }; var provider = GrainClient.GetStreamProvider(StreamProvider); var testProvider = new StreamMessageSenderComposite <int>(provider, 1); await processor.SubscribeToStreams(await testProvider.GetOutputStreams()); var testConsumer = new TransactionalStreamListConsumer <int>(provider); await SubscribeConsumer(processor, testConsumer); var tid = TransactionGenerator.GenerateTransactionId(); await testProvider.StartTransaction(tid); await testProvider.SendMessage(new ItemMessage <int>(itemsToSend)); await testProvider.EndTransaction(tid); CollectionAssert.AreEquivalent(itemsToSend, testConsumer.Items); await testProvider.TearDown(); }
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); }
public async Task TestTransactionNoItems() { var processorNodeGuid = Guid.NewGuid(); var processor = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectNodeGrain <int, int> >(processorNodeGuid); await processor.SetFunction(new SerializableFunc <int, int>(_ => _)); var provider = GrainClient.GetStreamProvider(StreamProvider); var testProvider = new StreamMessageSenderComposite <int>(provider, 1); await processor.SubscribeToStreams(await testProvider.GetOutputStreams()); var testConsumer = new TransactionalStreamListConsumer <int>(provider); await SubscribeConsumer(processor, testConsumer); await testProvider.SendMessage(new ItemMessage <int>(new List <int>())); Assert.AreEqual(0, testConsumer.Items.Count); await testProvider.TearDown(); }
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()); }
private async Task ValidateTwoLevelAggregateSetupAndTearDown() { int numberOfStreamsPerLevel = 2; var source = new StreamMessageSenderComposite <int>(_provider, numberOfStreamsPerLevel); var factory = new DefaultStreamProcessorAggregateFactory(GrainFactory); var aggregateOne = await factory.CreateSelect <int, int>(_ => _, new StreamProcessorAggregateConfiguration(await source.GetOutputStreams())); var aggregateTwo = await factory.CreateSelect <int, int>(_ => _, new StreamProcessorAggregateConfiguration(await aggregateOne.GetOutputStreams())); var firstElement = new StreamProcessorChainStart <int, int, DefaultStreamProcessorAggregateFactory>(aggregateOne, source, new DefaultStreamProcessorAggregateFactory(GrainFactory)); var query = new StreamProcessorChain <int, int, DefaultStreamProcessorAggregateFactory>(aggregateTwo, firstElement); Assert.IsFalse(await aggregateOne.IsTearedDown()); Assert.IsFalse(await aggregateTwo.IsTearedDown()); await query.TearDown(); Assert.IsTrue(await aggregateOne.IsTearedDown()); Assert.IsTrue(await aggregateTwo.IsTearedDown()); }