예제 #1
0
        public void When_endpoint_reported_within_staleness_period()
        {
            var now = DateTime.UtcNow;

            tracker.Record(A1, now);
            Assert.IsFalse(tracker.IsStale(A1));
        }
        public void ValidateIfConnectivityMathIsCorrect()
        {
            var endpointName = "Endpoint";

            var instanceIds = new[] { "a", "b", "c" };
            var instances   = instanceIds.Select(instanceId => new EndpointInstanceId(endpointName, instanceId)).ToArray();

            Array.ForEach(instances, instance => endpointRegistry.Record(instance));

            var period = HistoryPeriod.FromMinutes(DiagramApiController.DefaultHistory); // 5 minutes, 5 second period

            var now       = DateTime.UtcNow;
            var timestamp = now.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals)); // now - 5 seconds

            var samples = new[] {
                new RawMessage.Entry {
                    DateTicks = timestamp.Ticks, Value = 5
                },
                new RawMessage.Entry {
                    DateTicks = timestamp.Ticks, Value = 10
                }
            };

            var connected = instances.Take(2).ToArray();

            Array.ForEach(connected, instance => activityTracker.Record(instance, now));
            Array.ForEach(connected, instance => processingTimeStore.Store(samples, instance, EndpointMessageType.Unknown(instance.EndpointName)));

            var result        = apiController.GetAllEndpointsMetrics();
            var contentResult = result as OkNegotiatedContentResult <MonitoredEndpoint[]>;
            var model         = contentResult.Content;
            var item          = model[0];

            Assert.AreEqual(3, item.EndpointInstanceIds.Length, nameof(item.EndpointInstanceIds));
            Assert.AreEqual(2, item.ConnectedCount, nameof(item.ConnectedCount));
            Assert.AreEqual(1, item.DisconnectedCount, nameof(item.DisconnectedCount));
        }