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; }