Esempio n. 1
0
        private Task ValidatePubSub(StreamId streamId, string providerName)
        {
            var intStreamId = new InternalStreamId(providerName, streamId);
            var rendez      = this.client.GetGrain <IPubSubRendezvousGrain>(intStreamId.ToString());

            return(rendez.Validate());
        }
Esempio n. 2
0
 public Task UnregisterConsumer(GuidId subscriptionId, InternalStreamId streamId)
 {
     if (!IsImplicitSubscriber(subscriptionId, streamId))
     {
         throw new ArgumentOutOfRangeException(streamId.ToString(), "Only implicit subscriptions are supported.");
     }
     return(Task.CompletedTask);
 }
 public Task RegisterConsumer(GuidId subscriptionId, InternalStreamId streamId, IStreamConsumerExtension streamConsumer, IStreamFilterPredicateWrapper filter)
 {
     if (!IsImplicitSubscriber(streamConsumer, streamId))
     {
         throw new ArgumentOutOfRangeException(streamId.ToString(), "Only implicit subscriptions are supported.");
     }
     return(Task.CompletedTask);
 }
Esempio n. 4
0
 public Task RegisterConsumer(GuidId subscriptionId, InternalStreamId streamId, IStreamConsumerExtension streamConsumer, string filterData)
 {
     // TODO BPETIT filter data?
     if (!IsImplicitSubscriber(streamConsumer, streamId))
     {
         throw new ArgumentOutOfRangeException(streamId.ToString(), "Only implicit subscriptions are supported.");
     }
     return(Task.CompletedTask);
 }
Esempio n. 5
0
        public GuidId CreateSubscriptionId(InternalStreamId streamId, IStreamConsumerExtension streamConsumer)
        {
            GrainId grainId = GrainExtensions.GetGrainId(streamConsumer);
            Guid    subscriptionGuid;

            if (!implicitTable.TryGetImplicitSubscriptionGuid(grainId, streamId, out subscriptionGuid))
            {
                throw new ArgumentOutOfRangeException(streamId.ToString(), "Only implicit subscriptions are supported.");
            }
            return(GuidId.GetGuidId(subscriptionGuid));
        }
Esempio n. 6
0
 public override string ToString()
 {
     return(streamId.ToString());
 }
        public virtual async Task TestBecomeConsumerSlim(StreamId streamId, string providerName)
        {
            InitStream(streamId, providerName);
            var observer = new MyStreamObserver <int>(logger);

            //var subsHandle = await State.Stream.SubscribeAsync(observer);

            var(myExtension, myExtensionReference) = this.streamProviderRuntime.BindExtension <StreamConsumerExtension, IStreamConsumerExtension>(
                () => new StreamConsumerExtension(streamProviderRuntime));
            string extKey = providerName + "_" + Encoding.UTF8.GetString(State.Stream.StreamId.Namespace.ToArray());
            var    id     = new InternalStreamId(providerName, streamId);
            IPubSubRendezvousGrain pubsub = GrainFactory.GetGrain <IPubSubRendezvousGrain>(id.ToString());
            GuidId subscriptionId         = GuidId.GetNewGuidId();
            await pubsub.RegisterConsumer(subscriptionId, ((StreamImpl <int>)State.Stream).InternalStreamId, myExtensionReference, null);

            myExtension.SetObserver(subscriptionId, ((StreamImpl <int>)State.Stream), observer, null, null, null);
        }
Esempio n. 8
0
 private IPubSubRendezvousGrain GetRendezvousGrain(InternalStreamId streamId)
 {
     return(grainFactory.GetGrain <IPubSubRendezvousGrain>(streamId.ToString()));
 }
Esempio n. 9
0
        //private async Task Test_Stream_Churn_TimePeriod(
        //    string streamProviderName,
        //    int pipelineSize,
        //    TimeSpan duration,
        //    int numConsumers = 9,
        //    int numProducers = 1)
        //{
        //    output.WriteLine("Testing Subscription churn for duration {0} with {1} Consumers and {2} Producers per Stream",
        //        duration, numConsumers, numProducers);

        //    AsyncPipeline pipeline = new AsyncPipeline(pipelineSize);
        //    var promises = new List<Task>();

        //    Stopwatch sw = Stopwatch.StartNew();

        //    for (int i = 0; sw.Elapsed <= duration; i++)
        //    {
        //        Guid streamId = Guid.NewGuid();
        //        Task promise = SetupOneStream(streamId, streamProviderName, pipeline, numConsumers, numProducers);
        //        promises.Add(promise);
        //    }
        //    await Task.WhenAll(promises);
        //    sw.Stop();
        //    TimeSpan elapsed = sw.Elapsed;
        //    int totalSubscription = numSt* numConsumers);
        //    double rps = totalSubscription/elapsed.TotalSeconds;
        //    output.WriteLine("Subscriptions-per-second = {0} during period {1}", rps, elapsed);
        //    Assert.NotEqual(0.0, rps, "RPS greater than zero");
        //}

        private void WarmUpPubSub(string streamProviderName, StreamId[] streamIds, AsyncPipeline pipeline)
        {
            int numStreams = streamIds.Length;

            // Warm up PubSub for the appropriate streams
            for (int i = 0; i < numStreams; i++)
            {
                var streamId = new InternalStreamId(streamProviderName, streamIds[i]);
                _ = streamProviderName + "_" + this.StreamNamespace;

                IPubSubRendezvousGrain pubsub = this.GrainFactory.GetGrain <IPubSubRendezvousGrain>(streamId.ToString());

                Task promise = pubsub.Validate();

                pipeline.Add(promise);
            }
            pipeline.Wait();
        }
Esempio n. 10
0
        public virtual async Task TestBecomeConsumerSlim(Guid streamIdGuid, string providerName)
        {
            // TODO NOT SURE THIS FUNCTION MAKESE ANY SENSE
            var streamId = StreamId.Create(null, streamIdGuid);

            InitStream(streamId, providerName);
            var observer = new MyStreamObserver <int>(logger);

            var(myExtension, myExtensionReference) = this.streamProviderRuntime.BindExtension <StreamConsumerExtension, IStreamConsumerExtension>(
                () => new StreamConsumerExtension(streamProviderRuntime));

            var id = new InternalStreamId(providerName, streamId);
            IPubSubRendezvousGrain pubsub = GrainFactory.GetGrain <IPubSubRendezvousGrain>(id.ToString());
            GuidId subscriptionId         = GuidId.GetNewGuidId();
            await pubsub.RegisterConsumer(subscriptionId, ((StreamImpl <int>)State.Stream).InternalStreamId, myExtensionReference, null);

            myExtension.SetObserver(subscriptionId, ((StreamImpl <int>)State.Stream), observer, null, null, null);
        }
Esempio n. 11
0
        public async Task UnregisterConsumerFaultTest()
        {
            this.fixture.Logger.LogInformation("************************ UnregisterConsumerFaultTest *********************************");
            var streamId    = new InternalStreamId("ProviderName", StreamId.Create("StreamNamespace", Guid.NewGuid()));
            var pubSubGrain = this.fixture.GrainFactory.GetGrain <IPubSubRendezvousGrain>(streamId.ToString());
            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);
        }
Esempio n. 12
0
        public async Task RegisterConsumerFaultTest()
        {
            this.fixture.Logger.LogInformation("************************ RegisterConsumerFaultTest *********************************");
            var streamId    = new InternalStreamId("ProviderName", StreamId.Create("StreamNamespace", Guid.NewGuid()));
            var pubSubGrain = this.fixture.GrainFactory.GetGrain <IPubSubRendezvousGrain>(streamId.ToString());
            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);
        }