コード例 #1
0
        public async Task DeactivationTest(Guid streamGuid, string streamNamespace)
        {
            // get producer and consumer
            ISampleStreaming_ProducerGrain     producer = SampleStreaming_ProducerGrainFactory.GetGrain(Guid.NewGuid());
            IMultipleSubscriptionConsumerGrain consumer = MultipleSubscriptionConsumerGrainFactory.GetGrain(Guid.NewGuid());

            // subscribe (PubSubRendezvousGrain will have one consumer)
            StreamSubscriptionHandle <int> subscriptionHandle = await consumer.BecomeConsumer(streamGuid, streamNamespace, streamProviderName);

            // produce one message (PubSubRendezvousGrain will have one consumer and one producer)
            await producer.BecomeProducer(streamGuid, streamNamespace, streamProviderName);

            await producer.Produce();

            var count = await consumer.GetNumberConsumed();

            Assert.AreEqual(count[subscriptionHandle], 1, "Consumer grain has not received stream message");

            //TODO: trigger deactivation programmatically
            await Task.Delay(TimeSpan.FromMilliseconds(130000)); // wait for the PubSubRendezvousGrain and the SampleStreaming_ProducerGrain to be deactivated

            // deactivating PubSubRendezvousGrain and SampleStreaming_ProducerGrain during the same GC cycle causes a deadlock
            // resume producing after the PubSubRendezvousGrain and the SampleStreaming_ProducerGrain grains have been deactivated:

            await producer.BecomeProducer(streamGuid, streamNamespace, streamProviderName).WithTimeout(Timeout, "BecomeProducer is hung due to deactivation deadlock");

            await producer.Produce().WithTimeout(Timeout, "Produce is hung due to deactivation deadlock");

            // consumer grain should continue to receive stream messages:
            count = await consumer.GetNumberConsumed();

            Assert.AreEqual(count[subscriptionHandle], 2, "Consumer did not receive stream messages after PubSubRendezvousGrain and SampleStreaming_ProducerGrain reactivation");
        }
コード例 #2
0
        public async Task MultipleSubscriptionTest(Guid streamGuid, string streamNamespace)
        {
            // get producer and consumer
            ISampleStreaming_ProducerGrain     producer = SampleStreaming_ProducerGrainFactory.GetGrain(Guid.NewGuid());
            IMultipleSubscriptionConsumerGrain consumer = MultipleSubscriptionConsumerGrainFactory.GetGrain(Guid.NewGuid());

            // setup two subscriptions
            StreamSubscriptionHandle <int> firstSubscriptionHandle = await consumer.BecomeConsumer(streamGuid, streamNamespace, streamProviderName);

            StreamSubscriptionHandle <int> secondSubscriptionHandle = await consumer.BecomeConsumer(streamGuid, streamNamespace, streamProviderName);

            // produce some messages
            await producer.BecomeProducer(streamGuid, streamNamespace, streamProviderName);

            await producer.StartPeriodicProducing();

            Thread.Sleep(1000);
            await producer.StopPeriodicProducing();

            // check
            await UnitTestUtils.WaitUntilAsync(lastTry => CheckCounters(producer, consumer, 2, lastTry), Timeout);

            // unsubscribe
            await consumer.StopConsuming(firstSubscriptionHandle);

            await consumer.StopConsuming(secondSubscriptionHandle);
        }
コード例 #3
0
        public async Task ResubscriptionTest(Guid streamGuid, string streamNamespace)
        {
            // get producer and consumer
            ISampleStreaming_ProducerGrain     producer = SampleStreaming_ProducerGrainFactory.GetGrain(Guid.NewGuid());
            IMultipleSubscriptionConsumerGrain consumer = MultipleSubscriptionConsumerGrainFactory.GetGrain(Guid.NewGuid());

            await producer.BecomeProducer(streamGuid, streamNamespace, streamProviderName);

            // setup one subscription and send messsages
            StreamSubscriptionHandle <int> firstSubscriptionHandle = await consumer.BecomeConsumer(streamGuid, streamNamespace, streamProviderName);

            await producer.StartPeriodicProducing();

            Thread.Sleep(1000);
            await producer.StopPeriodicProducing();

            await UnitTestUtils.WaitUntilAsync(lastTry => CheckCounters(producer, consumer, 1, lastTry), Timeout);

            // Resume
            StreamSubscriptionHandle <int> resumeHandle = await consumer.Resume(firstSubscriptionHandle);

            Assert.AreEqual(firstSubscriptionHandle, resumeHandle, "Handle matches");

            await producer.StartPeriodicProducing();

            Thread.Sleep(1000);
            await producer.StopPeriodicProducing();

            await UnitTestUtils.WaitUntilAsync(lastTry => CheckCounters(producer, consumer, 1, lastTry), Timeout);

            // remove subscription
            await consumer.StopConsuming(resumeHandle);
        }
