Beispiel #1
0
        public async Task RegisterConsumerFaultTest()
        {
            this.fixture.Logger.Info("************************ RegisterConsumerFaultTest *********************************");
            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);

            // clean call, to make sure everything is happy and pubsub has state.
            await pubSubGrain.RegisterConsumer(GuidId.GetGuidId(Guid.NewGuid()), streamId, null, null);

            int consumers = await pubSubGrain.ConsumerCount(streamId);

            Assert.Equal(1, consumers);

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

            // expect exception when registering a new consumer
            await Assert.ThrowsAsync <OrleansException>(
                () => pubSubGrain.RegisterConsumer(GuidId.GetGuidId(Guid.NewGuid()), streamId, null, null));

            // pubsub grain should recover and still function
            await pubSubGrain.RegisterConsumer(GuidId.GetGuidId(Guid.NewGuid()), streamId, null, null);

            consumers = await pubSubGrain.ConsumerCount(streamId);

            Assert.Equal(2, consumers);
        }
Beispiel #2
0
        public IAsyncStream <T> GetStream <T>(Guid id, string streamNamespace)
        {
            var streamId = StreamId.GetStreamId(id, Name, streamNamespace);

            return(providerRuntime.GetStreamDirectory().GetOrAddStream <T>(
                       streamId, () => new StreamImpl <T>(streamId, this, IsRewindable, this.runtimeClient)));
        }
Beispiel #3
0
        public Task <IEnumerable <StreamSubscription> > GetSubscriptions(IStreamIdentity streamIdentity)
        {
            var streamProviderName = this.name;
            var streamId           = StreamId.GetStreamId(streamIdentity.Guid, streamProviderName, streamIdentity.Namespace);

            return(streamPubSub.GetAllSubscriptions(streamId).ContinueWith(subs => subs.Result.AsEnumerable()));
        }
Beispiel #4
0
        public async Task <StreamSubscription> AddSubscription(string streamProviderName, IStreamIdentity streamIdentity, GrainReference grainRef)
        {
            var consumer       = grainRef.AsReference <IStreamConsumerExtension>();
            var streamId       = StreamId.GetStreamId(streamIdentity.Guid, streamProviderName, streamIdentity.Namespace);
            var subscriptionId = streamPubSub.CreateSubscriptionId(
                streamId, consumer);
            await streamPubSub.RegisterConsumer(subscriptionId, streamId, streamProviderName, consumer, null);

            var newSub = new StreamSubscription(subscriptionId.Guid, streamProviderName, streamId, grainRef.GrainId);

            return(newSub);
        }
Beispiel #5
0
        public async Task UnregisterConsumerFaultTest()
        {
            this.fixture.Logger.Info("************************ UnregisterConsumerFaultTest *********************************");
            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);

            // Add two consumers so when we remove the first it does a storage write, not a storage clear.
            GuidId subscriptionId1 = GuidId.GetGuidId(Guid.NewGuid());
            GuidId subscriptionId2 = GuidId.GetGuidId(Guid.NewGuid());
            await pubSubGrain.RegisterConsumer(subscriptionId1, streamId, null, null);

            await pubSubGrain.RegisterConsumer(subscriptionId2, streamId, null, null);

            int consumers = await pubSubGrain.ConsumerCount(streamId);

            Assert.Equal(2, consumers);

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

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

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

            consumers = await pubSubGrain.ConsumerCount(streamId);

            Assert.Equal(1, consumers);

            // inject clear fault, because removing last consumer 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.UnregisterConsumer(subscriptionId2, streamId));

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

            consumers = await pubSubGrain.ConsumerCount(streamId);

            Assert.Equal(0, consumers);
        }
Beispiel #6
0
        public async Task UnregisterProducerFaultTest()
        {
            logger.Info("************************ UnregisterProducerFaultTest *********************************");
            var streamId    = StreamId.GetStreamId(Guid.NewGuid(), "ProviderName", "StreamNamespace");
            var pubSubGrain = GrainClient.GrainFactory.GetGrain <IPubSubRendezvousGrain>(
                streamId.Guid,
                keyExtension: streamId.ProviderName + "_" + streamId.Namespace);
            var faultGrain = GrainClient.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);
        }
Beispiel #7
0
 public async Task RemoveSubscription(string streamProviderName, IStreamIdentity streamId, Guid subscriptionId)
 {
     await streamPubSub.UnregisterConsumer(GuidId.GetGuidId(subscriptionId), StreamId.GetStreamId(streamId.Guid, streamProviderName, streamId.Namespace), streamProviderName);
 }