static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Bad arguments provided."); PrintHelp(); return(1); } string openApiDocFilePath = args[0]; string outputEndpointsFilePath = args[1]; if (!ValidateArguments(openApiDocFilePath, outputEndpointsFilePath)) { PrintHelp(); return(1); } OpenApiDocument openApiDocument = OpenApiDocumentParser.ParseOpenApiDocument(openApiDocFilePath); List <Endpoint> endpoints = EndpointParser.ParseAllEndpoints(openApiDocument); string json = JsonConvert.SerializeObject(endpoints, Formatting.Indented); File.WriteAllText(outputEndpointsFilePath, json); return(0); }
public void CanUseDefaultPort() { var success = EndpointParser.TryParse("127.0.0.1", 7051, out var hostPort); Assert.True(success); Assert.Equal("127.0.0.1", hostPort.Host); Assert.Equal(7051, hostPort.Port); }
public void CanParseEndpoint(string endpoint, string expectedHost, int expectedPort) { var success = EndpointParser.TryParse(endpoint, 0, out var hostPort); Assert.True(success); Assert.Equal(expectedHost, hostPort.Host); Assert.Equal(expectedPort, hostPort.Port); }
public void DocumentWithTwoPathsEachHavingSingleResponseShouldReturnTwoEndpoints() { AddTwoTestingPaths(); List <Endpoint> endpoints = EndpointParser.ParseAllEndpoints(_document); Assert.AreEqual(2, endpoints.Count); }
private static IEndPointSource ResolveEndPointSource(IServiceProvider provider) { var config = provider.GetRequiredService <StatsDConfiguration>(); return(EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval)); }
public void AMetricCanBeSentWithoutAnExceptionBeingThrown() { // Arrange var endPointSource = EndpointParser.MakeEndPointSource( UdpListeners.EndpointA, null); using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp)) { // Act and Assert target.Send("mycustommetric"); } }
public void Setup() { var config = new StatsDConfiguration { Host = "127.0.0.1", }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); _pooledTransport = new PooledUdpTransport(endpointSource); _unpooledTransport = new UdpTransport(endpointSource); }
/// <summary> /// Registers the TypedRest OpenAPI extension parser. /// </summary> /// <param name="settings">The settings to register the extension parser in.</param> /// <param name="endpointRegistry">A list of all known <see cref="IEndpoint"/> kinds; leave <c>null</c> for default.</param> /// <seealso cref="OpenApiDocumentExtensions.GetTypedRest"/> public static OpenApiReaderSettings AddTypedRest(this OpenApiReaderSettings settings, EndpointRegistry?endpointRegistry = null) { var parser = new EndpointParser(endpointRegistry ?? EndpointRegistry.Default); settings.ExtensionParsers.Add(OpenApiDocumentExtensions.TypedRestKey, (data, _) => { if (!(data is OpenApiObject objData)) { throw new FormatException($"{OpenApiDocumentExtensions.TypedRestKey} is not an object."); } var entryEndpoint = new EntryEndpoint(); entryEndpoint.Parse(objData, parser); return(entryEndpoint); });
public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownParallel() { // Arrange var endPointSource = EndpointParser.MakeEndPointSource( UdpListeners.EndpointA, null); using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp)) { Parallel.For(0, 10_000, _ => { // Act and Assert target.Send("mycustommetric:1|c"); }); } }
public StatsDPublisher(StatsDConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (string.IsNullOrWhiteSpace(configuration.Host)) { throw new ArgumentNullException(nameof(configuration.Host)); } _formatter = new StatsDMessageFormatter(configuration.Culture, configuration.Prefix); var endpointSource = EndpointParser.MakeEndPointSource( configuration.Host, configuration.Port, configuration.DnsLookupInterval); _transport = new UdpTransport(endpointSource); }
private static void Main(string[] args) { var iterations = Enumerable.Range(1, 500000); var endpoint = EndpointParser.MakeEndPointSource("localhost", 3128, null); var client = new UdpTransport(endpoint); var formatter = new StatsDMessageFormatter(CultureInfo.InvariantCulture); var watch = new Stopwatch(); Console.WriteLine("To start - hit ENTER."); Console.ReadLine(); Console.WriteLine("start"); watch.Start(); Parallel.ForEach(iterations, x => client.Send(formatter.Gauge(x, "bucket_sample" + "number-of-messages-to-be-sent"))); watch.Stop(); Console.WriteLine("end - " + watch.ElapsedMilliseconds); Console.ReadLine(); }
public static void EndpointSwitchShouldNotCauseExceptionsSequential() { // Arrange var endPointSource1 = EndpointParser.MakeEndPointSource( UdpListeners.EndpointA, null); var endPointSource2 = EndpointParser.MakeEndPointSource( UdpListeners.EndpointB, null); using (var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp)) { for (int i = 0; i < 10_000; i++) { // Act and Assert target.Send("mycustommetric:1|c"); } } }
public static void EndpointSwitchShouldNotCauseExceptionsParallel() { // Arrange var endPointSource1 = EndpointParser.MakeEndPointSource( UdpListeners.EndpointA, null); var endPointSource2 = EndpointParser.MakeEndPointSource( UdpListeners.EndpointB, null); using (var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp)) { Parallel.For(0, 10_000, _ => { // Act and Assert target.Send("mycustommetric"); }); } }
public void Setup() { var config = new StatsDConfiguration { Host = "127.0.0.1", }; var endpointSource1 = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); var endpointSource2 = EndpointParser.MakeEndPointSource( config.Host, config.Port + 1, config.DnsLookupInterval); var switcher = new MillisecondSwitcher(endpointSource1, endpointSource2); _transport = new SocketTransport(endpointSource1, SocketProtocol.Udp); _transportSwitched = new SocketTransport(switcher, SocketProtocol.Udp); }
public void Setup() { var config = new StatsDConfiguration { // if you want verify that stats are recevied, // you will need the IP of suitable local test stats server Host = "127.0.0.1", Prefix = "testmetric" }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); var udpTransport = new UdpTransport(endpointSource); var ipTransport = new IpTransport(endpointSource); _udpSender = new StatsDPublisher(config, udpTransport); _udpSender.Increment("startup.ud"); _ipSender = new StatsDPublisher(config, ipTransport); _udpSender.Increment("startup.ip"); }
/// <summary> /// Initializes a new instance of the <see cref="StatsDPublisher"/> class using the default transport. /// </summary> /// <param name="configuration">The StatsD configuration to use.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="configuration"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="configuration"/> is invalid, such as an invalid hostname or IP address. /// </exception> public StatsDPublisher(StatsDConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (string.IsNullOrWhiteSpace(configuration.Host)) { throw new ArgumentException("No hostname or IP address is set.", nameof(configuration)); } var endpointSource = EndpointParser.MakeEndPointSource( configuration.Host, configuration.Port, configuration.DnsLookupInterval); var transport = new SocketTransport(endpointSource, configuration.SocketProtocol); _transport = transport; _disposeTransport = true; _inner = new BufferBasedStatsDPublisher(configuration, transport); }
public void Setup() { var config = new StatsDConfiguration { // if you want to verify that stats are received, // you will need the IP of suitable local test stats server Host = "127.0.0.1", Prefix = "testmetric" }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); _transport = new SocketTransport(endpointSource, SocketProtocol.Udp); _adaptedStatsDPublisher = new StatsDPublisher(config); _adaptedStatsDPublisher.Increment("startup.ud"); _udpSender = new BufferBasedStatsDPublisher(config, _transport); _udpSender.Increment("startup.ud"); }
public void DocumentWithoutAnyPathsShouldReturnEmptyList() { List <Endpoint> endpoints = EndpointParser.ParseAllEndpoints(_document); Assert.IsEmpty(endpoints); }