コード例 #4
0
        public async Task AddAndRemoveSubscriptionTest(Guid streamGuid, string streamNamespace)
        {
            // get producer and consumer
            ISampleStreaming_ProducerGrain     producer = SampleStreaming_ProducerGrainFactory.GetGrain(Guid.NewGuid());
            IMultipleSubscriptionConsumerGrain consumer = MultipleSubscriptionConsumerGrainFactory.GetGrain(Guid.NewGuid());

            await producer.BecomeProducer(streamGuid, streamNamespace, streamProviderName);

            // setup one subscription and send messsages
            StreamSubscriptionHandle <int> firstSubscriptionHandle = await consumer.BecomeConsumer(streamGuid, streamNamespace, streamProviderName);

            await producer.StartPeriodicProducing();

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            await producer.StopPeriodicProducing();

            await TestingUtils.WaitUntilAsync(lastTry => CheckCounters(producer, consumer, 1, lastTry), Timeout);

            // clear counts
            await consumer.ClearNumberConsumed();

            await producer.ClearNumberProduced();

            // setup second subscription and send messages
            StreamSubscriptionHandle <int> secondSubscriptionHandle = await consumer.BecomeConsumer(streamGuid, streamNamespace, streamProviderName);

            await producer.StartPeriodicProducing();

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            await producer.StopPeriodicProducing();

            await TestingUtils.WaitUntilAsync(lastTry => CheckCounters(producer, consumer, 2, lastTry), Timeout);

            // clear counts
            await consumer.ClearNumberConsumed();

            await producer.ClearNumberProduced();

            // remove first subscription and send messages
            await consumer.StopConsuming(firstSubscriptionHandle);

            await producer.StartPeriodicProducing();

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            await producer.StopPeriodicProducing();

            await TestingUtils.WaitUntilAsync(lastTry => CheckCounters(producer, consumer, 1, lastTry), Timeout);

            // remove second subscription
            await consumer.StopConsuming(secondSubscriptionHandle);
        }
コード例 #5
0
        private async Task <bool> CheckCounter(IBatchProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer,
                                               StreamSubscriptionHandle <int> handler, bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();

            var consumers = await consumer.GetNumberConsumed();

            var numConsumed = consumers[handler];

            _logger.Info("Checking now for handler for stream: {0}", handler.StreamIdentity.ToString());

            return(await CheckCounter(numProduced, numConsumed, assertIsTrue));
        }
