public void CanSerializeEquivalentIntMessageReverse() { var typeRegistry = new MessageTypeRegistry(); var serializer = new RosMessageSerializer(typeRegistry); var ms = new MemoryStream(); const int expectedValue = 17; const string expectedText = "It could be any string"; var message = new EquivalentIntMessages.ShortMessage() { Value = expectedValue, Text = expectedText }; serializer.Serialize(message, ms); ms.ToArray().Should().NotBeNull(); ms.Position = 0; var deserializedMessage = (EquivalentIntMessages.IntMessage)serializer.Deserialize(typeof(EquivalentIntMessages.IntMessage), ms); deserializedMessage.Should().NotBeNull(); deserializedMessage.Value.Should().Be(expectedValue); deserializedMessage.Text.Should().Be(expectedText); }
static Func <dynamic, CancellationToken, Task <dynamic> > CreateQuery(ProcessingTimeStore processingTimeStore, EndpointRegistry endpointRegistry) { var criticalTimeStore = new CriticalTimeStore(); var retriesStore = new RetriesStore(); var queueLengthStore = new QueueLengthStore(); var settings = new Settings { EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5) }; var activityTracker = new EndpointInstanceActivityTracker(settings); var messageTypeRegistry = new MessageTypeRegistry(); var breakdownProviders = new IProvideBreakdown[] { processingTimeStore, criticalTimeStore, retriesStore, queueLengthStore }; var monitoredEndpointsModule = new MonitoredEndpointsModule(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry) { Context = new NancyContext() { Request = new Request("Get", "/monitored-endpoints/{endpointName}", "HTTP") } }; var queryAction = monitoredEndpointsModule.Routes.Single(r => r.Description.Path == "/monitored-endpoints/{endpointName}").Action; return(queryAction); }
public SerializationContext(Stream stream, IEnumerable <IRosMessageFormatter> messageFormatters, MessageTypeRegistry messageTypeRegistry) { Stream = stream ?? throw new ArgumentNullException(nameof(stream)); MessageFormatters = messageFormatters ?? throw new ArgumentNullException(nameof(messageFormatters)); MessageTypeRegistry = messageTypeRegistry ?? throw new ArgumentNullException(nameof(messageTypeRegistry)); }
public void GetType_ShouldFailPreconditionsIfPassedNullUri() { var sut = new MessageTypeRegistry(); Uri uri = null; Assert.Throws <ArgumentException>(() => sut.GetType(uri)); }
public new void Setup() { endpointRegistry = new EndpointRegistry(); criticalTimeStore = new CriticalTimeStore(); processingTimeStore = new ProcessingTimeStore(); retriesStore = new RetriesStore(); queueLengthProvider = new FakeQueueLengthProvider(); queueLengthStore = new QueueLengthStore(); queueLengthProvider.Initialize(string.Empty, (entryDtos, dto) => queueLengthStore.Store(entryDtos.Select(e => ToEntry(e)).ToArray(), ToEndpointInputQueue(dto))); var settings = new Settings { EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5) }; activityTracker = new EndpointInstanceActivityTracker(settings); messageTypeRegistry = new MessageTypeRegistry(); var breakdownProviders = new IProvideBreakdown[] { criticalTimeStore, processingTimeStore, retriesStore, queueLengthStore }; var controller = new DiagramApiController(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry) { Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/monitored-endpoint") }; GetMonitoredEndpoints = () => controller.GetAllEndpointsMetrics(); GetMonitoredSingleEndpoint = endpointName => controller.GetSingleEndpointMetrics(endpointName); }
public void CanSerializeEnumMessageAndDeserializeWithoutEnum() { var typeRegistry = new MessageTypeRegistry(); var serializer = new RosMessageSerializer(typeRegistry); var ms = new MemoryStream(); const int expectedGoalId = 17; const byte expectedStatus = 6; const string expectedText = "test"; var message = new EnumGoalStatus { GoalId = expectedGoalId, Status = (GoalStatusValue)expectedStatus, Text = expectedText }; serializer.Serialize(message, ms); ms.ToArray().Should().NotBeNull(); ms.Position = 0; var deserializedMessage = (GoalStatus)serializer.Deserialize(typeof(GoalStatus), ms); deserializedMessage.Should().NotBeNull(); deserializedMessage.GoalId.Should().Be(expectedGoalId); deserializedMessage.Status.Should().Be(expectedStatus); deserializedMessage.Text.Should().Be(expectedText); }
static DiagramApiController CreateConroller(ProcessingTimeStore processingTimeStore, EndpointRegistry endpointRegistry) { var criticalTimeStore = new CriticalTimeStore(); var retriesStore = new RetriesStore(); var queueLengthStore = new QueueLengthStore(); var settings = new Settings { EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5) }; var activityTracker = new EndpointInstanceActivityTracker(settings); var messageTypeRegistry = new MessageTypeRegistry(); var breakdownProviders = new IProvideBreakdown[] { processingTimeStore, criticalTimeStore, retriesStore, queueLengthStore }; var controller = new DiagramApiController(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry) { Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/monitored-endpoint") }; return(controller); }
public void AddShouldThrowIfUriHasBeenRegisteredToAnotherType() { var sut = new MessageTypeRegistry(); var uri = new Uri("http://messages.skutt.net/tests"); sut.Add<TestMessage>(uri); Assert.Throws<SkuttException>(() => sut.Add<TestMessage2>(uri)); }
public void AddShouldThrowIfTypeHasBeenRegisteredAgainstAnotherUri() { var sut = new MessageTypeRegistry(); var uri = new Uri("http://messages.skutt.net/test_message"); sut.Add<TestMessage>(uri); Assert.Throws<SkuttException>(() => sut.Add<TestMessage>(new Uri("http://messages.skutt.net/test_message2"))); }
public void AddShouldThrowIfUriHasBeenRegisteredToAnotherType() { var sut = new MessageTypeRegistry(); var uri = new Uri("http://messages.skutt.net/tests"); sut.Add <TestMessage>(uri); Assert.Throws <SkuttException>(() => sut.Add <TestMessage2>(uri)); }
public void AddShouldThrowIfTypeHasBeenRegisteredAgainstAnotherUri() { var sut = new MessageTypeRegistry(); var uri = new Uri("http://messages.skutt.net/test_message"); sut.Add <TestMessage>(uri); Assert.Throws <SkuttException>(() => sut.Add <TestMessage>(new Uri("http://messages.skutt.net/test_message2"))); }
public void CreateMessageTypeInfo_with_correct_md5_sum(Type messageType, string expectedMd5Sum) { var target = new MessageTypeRegistry(); var typeInfo = target.GetOrCreateMessageTypeInfo(messageType); typeInfo.Should().NotBeNull(); typeInfo.MD5Sum.Should().NotBeNull(); typeInfo.MD5Sum.Should().Be(expectedMd5Sum); }
public QueueSubscriber(string queue, MessageTypeRegistry registry, Action<object> messageHandler) { Preconditions.Require(queue, "queue"); Preconditions.Require(registry, "registry"); Preconditions.Require(messageHandler, "messageHandler"); this.queue = queue; this.registry = registry; this.queueAdd = messageHandler; }
public void MessageTypeInfo_has_correct_message_definition(Type messageType, string expectedMessageDefinition) { expectedMessageDefinition = expectedMessageDefinition?.Replace("\r\n", "\n"); var target = new MessageTypeRegistry(); var typeInfo = target.GetOrCreateMessageTypeInfo(messageType); typeInfo.Should().NotBeNull(); typeInfo.MessageDefinition.Should().NotBeNull(); typeInfo.MessageDefinition.Should().Be(expectedMessageDefinition); }
public QueueSubscriber(string queue, MessageTypeRegistry registry, Action <object> messageHandler) { Preconditions.Require(queue, "queue"); Preconditions.Require(registry, "registry"); Preconditions.Require(messageHandler, "messageHandler"); this.queue = queue; this.registry = registry; this.queueAdd = messageHandler; }
public void AddedMappingShouldBeRetrievableAsFromType() { //Arrange var sut = new MessageTypeRegistry(); var uri = new Uri("http://messages.skutt.net/tests"); //Act sut.Add<TestMessage>(uri); //Assert Assert.Equal(uri, sut.GetUri<TestMessage>()); Assert.Equal(typeof(TestMessage), sut.GetType(uri)); Assert.Equal(typeof(TestMessage), sut.GetType("http://messages.skutt.net/tests")); }
public void AddedMappingShouldBeRetrievableAsFromType() { //Arrange var sut = new MessageTypeRegistry(); var uri = new Uri("http://messages.skutt.net/tests"); //Act sut.Add <TestMessage>(uri); //Assert Assert.Equal(uri, sut.GetUri <TestMessage>()); Assert.Equal(typeof(TestMessage), sut.GetType(uri)); Assert.Equal(typeof(TestMessage), sut.GetType("http://messages.skutt.net/tests")); }
public void CanSerializeEmptyMessage() { var typeRegistry = new MessageTypeRegistry(); var serializer = new RosMessageSerializer(typeRegistry); var ms = new MemoryStream(); var message = new Empty(); serializer.Serialize(message, ms); ms.ToArray().Should().NotBeNull(); ms.Position = 0; var deserializedMessage = serializer.Deserialize(message.GetType(), ms); deserializedMessage.Should().NotBeNull(); deserializedMessage.Should().NotBeSameAs(message); }
public void Setup() { endpointRegistry = new EndpointRegistry(); criticalTimeStore = new CriticalTimeStore(); processingTimeStore = new ProcessingTimeStore(); retriesStore = new RetriesStore(); queueLengthProvider = new DefaultQueueLengthProvider(); queueLengthStore = new QueueLengthStore(); queueLengthProvider.Initialize(string.Empty, queueLengthStore); var settings = new Settings { EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5) }; activityTracker = new EndpointInstanceActivityTracker(settings); messageTypeRegistry = new MessageTypeRegistry(); var breakdownProviders = new IProvideBreakdown[] { criticalTimeStore, processingTimeStore, retriesStore, queueLengthStore }; var monitoredEndpointsModule = new MonitoredEndpointsModule(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry) { Context = new NancyContext() { Request = new Request("Get", "/monitored-endpoints", "HTTP") } }; var dictionary = monitoredEndpointsModule.Routes.ToDictionary(r => r.Description.Path, r => r.Action); GetMonitoredEndpoints = () => dictionary["/monitored-endpoints"](new object(), new CancellationToken(false)); GetMonitoredSingleEndpoint = endpointName => dictionary["/monitored-endpoints/{endpointName}"](new { EndpointName = endpointName }.ToDynamic(), new CancellationToken()); }
public async void AddRemoveHandler() { var x = new MessageTypeRegistry(); var counter = 0; Task Handler(MessageEventArgs args1) { Assert.Equal("test", args1.Body); counter++; return(Task.CompletedTask); } x.Add(Handler); var args = new MessageEventArgs("test"); await x.RunAll(args); Assert.Equal(1, counter); x.Remove(Handler); await x.RunAll(args); Assert.Equal(1, counter); }
public void Setup() { settings = new Settings { EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5) }; activityTracker = new EndpointInstanceActivityTracker(settings); processingTimeStore = new ProcessingTimeStore(); endpointRegistry = new EndpointRegistry(); var messageTypeRegistry = new MessageTypeRegistry(); var breakdownProviders = new IProvideBreakdown[] { processingTimeStore, new CriticalTimeStore(), new RetriesStore(), new QueueLengthStore() }; apiController = new DiagramApiController(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry) { Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/monitored-endpoint") }; }
public void GetType_ShouldThrowWhenNoRegistryAdded() { var sut = new MessageTypeRegistry(); Assert.Throws<SkuttException>(() => sut.GetType(new Uri("http://www.google.com"))); }
public void GetUri_ShouldThrowWhenNoRegistryAdded() { var sut = new MessageTypeRegistry(); Assert.Throws <SkuttException>(() => sut.GetUri <TestMessage>()); }
public void GetType_ShouldThrowWhenNoRegistryAdded() { var sut = new MessageTypeRegistry(); Assert.Throws <SkuttException>(() => sut.GetType(new Uri("http://www.google.com"))); }
/// <summary> /// Initializes the metric API module. /// </summary> public MonitoredEndpointsModule(IProvideBreakdown[] breakdownProviders, EndpointRegistry endpointRegistry, EndpointInstanceActivityTracker activityTracker, MessageTypeRegistry messageTypeRegistry) { var metricByInstanceLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointInstanceId> >().ToDictionary(i => i.GetType()); var metricByQueueLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointInputQueue> >().ToDictionary(i => i.GetType()); var metricByMessageTypeLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointMessageType> >().ToDictionary(i => i.GetType()); var instanceMetrics = new[] { CreateMetric <EndpointInstanceId, ProcessingTimeStore>("ProcessingTime", Aggregator.ToAverages), CreateMetric <EndpointInstanceId, CriticalTimeStore>("CriticalTime", Aggregator.ToAverages), CreateMetric <EndpointInstanceId, RetriesStore>("Retries", Aggregator.ToTotalMeasurementsPerSecond), CreateMetric <EndpointInstanceId, ProcessingTimeStore>("Throughput", Aggregator.ToTotalMeasurementsPerSecond) }; var queueMetrics = new[] { CreateMetric <EndpointInputQueue, QueueLengthStore>("QueueLength", Aggregator.ToRoundedSumOfBreakdownAverages) }; var messageTypeMetrics = new[] { CreateMetric <EndpointMessageType, ProcessingTimeStore>("ProcessingTime", Aggregator.ToAverages), CreateMetric <EndpointMessageType, CriticalTimeStore>("CriticalTime", Aggregator.ToAverages), CreateMetric <EndpointMessageType, RetriesStore>("Retries", Aggregator.ToTotalMeasurementsPerSecond), CreateMetric <EndpointMessageType, ProcessingTimeStore>("Throughput", Aggregator.ToTotalMeasurementsPerSecond) }; var detailedMetrics = new HashSet <string> { "Throughput", "QueueLength", "ProcessingTime", "CriticalTime", "Retries" }; Get["/monitored-endpoints"] = parameters => { var endpoints = GetMonitoredEndpoints(endpointRegistry, activityTracker); var period = ExtractHistoryPeriod(); foreach (var metric in instanceMetrics) { var store = metricByInstanceLookup[metric.StoreType]; var intervals = store.GetIntervals(period, DateTime.UtcNow).ToLookup(k => k.Id.EndpointName); foreach (var endpoint in endpoints) { var values = metric.Aggregate(intervals[endpoint.Name].ToList(), period); endpoint.Metrics.Add(metric.ReturnName, values); } } foreach (var metric in queueMetrics) { var store = metricByQueueLookup[metric.StoreType]; var intervals = store.GetIntervals(period, DateTime.UtcNow).ToLookup(k => k.Id.EndpointName); foreach (var endpoint in endpoints) { var values = metric.Aggregate(intervals[endpoint.Name].ToList(), period); endpoint.Metrics.Add(metric.ReturnName, values); } } return(Negotiate.WithModel(endpoints)); }; Get["/monitored-endpoints/{endpointName}"] = parameters => { var endpointName = (string)parameters.EndpointName; var period = ExtractHistoryPeriod(); var instances = GetMonitoredEndpointInstances(endpointRegistry, endpointName, activityTracker); var digest = new MonitoredEndpointDigest(); var metricDetails = new MonitoredEndpointMetricDetails(); foreach (var metric in instanceMetrics) { var store = metricByInstanceLookup[metric.StoreType]; var intervals = store.GetIntervals(period, DateTime.UtcNow); var intervalsByEndpoint = intervals.ToLookup(k => k.Id.EndpointName); var endpointValues = metric.Aggregate(intervalsByEndpoint[endpointName].ToList(), period); if (detailedMetrics.Contains(metric.ReturnName)) { var details = new MonitoredValuesWithTimings { Points = endpointValues.Points, Average = endpointValues.Average, TimeAxisValues = GetTimeAxisValues(intervalsByEndpoint[endpointName]) }; metricDetails.Metrics.Add(metric.ReturnName, details); } var metricDigest = new MonitoredEndpointMetricDigest { Latest = endpointValues.Points.LastOrDefault(), Average = endpointValues.Average }; digest.Metrics.Add(metric.ReturnName, metricDigest); var intervalsByInstanceId = intervals.ToLookup(k => k.Id); foreach (var instance in instances) { var instanceId = new EndpointInstanceId(endpointName, instance.Id, instance.Name); var instanceValues = metric.Aggregate(intervalsByInstanceId[instanceId].ToList(), period); instance.Metrics.Add(metric.ReturnName, instanceValues); } } foreach (var metric in queueMetrics) { var store = metricByQueueLookup[metric.StoreType]; var intervals = store.GetIntervals(period, DateTime.UtcNow); var intervalsByEndpoint = intervals.ToLookup(k => k.Id.EndpointName); var endpointValues = metric.Aggregate(intervalsByEndpoint[endpointName].ToList(), period); if (detailedMetrics.Contains(metric.ReturnName)) { var details = new MonitoredValuesWithTimings { Points = endpointValues.Points, Average = endpointValues.Average, TimeAxisValues = GetTimeAxisValues(intervalsByEndpoint[endpointName]) }; metricDetails.Metrics.Add(metric.ReturnName, details); } var metricDigest = new MonitoredEndpointMetricDigest { Latest = endpointValues.Points.LastOrDefault(), Average = endpointValues.Average }; digest.Metrics.Add(metric.ReturnName, metricDigest); } var messageTypes = GetMonitoredMessageTypes(messageTypeRegistry.GetForEndpointName(endpointName)); foreach (var metric in messageTypeMetrics) { var store = metricByMessageTypeLookup[metric.StoreType]; var intervals = store.GetIntervals(period, DateTime.UtcNow).ToLookup(k => k.Id); foreach (var messageType in messageTypes) { var values = metric.Aggregate(intervals[new EndpointMessageType(endpointName, messageType.Id)].ToList(), period); messageType.Metrics.Add(metric.ReturnName, values); } } var data = new MonitoredEndpointDetails { Digest = digest, Instances = instances, MessageTypes = messageTypes, MetricDetails = metricDetails }; return(Negotiate.WithModel(data)); }; }
public RosMessageSerializer(MessageTypeRegistry messageTypeRegistry) { MessageTypeRegistry = messageTypeRegistry ?? throw new ArgumentNullException(nameof(messageTypeRegistry)); }
public DiagramApiController(IProvideBreakdown[] breakdownProviders, EndpointRegistry endpointRegistry, EndpointInstanceActivityTracker activityTracker, MessageTypeRegistry messageTypeRegistry) { this.breakdownProviders = breakdownProviders; this.endpointRegistry = endpointRegistry; this.activityTracker = activityTracker; this.messageTypeRegistry = messageTypeRegistry; }
public void GetType_ShouldFailPreconditionsIfPassedNullUri() { var sut = new MessageTypeRegistry(); Uri uri = null; Assert.Throws<ArgumentException>(() => sut.GetType(uri)); }
public void GetUri_ShouldThrowWhenNoRegistryAdded() { var sut = new MessageTypeRegistry(); Assert.Throws<SkuttException>(() => sut.GetUri<TestMessage>()); }