public async Task StreamingTests_Consumer_Producer_SubscribeToStreamsHandledByDifferentStreamProvider()
        {
            var streamId = new FullStreamIdentity(Guid.NewGuid(), ImplicitSubscribeGrain.StreamNameSpace, StreamProviderName);

            var producer = this.fixture.GrainFactory.GetGrain <ITypedProducerGrainProducingApple>(Guid.NewGuid());
            await producer.BecomeProducer(streamId.Guid, streamId.Namespace, streamId.ProviderName);

            await producer.StartPeriodicProducing();

            int numProduced = 0;
            await TestingUtils.WaitUntilAsync(lastTry => ProgrammaticSubcribeTestsRunner.ProducerHasProducedSinceLastCheck(numProduced, producer, lastTry), _timeout);

            // set up the new stream with the same guid, but different namespace, so it would invoke the same consumer grain
            var streamId2 = new FullStreamIdentity(streamId.Guid, ImplicitSubscribeGrain.StreamNameSpace2, StreamProviderName2);
            var producer2 = this.fixture.GrainFactory.GetGrain <ITypedProducerGrainProducingApple>(Guid.NewGuid());
            await producer2.BecomeProducer(streamId2.Guid, streamId2.Namespace, streamId2.ProviderName);

            await producer2.StartPeriodicProducing();

            await TestingUtils.WaitUntilAsync(lastTry => ProgrammaticSubcribeTestsRunner.ProducerHasProducedSinceLastCheck(numProduced, producer2, lastTry), _timeout);

            await producer.StopPeriodicProducing();

            await producer2.StopPeriodicProducing();

            var implicitConsumer =
                this.fixture.HostedCluster.GrainFactory.GetGrain <IImplicitSubscribeGrain>(streamId.Guid);
            await TestingUtils.WaitUntilAsync(lastTry => ProgrammaticSubcribeTestsRunner.CheckCounters(new List <ITypedProducerGrain> {
                producer, producer2
            },
                                                                                                       implicitConsumer, lastTry, this.fixture.Logger), _timeout);

            //clean up test
            await implicitConsumer.StopConsuming();
        }
コード例 #2
0
        public async Task Programmatic_Subscribe_DynamicAddNewStreamProvider_WhenConsuming()
        {
            var streamId   = new FullStreamIdentity(Guid.NewGuid(), "EmptySpace", StreamProviderName);
            var subManager = this.Client.ServiceProvider.GetService <IStreamSubscriptionManagerAdmin>()
                             .GetStreamSubscriptionManager(StreamSubscriptionManagerType.ExplicitSubscribeOnly);
            //set up stream subscriptions for grains
            var subscriptions = await SetupStreamingSubscriptionForStream <IPassive_ConsumerGrain>(subManager, this.GrainFactory, streamId, 10);

            var consumers = subscriptions.Select(sub => this.GrainFactory.GetGrain <IPassive_ConsumerGrain>(sub.GrainId.PrimaryKey)).ToList();

            // configure stream provider1
            await AddSimpleStreamProviderAndUpdate(new List <String>() { StreamProviderName });

            //set up producer1
            var producer = this.GrainFactory.GetGrain <ITypedProducerGrainProducingApple>(Guid.NewGuid());
            await producer.BecomeProducer(streamId.Guid, streamId.Namespace, streamId.ProviderName);

            await producer.StartPeriodicProducing();

            int numProduced = 0;
            await TestingUtils.WaitUntilAsync(lastTry => ProgrammaticSubcribeTestsRunner.ProducerHasProducedSinceLastCheck(numProduced, producer, lastTry), _timeout);

            //set up stream2 and StreamProvider2
            await AddSimpleStreamProviderAndUpdate(new List <String>() { StreamProviderName2 });

            var streamId2 = new FullStreamIdentity(Guid.NewGuid(), "EmptySpace2", StreamProviderName2);

            await SetupStreamingSubscriptionForGrains <IPassive_ConsumerGrain>(subManager, streamId2, consumers);

            //set up producer2 to produce to stream2
            var producer2 = this.GrainFactory.GetGrain <ITypedProducerGrainProducingApple>(Guid.NewGuid());
            await producer2.BecomeProducer(streamId2.Guid, streamId2.Namespace, streamId2.ProviderName);

            await producer2.StartPeriodicProducing();

            await TestingUtils.WaitUntilAsync(lastTry => ProgrammaticSubcribeTestsRunner.ProducerHasProducedSinceLastCheck(numProduced, producer2, lastTry), _timeout);

            //stop producing
            await producer2.StopPeriodicProducing();

            await producer.StopPeriodicProducing();

            var tasks = new List <Task>();

            foreach (var consumer in consumers)
            {
                tasks.Add(TestingUtils.WaitUntilAsync(lastTry => ProgrammaticSubcribeTestsRunner.CheckCounters(new List <ITypedProducerGrain> {
                    producer, producer2
                },
                                                                                                               consumer, lastTry, this.Logger), _timeout));
            }
            await Task.WhenAll(tasks);

            //clean up test
            tasks.Clear();
            tasks = consumers.Select(consumer => consumer.StopConsuming()).ToList();
            await Task.WhenAll(tasks);
        }
        public async Task StreamingTests_Consumer_Producer_Subscribe()
        {
            var streamId = new FullStreamIdentity(Guid.NewGuid(), ImplicitSubscribeGrain.StreamNameSpace, StreamProviderName);
            var producer = this.fixture.HostedCluster.GrainFactory.GetGrain <ITypedProducerGrainProducingApple>(Guid.NewGuid());
            await producer.BecomeProducer(streamId.Guid, streamId.Namespace, streamId.ProviderName);

            await producer.StartPeriodicProducing();

            int numProduced = 0;
            await TestingUtils.WaitUntilAsync(lastTry => ProgrammaticSubcribeTestsRunner.ProducerHasProducedSinceLastCheck(numProduced, producer, lastTry), _timeout);

            await producer.StopPeriodicProducing();

            var implicitConsumer =
                this.fixture.HostedCluster.GrainFactory.GetGrain <IImplicitSubscribeGrain>(streamId.Guid);
            await TestingUtils.WaitUntilAsync(lastTry => ProgrammaticSubcribeTestsRunner.CheckCounters(new List <ITypedProducerGrain> {
                producer
            },
                                                                                                       implicitConsumer, lastTry, this.fixture.Logger), _timeout);

            //clean up test
            await implicitConsumer.StopConsuming();
        }