コード例 #6
0
        public async Task ActiveSubscriptionTest(Guid streamGuid, string streamNamespace)
        {
            const int subscriptionCount = 10;

            // get producer and consumer
            IMultipleSubscriptionConsumerGrain consumer = MultipleSubscriptionConsumerGrainFactory.GetGrain(Guid.NewGuid());

            // create expected subscriptions
            IEnumerable <Task <StreamSubscriptionHandle <int> > > subscriptionTasks =
                Enumerable.Range(0, subscriptionCount)
                .Select(async i => await consumer.BecomeConsumer(streamGuid, streamNamespace, streamProviderName));
            List <StreamSubscriptionHandle <int> > expectedSubscriptions = (await Task.WhenAll(subscriptionTasks)).ToList();

            // query actuall subscriptions
            IList <StreamSubscriptionHandle <int> > actualSubscriptions = await consumer.GetAllSubscriptions(streamGuid, streamNamespace, streamProviderName);

            // validate
            Assert.AreEqual(subscriptionCount, actualSubscriptions.Count, "Subscription Count");
            Assert.AreEqual(subscriptionCount, expectedSubscriptions.Count, "Reported subscription Count");
            foreach (StreamSubscriptionHandle <int> subscription in actualSubscriptions)
            {
                Assert.IsTrue(expectedSubscriptions.Contains(subscription), "Subscription Match");
            }

            // unsubscribe from one of the subscriptions
            StreamSubscriptionHandle <int> firstHandle = expectedSubscriptions.First();
            await consumer.StopConsuming(firstHandle);

            expectedSubscriptions.Remove(firstHandle);

            // query actuall subscriptions again
            actualSubscriptions = await consumer.GetAllSubscriptions(streamGuid, streamNamespace, streamProviderName);

            // validate
            Assert.AreEqual(subscriptionCount - 1, actualSubscriptions.Count, "Subscription Count");
            Assert.AreEqual(subscriptionCount - 1, expectedSubscriptions.Count, "Reported subscription Count");
            foreach (StreamSubscriptionHandle <int> subscription in actualSubscriptions)
            {
                Assert.IsTrue(expectedSubscriptions.Contains(subscription), "Subscription Match");
            }

            // unsubscribe from the rest of the subscriptions
            expectedSubscriptions.ForEach(async h => await consumer.StopConsuming(h));

            // query actuall subscriptions again
            actualSubscriptions = await consumer.GetAllSubscriptions(streamGuid, streamNamespace, streamProviderName);

            // validate
            Assert.AreEqual(0, actualSubscriptions.Count, "Subscription Count");
        }
コード例 #7
0
        private async Task <bool> CheckCounter(IBatchProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int consumersCount,
                                               bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();

            var numConsumed = await consumer.GetNumberConsumed();

            if (assertIsTrue)
            {
                Assert.IsTrue(numProduced > 0, "No messages produced");
                Assert.AreEqual(consumersCount, numConsumed.Count, "Number of consumers is incorrect");

                foreach (int consumed in numConsumed.Values)
                {
                    Assert.AreEqual(numProduced, consumed, "Produced and consumed counts do not match");
                }
            }
            else if (numProduced <= 0 ||
                     numConsumed.Count != consumersCount ||
                     numConsumed.Values.Any(consumed => consumed != numProduced))
            {
                if (numProduced <= 0)
                {
                    _logger.Info("Noting produced yet..");
                }
                if (numConsumed.Count != consumersCount)
                {
                    _logger.Info("Consumer num doesn't match yet..");
                }
                foreach (var consumed in numConsumed.Values)
                {
                    if (consumed != numProduced)
                    {
                        _logger.Info("numProduced != consumed: Produced and consumed counts do not match. numProduced = {0}, consumed = {1}",
                                     numProduced, consumed);
                    }
                }

                return(false);
            }

            _logger.Info("All counts are equal. numProduced = {0}, consumersCount = {1}, Total consumed = {2}", numProduced, consumersCount, numConsumed.Values.Sum());

            return(true);
        }
コード例 #8
0
        public async Task ResubscriptionAfterDeactivationTest(Guid streamGuid, string streamNamespace)
        {
            // get producer and consumer
            ISampleStreaming_ProducerGrain     producer = SampleStreaming_ProducerGrainFactory.GetGrain(Guid.NewGuid());
            IMultipleSubscriptionConsumerGrain consumer = MultipleSubscriptionConsumerGrainFactory.GetGrain(Guid.NewGuid());

            await producer.BecomeProducer(streamGuid, streamNamespace, streamProviderName);

            // setup one subscription and send messsages
            StreamSubscriptionHandle <int> firstSubscriptionHandle = await consumer.BecomeConsumer(streamGuid, streamNamespace, streamProviderName);

            await producer.StartPeriodicProducing();

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            await producer.StopPeriodicProducing();

            await TestingUtils.WaitUntilAsync(lastTry => CheckCounters(producer, consumer, 1, lastTry), Timeout);

            // Deactivate grain
            await consumer.Deactivate();

            // make sure grain has time to deactivate.
            await Task.Delay(TimeSpan.FromMilliseconds(100));

            // clear producer counts
            await producer.ClearNumberProduced();

            // Resume
            StreamSubscriptionHandle <int> resumeHandle = await consumer.Resume(firstSubscriptionHandle);

            Assert.AreEqual(firstSubscriptionHandle, resumeHandle, "Handle matches");

            await producer.StartPeriodicProducing();

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            await producer.StopPeriodicProducing();

            await TestingUtils.WaitUntilAsync(lastTry => CheckCounters(producer, consumer, 1, lastTry), Timeout);

            // remove subscription
            await consumer.StopConsuming(resumeHandle);
        }
