示例#1
0
        public async Task UnregisterProducerFaultTest()
        {
            this.fixture.Logger.Info("************************ UnregisterProducerFaultTest *********************************");
            var streamId    = StreamId.GetStreamId(Guid.NewGuid(), "ProviderName", "StreamNamespace");
            var pubSubGrain = this.fixture.GrainFactory.GetGrain <IPubSubRendezvousGrain>(
                streamId.Guid,
                keyExtension: streamId.ProviderName + "_" + streamId.Namespace);
            var faultGrain = this.fixture.GrainFactory.GetGrain <IStorageFaultGrain>(typeof(PubSubRendezvousGrain).FullName);

            IStreamProducerExtension firstProducer  = new DummyStreamProducerExtension();
            IStreamProducerExtension secondProducer = new DummyStreamProducerExtension();
            // Add two producers so when we remove the first it does a storage write, not a storage clear.
            await pubSubGrain.RegisterProducer(streamId, firstProducer);

            await pubSubGrain.RegisterProducer(streamId, secondProducer);

            int producers = await pubSubGrain.ProducerCount(streamId);

            Assert.Equal(2, producers);

            // inject fault
            await faultGrain.AddFaultOnWrite(pubSubGrain as GrainReference, new ApplicationException("Write"));

            // expect exception when unregistering a producer
            await Assert.ThrowsAsync <OrleansException>(
                () => pubSubGrain.UnregisterProducer(streamId, firstProducer));

            // pubsub grain should recover and still function
            await pubSubGrain.UnregisterProducer(streamId, firstProducer);

            producers = await pubSubGrain.ProducerCount(streamId);

            Assert.Equal(1, producers);

            // inject clear fault, because removing last producers should trigger a clear storage call.
            await faultGrain.AddFaultOnClear(pubSubGrain as GrainReference, new ApplicationException("Write"));

            // expect exception when unregistering a consumer
            await Assert.ThrowsAsync <OrleansException>(
                () => pubSubGrain.UnregisterProducer(streamId, secondProducer));

            // pubsub grain should recover and still function
            await pubSubGrain.UnregisterProducer(streamId, secondProducer);

            producers = await pubSubGrain.ConsumerCount(streamId);

            Assert.Equal(0, producers);
        }
示例#2
0
 private bool Equals(DummyStreamProducerExtension other)
 {
     return(id.Equals(other.id));
 }