コード例 #9
0
        private async Task<bool> CheckCounters(IMultipleProducingProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int producerCount, int consumerCount, bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();
            var numConsumed = await consumer.GetNumberConsumed();

            var consumed = numConsumed.First().Value;

            if (assertIsTrue)
            {
                Assert.IsTrue(numProduced.Any(pair => pair.Value > 0), "Events were not produced");
                Assert.AreEqual(consumerCount, numConsumed.Count, "Incorrect number of consumers");
                Assert.AreEqual(producerCount, numProduced.Count, "Incorrect number of producers");

                foreach (int produced in numProduced.Values)
                {
                    Assert.AreEqual(produced, consumed, "Produced and Consumed counts do not match");
                }
            }
            else if (numProduced.Any(pair => pair.Value <= 0) || // no events produced?
                     consumerCount != numConsumed.Count || // subscription counts are wrong?
                     producerCount != numProduced.Count ||
                     numProduced.Values.All(producedCount => producedCount != consumed)) // consumed events don't match produced events for any subscription or specific handler (if sent)?
            {
                if (numProduced.Any(pair => pair.Value <= 0))
                {
                    _logger.Info("numProduced <= 0: Events were not produced");
                }
                if (consumerCount != numConsumed.Count)
                {
                    _logger.Info("consumerCount != numConsumed.Count: Incorrect number of consumers. consumerCount = {0}, numConsumed.Count = {1}",
                        consumerCount, numConsumed.Count);
                }
                if (producerCount != numProduced.Count)
                {
                    _logger.Info("producerCount != numProduced.Count: Incorrect number of producer. producerCount = {0}, numProduced.Count = {1}",
                        producerCount, numProduced.Count);
                }

                foreach (var produced in numProduced.Values)
                {
                    if (produced != consumed)
                    {
                        _logger.Info("numProduced != consumed: Produced and consumed counts do not match. numProduced = {0}, consumed = {1}",
                            produced, consumed);
                        //numProduced, Utils.DictionaryToString(numConsumed));
                    }
                }
                return false;
            }

            _logger.Info("All counts are equal. numProduced = {0}, consumersCount = {1}", numProduced, consumerCount); //Utils.DictionaryToString(numConsumed));    

            return true;
        }
        private async Task <bool> CheckCounters(IMultipleProducingProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int producerCount, int consumerCount, bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();

            var numConsumed = await consumer.GetNumberConsumed();

            var consumed = numConsumed.First().Value;

            if (assertIsTrue)
            {
                Assert.IsTrue(numProduced.Any(pair => pair.Value > 0), "Events were not produced");
                Assert.AreEqual(consumerCount, numConsumed.Count, "Incorrect number of consumers");
                Assert.AreEqual(producerCount, numProduced.Count, "Incorrect number of producers");

                foreach (int produced in numProduced.Values)
                {
                    Assert.AreEqual(produced, consumed, "Produced and Consumed counts do not match");
                }
            }
            else if (numProduced.Any(pair => pair.Value <= 0) ||                         // no events produced?
                     consumerCount != numConsumed.Count ||                               // subscription counts are wrong?
                     producerCount != numProduced.Count ||
                     numProduced.Values.All(producedCount => producedCount != consumed)) // consumed events don't match produced events for any subscription or specific handler (if sent)?
            {
                if (numProduced.Any(pair => pair.Value <= 0))
                {
                    _logger.Info("numProduced <= 0: Events were not produced");
                }
                if (consumerCount != numConsumed.Count)
                {
                    _logger.Info("consumerCount != numConsumed.Count: Incorrect number of consumers. consumerCount = {0}, numConsumed.Count = {1}",
                                 consumerCount, numConsumed.Count);
                }
                if (producerCount != numProduced.Count)
                {
                    _logger.Info("producerCount != numProduced.Count: Incorrect number of producer. producerCount = {0}, numProduced.Count = {1}",
                                 producerCount, numProduced.Count);
                }

                foreach (var produced in numProduced.Values)
                {
                    if (produced != consumed)
                    {
                        _logger.Info("numProduced != consumed: Produced and consumed counts do not match. numProduced = {0}, consumed = {1}",
                                     produced, consumed);
                        //numProduced, Utils.DictionaryToString(numConsumed));
                    }
                }
                return(false);
            }

            _logger.Info("All counts are equal. numProduced = {0}, consumersCount = {1}", numProduced, consumerCount); //Utils.DictionaryToString(numConsumed));

            return(true);
        }
        private async Task <bool> CheckCounters(ISampleStreaming_ProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int consumerCount, StreamSubscriptionHandle <int> handler, bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();

            var numConsumed = await consumer.GetNumberConsumed();

            if (assertIsTrue)
            {
                Assert.IsTrue(numProduced > 0, "Events were not produced");
                Assert.AreEqual(consumerCount, numConsumed.Count, "Incorrect number of consumers");
                if (handler != null)
                {
                    var numHandlerConsumed = numConsumed[handler];
                    Assert.AreEqual(numProduced, numHandlerConsumed, "Producer and consumer do not match");
                }
                else
                {
                    foreach (int consumed in numConsumed.Values)
                    {
                        Assert.AreEqual(numProduced, consumed, "Produced and consumed counts do not match");
                    }
                }
            }
            else if (numProduced <= 0 ||                                                                                                            // no events produced?
                     consumerCount != numConsumed.Count ||                                                                                          // subscription counts are wrong?
                     handler == null ? numConsumed.Values.All(consumedCount => consumedCount != numProduced) : numConsumed[handler] != numProduced) // consumed events don't match produced events for any subscription or specific handler (if sent)?
            {
                if (numProduced <= 0)
                {
                    _logger.Info("numProduced <= 0: Events were not produced");
                }
                if (consumerCount != numConsumed.Count)
                {
                    _logger.Info("consumerCount != numConsumed.Count: Incorrect number of consumers. consumerCount = {0}, numConsumed.Count = {1}",
                                 consumerCount, numConsumed.Count);
                }
                foreach (int consumed in numConsumed.Values)
                {
                    if (numProduced != consumed)
                    {
                        _logger.Info("numProduced != consumed: Produced and consumed counts do not match. numProduced = {0}, consumed = {1}",
                                     numProduced, consumed);
                        //numProduced, Utils.DictionaryToString(numConsumed));
                    }
                }
                return(false);
            }

            if (handler != null)
            {
                _logger.Info("All counts are equal. numProduced = {0}, numHandlerConsumed = {1}, consumersCount = {2}", numProduced, numConsumed[handler], consumerCount); //Utils.DictionaryToString(numConsumed));
            }
            else
            {
                _logger.Info("All counts are equal. numProduced = {0}, consumersCount = {1}", numProduced, consumerCount); //Utils.DictionaryToString(numConsumed));
            }

            return(true);
        }
コード例 #12
0
        private async Task <bool> CheckCounters(ISampleStreaming_ProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int consumerCount, bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();

            var numConsumed = await consumer.GetNumberConsumed();

            if (assertIsTrue)
            {
                Assert.IsTrue(numProduced > 0, "Events were not produced");
                Assert.AreEqual(consumerCount, numConsumed.Count, "Incorrect number of consumers");
                foreach (int consumed in numConsumed.Values)
                {
                    Assert.AreEqual(numProduced, consumed, "Produced and consumed counts do not match");
                }
            }
            else if (numProduced <= 0 ||                                                    // no events produced?
                     consumerCount != numConsumed.Count ||                                  // subscription counts are wrong?
                     numConsumed.Values.Any(consumedCount => consumedCount != numProduced)) // consumed events don't match produced events for any subscription?
            {
                return(false);
            }
            return(true);
        }
コード例 #13
0
        private async Task<bool> CheckCounter(IBatchProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int consumersCount,
            bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();
            var numConsumed = await consumer.GetNumberConsumed();

            if (assertIsTrue)
            {
                Assert.IsTrue(numProduced > 0, "No messages produced");
                Assert.AreEqual(consumersCount, numConsumed.Count, "Number of consumers is incorrect" );

                foreach (int consumed in numConsumed.Values)
                {
                    Assert.AreEqual(numProduced, consumed, "Produced and consumed counts do not match");
                }
            }
            else if (numProduced <= 0 ||
                     numConsumed.Count != consumersCount ||
                     numConsumed.Values.Any(consumed => consumed != numProduced))
            {
                if (numProduced <= 0)
                {
                    _logger.Info("Noting produced yet..");
                }
                if (numConsumed.Count != consumersCount)
                {
                    _logger.Info("Consumer num doesn't match yet..");
                }
                foreach (var consumed in numConsumed.Values)
                {
                    if (consumed != numProduced)
                    {
                        _logger.Info("numProduced != consumed: Produced and consumed counts do not match. numProduced = {0}, consumed = {1}",
                            numProduced, consumed);
                    }
                }

                return false;
            }

            _logger.Info("All counts are equal. numProduced = {0}, consumersCount = {1}, Total consumed = {2}", numProduced, consumersCount, numConsumed.Values.Sum());

            return true;
        }
コード例 #14
0
        private async Task<bool> CheckCounter(IBatchProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer,
            StreamSubscriptionHandle<int> handler, bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();
            var consumers = await consumer.GetNumberConsumed();
            var numConsumed = consumers[handler];
            
            _logger.Info("Checking now for handler for stream: {0}", handler.StreamIdentity.ToString());

            return await CheckCounter(numProduced, numConsumed, assertIsTrue);
        }
コード例 #15
0
 private async Task<bool> CheckCounters(ISampleStreaming_ProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int consumerCount, bool assertIsTrue)
 {
     var numProduced = await producer.GetNumberProduced();
     var numConsumed = await consumer.GetNumberConsumed();
     if (assertIsTrue)
     {
         Assert.IsTrue(numConsumed.Values.All(v => v.Item2 == 0), "Errors");
         Assert.IsTrue(numProduced > 0, "Events were not produced");
         Assert.AreEqual(consumerCount, numConsumed.Count, "Incorrect number of consumers");
         foreach (int consumed in numConsumed.Values.Select(v => v.Item1))
         {
             Assert.AreEqual(numProduced, consumed, "Produced and consumed counts do not match");
         }
     }
     else if (numProduced <= 0 || // no events produced?
              consumerCount != numConsumed.Count || // subscription counts are wrong?
              numConsumed.Values.Any(consumedCount => consumedCount.Item1 != numProduced) ||// consumed events don't match produced events for any subscription?
              numConsumed.Values.Any(v => v.Item2 != 0)) // stream errors
     {
         if (numProduced <= 0)
         {
             logger.Info("numProduced <= 0: Events were not produced");
         }
         if (consumerCount != numConsumed.Count)
         {
             logger.Info("consumerCount != numConsumed.Count: Incorrect number of consumers. consumerCount = {0}, numConsumed.Count = {1}",
                 consumerCount, numConsumed.Count);
         }
         foreach (var consumed in numConsumed)
         {
             if (numProduced != consumed.Value.Item1)
             {
                 logger.Info("numProduced != consumed: Produced and consumed counts do not match. numProduced = {0}, consumed = {1}",
                     numProduced, consumed.Key.HandleId + " -> " + consumed.Value);
                     //numProduced, Utils.DictionaryToString(numConsumed));
             }
         }
         return false;
     }
     logger.Info("All counts are equal. numProduced = {0}, numConsumed = {1}", numProduced, 
         Utils.EnumerableToString(numConsumed, kvp => kvp.Key.HandleId.ToString() + "->" +  kvp.Value.ToString()));
     return true;
 }
コード例 #16
0
        private async Task <bool> CheckCounters(ISampleStreaming_ProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int consumerCount, bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();

            var numConsumed = await consumer.GetNumberConsumed();

            if (assertIsTrue)
            {
                Assert.IsTrue(numConsumed.Values.All(v => v.Item2 == 0), "Errors");
                Assert.IsTrue(numProduced > 0, "Events were not produced");
                Assert.AreEqual(consumerCount, numConsumed.Count, "Incorrect number of consumers");
                foreach (int consumed in numConsumed.Values.Select(v => v.Item1))
                {
                    Assert.AreEqual(numProduced, consumed, "Produced and consumed counts do not match");
                }
            }
            else if (numProduced <= 0 ||                                                            // no events produced?
                     consumerCount != numConsumed.Count ||                                          // subscription counts are wrong?
                     numConsumed.Values.Any(consumedCount => consumedCount.Item1 != numProduced) || // consumed events don't match produced events for any subscription?
                     numConsumed.Values.Any(v => v.Item2 != 0))                                     // stream errors
            {
                if (numProduced <= 0)
                {
                    logger.Info("numProduced <= 0: Events were not produced");
                }
                if (consumerCount != numConsumed.Count)
                {
                    logger.Info("consumerCount != numConsumed.Count: Incorrect number of consumers. consumerCount = {0}, numConsumed.Count = {1}",
                                consumerCount, numConsumed.Count);
                }
                foreach (var consumed in numConsumed)
                {
                    if (numProduced != consumed.Value.Item1)
                    {
                        logger.Info("numProduced != consumed: Produced and consumed counts do not match. numProduced = {0}, consumed = {1}",
                                    numProduced, consumed.Key.HandleId + " -> " + consumed.Value);
                        //numProduced, Utils.DictionaryToString(numConsumed));
                    }
                }
                return(false);
            }
            logger.Info("All counts are equal. numProduced = {0}, numConsumed = {1}", numProduced,
                        Utils.EnumerableToString(numConsumed, kvp => kvp.Key.HandleId.ToString() + "->" + kvp.Value.ToString()));
            return(true);
        }
コード例 #17
0
        private async Task<bool> CheckCounters(ISampleStreaming_ProducerGrain producer, IMultipleSubscriptionConsumerGrain consumer, int consumerCount, StreamSubscriptionHandle<int> handler, bool assertIsTrue)
        {
            var numProduced = await producer.GetNumberProduced();
            var numConsumed = await consumer.GetNumberConsumed();
            if (assertIsTrue)
            {
                Assert.IsTrue(numProduced > 0, "Events were not produced");
                Assert.AreEqual(consumerCount, numConsumed.Count, "Incorrect number of consumers");
                if (handler != null)
                {
                    var numHandlerConsumed = numConsumed[handler];
                    Assert.AreEqual(numProduced, numHandlerConsumed, "Producer and consumer do not match");
                }
                else
                {
                    foreach (int consumed in numConsumed.Values)
                    {
                        Assert.AreEqual(numProduced, consumed, "Produced and consumed counts do not match");
                    }
                }
            }
            else if (numProduced <= 0 || // no events produced?
                     consumerCount != numConsumed.Count || // subscription counts are wrong?
                     handler == null ? numConsumed.Values.All(consumedCount => consumedCount != numProduced) : numConsumed[handler] != numProduced) // consumed events don't match produced events for any subscription or specific handler (if sent)?
            {
                if (numProduced <= 0)
                {
                    _logger.Info("numProduced <= 0: Events were not produced");
                }
                if (consumerCount != numConsumed.Count)
                {
                    _logger.Info("consumerCount != numConsumed.Count: Incorrect number of consumers. consumerCount = {0}, numConsumed.Count = {1}",
                        consumerCount, numConsumed.Count);
                }
                foreach (int consumed in numConsumed.Values)
                {
                    if (numProduced != consumed)
                    {
                        _logger.Info("numProduced != consumed: Produced and consumed counts do not match. numProduced = {0}, consumed = {1}",
                            numProduced, consumed);
                        //numProduced, Utils.DictionaryToString(numConsumed));
                    }
                }
                return false;
            }

            if (handler != null)
            {
                _logger.Info("All counts are equal. numProduced = {0}, numHandlerConsumed = {1}, consumersCount = {2}", numProduced, numConsumed[handler], consumerCount); //Utils.DictionaryToString(numConsumed));    
            }
            else
            {
                _logger.Info("All counts are equal. numProduced = {0}, consumersCount = {1}", numProduced, consumerCount); //Utils.DictionaryToString(numConsumed));    
            }
         
            return true;
        }