示例#1
0
 /// <summary>
 /// Creates the output gateway.
 /// </summary>
 /// <param name="uri">The URI.</param>
 /// <param name="transportType">The supported transports.</param>
 /// <param name="dataContractSerializer">The data contract serializer.</param>
 /// <returns></returns>
 public static RouterOutputGateway CreateOutputGateway(Uri uri, TransportType transportType, IDataContractSerializer dataContractSerializer)
 {
     return(new RouterOutputGateway(EndPointFactory.CreateSenderEndPoint(uri, transportType), dataContractSerializer)
     {
         Logger = LoggerManager.Instance
     });
 }
 /// <summary>
 /// Creates the input gateway.
 /// </summary>
 /// <typeparam name="TMessage">The type of the message.</typeparam>
 /// <param name="uri">The URI.</param>
 /// <param name="transportType">The supported transports.</param>
 /// <param name="numberOfParallelTasks">The number of parallel tasks.</param>
 /// <param name="maxReijections">The max reijections.</param>
 /// <returns></returns>
 public static AgentInputGateway <TMessage> CreateInputGateway <TMessage>(Uri uri,
                                                                          TransportType transportType,
                                                                          int numberOfParallelTasks, int maxReijections)
     where TMessage : IMessage
 {
     return(CreateInputGateway <TMessage>(EndPointFactory.CreateReceiverEndPoint(uri, transportType, numberOfParallelTasks), maxReijections));
 }
 public HighPerformanceServerStrategy(int localPort) : base(localPort)
 {
     Role            = TcpRole.Client;
     MultipleClients = true;
     endPointFactory = new EndPointFactory(localPort);
     communicants.Add(ComputerInfo.Current.PerformanceIndex, endPointFactory.Create(IPAddress.Loopback));
 }
示例#4
0
 /// <summary>
 /// Creates the output gateway.
 /// </summary>
 /// <param name="uri">The URI.</param>
 /// <param name="transportType">The supported transports.</param>
 /// <returns></returns>
 public static RouterOutputGateway CreateOutputGateway(Uri uri, TransportType transportType)
 {
     return(new RouterOutputGateway(EndPointFactory.CreateSenderEndPoint(uri, transportType))
     {
         Logger = LoggerManager.Instance
     });
 }
示例#5
0
 /// <summary>
 /// Creates the input gateway.
 /// </summary>
 /// <param name="uri">The URI.</param>
 /// <param name="transportType">The supported transports.</param>
 /// <param name="numberOfParallelTasks">The number of parallel tasks.</param>
 /// <param name="maxReijections">The max reijections.</param>
 /// <returns></returns>
 public static RouterInputGateway CreateInputGateway(Uri uri, TransportType transportType, int numberOfParallelTasks, int maxReijections)
 {
     return(new RouterInputGateway(EndPointFactory.CreateReceiverEndPoint(uri, transportType, numberOfParallelTasks), maxReijections)
     {
         Logger = LoggerManager.Instance
     });
 }
 /// <summary>
 /// Creates the output gateway.
 /// </summary>
 /// <param name="identification">The identification.</param>
 /// <param name="uri">The URI.</param>
 /// <param name="transportType">The supported transports.</param>
 /// <returns></returns>
 public static AgentOutputGateway CreateOutputGateway(Identification identification, Uri uri, TransportType transportType)
 {
     return(new AgentOutputGateway(identification, EndPointFactory.CreateSenderEndPoint(uri, transportType))
     {
         Logger = LoggerManager.Instance
     });
 }
示例#7
0
        public void CreateSenderEndPointFromUriAndTransportTypeMsmq()
        {
            var ep = EndPointFactory.CreateSenderEndPoint(_uri, _transportType);

            Assert.IsInstanceOf(typeof(ISenderEndPoint), ep);
            Assert.AreEqual(ep.Uri, _uri);
            Assert.AreEqual(ep.Transport, _transportType);
        }
        private static IEndPointSource ResolveEndPointSource(IServiceProvider provider)
        {
            var config = provider.GetRequiredService <StatsDConfiguration>();

            return(EndPointFactory.MakeEndPointSource(
                       config.Host,
                       config.Port,
                       config.DnsLookupInterval));
        }
示例#9
0
 /// <summary>
 /// Creates the input gateway.
 /// </summary>
 /// <param name="uri">The URI.</param>
 /// <param name="transportType">The supported transports.</param>
 /// <param name="dataContractSerializer">The data contract serializer.</param>
 /// <param name="numberOfParallelTasks">The number of parallel tasks.</param>
 /// <param name="maxReijections">The max reijections.</param>
 /// <returns></returns>
 public static RouterInputGateway CreateInputGateway(Uri uri,
                                                     TransportType transportType,
                                                     IDataContractSerializer dataContractSerializer,
                                                     int numberOfParallelTasks, int maxReijections)
 {
     return(CreateInputGateway(EndPointFactory.CreateReceiverEndPoint(uri, transportType, numberOfParallelTasks),
                               dataContractSerializer,
                               maxReijections));
 }
示例#10
0
        public async Task PutFieldReturnsBadRequestAndCorrectContentType()
        {
            // Given
            UpdateFieldViewModel model = ViewModelFactory.CreateInvalidUpdateModel();

            // When
            HttpResponseMessage response = await Client.PutAsJsonAsync(EndPointFactory.UpdateEndpoint(), model);

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            response.Content.Headers.ContentType.ToString().Should().Be("application/problem+json; charset=utf-8");
        }
示例#11
0
        public async Task DeleteFieldReturnsNoContentAndCorrectContentType()
        {
            // Given
            A.CallTo(() => _fakeCommand.Delete(A <Guid> .Ignored)).Returns(Task.CompletedTask);

            // When
            HttpResponseMessage response = await Client.DeleteAsync(EndPointFactory.DeleteEndpoint());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.NoContent);
            A.CallTo(() => _fakeCommand.Delete(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
        }
        public void AMetricCanBeSentWithoutAnExceptionBeingThrown()
        {
            // Arrange
            var endPointSource = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            using var target = new SocketTransport(endPointSource, SocketProtocol.Udp);

            // Act and Assert
            target.Send("mycustommetric");
        }
示例#13
0
        public async Task PostNewSpeciesReturnsConflictIfResourceStateExceptionOccured()
        {
            // Given
            A.CallTo(() => _fakeCommand.Create(A <CreateSpeciesModel> .Ignored)).Throws(A.Fake <ResourceStateException>());

            // When
            HttpResponseMessage response = await Client.PostAsJsonAsync(EndPointFactory.CreateEndpoint(), ViewModelFactory.CreateValidCreationModel());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.Conflict);
            response.Content.Headers.ContentType.ToString().Should().Be("application/json; charset=utf-8");
            A.CallTo(() => _fakeCommand.Create(A <CreateSpeciesModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
 public ClientRequestor(ParallelNetworkStream parent)
 {
     this.parent     = parent;
     broadcastedType = new WatchedVariable <short>(parent.watcher)
     {
         Value = EMPTY_BROADCASTED_TYPE
     };
     broadcastEverything = new WatchedVariable <bool>(parent.watcher)
     {
         Value = false
     };
     remoteEndPointFactory = parent.udpEndPointFactory;
 }
示例#15
0
        public async Task GetFieldReturnsFieldAndCorrectContentType()
        {
            // Given
            A.CallTo(() => _fakeQuery.Get(A <Guid> .Ignored)).Returns(A.Fake <Field>());

            // When
            HttpResponseMessage response = await Client.GetAsync(EndPointFactory.DetailsEndpoint());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Headers.ContentType.ToString().Should().Be("application/json; charset=utf-8");
            A.CallTo(() => _fakeQuery.Get(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
        }
示例#16
0
        public async Task PostNewFieldReturnsCreatedAndCorrectContentType()
        {
            // Given
            A.CallTo(() => _fakeCommand.Create(A <CreateFieldModel> .Ignored)).Returns(Guid.NewGuid());

            // When
            HttpResponseMessage response = await Client.PostAsJsonAsync(EndPointFactory.CreateEndpoint(), ViewModelFactory.CreateValidCreationModel());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.Created);
            response.Headers.Location.Should().NotBeNull();
            A.CallTo(() => _fakeCommand.Create(A <CreateFieldModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
示例#17
0
        public async Task PutFieldReturnsFieldAndCorrectContentType()
        {
            // Given
            A.CallTo(() => _fakeCommand.Update(A <UpdateFieldModel> .Ignored)).Returns(A.Fake <Field>());

            // When
            HttpResponseMessage response = await Client.PutAsJsonAsync(EndPointFactory.UpdateEndpoint(), ViewModelFactory.CreateValidUpdateModel());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Headers.ContentType.ToString().Should().Be("application/json; charset=utf-8");
            A.CallTo(() => _fakeCommand.Update(A <UpdateFieldModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
示例#18
0
        public async Task GetPlantEventReturnsNotFoundAndCorrectContentTypeIfPlantEventDoesNotExist()
        {
            // Given
            A.CallTo(() => _fakeQuery.Get(A <Guid> .Ignored, A <Guid> .Ignored)).Returns(Task.FromResult <Event>(null));

            // When
            HttpResponseMessage response = await Client.GetAsync(EndPointFactory.DetailsEndpoint());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
            response.Content.Headers.ContentType.ToString().Should().Be("application/problem+json; charset=utf-8");
            A.CallTo(() => _fakeQuery.Get(A <Guid> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
        }
示例#19
0
        public async Task PutPlantEventReturnsNotFoundAndCorrectContentType()
        {
            // Given
            A.CallTo(() => _fakeCommand.Update(A <Guid> .Ignored, A <UpdatePlantEventModel> .Ignored)).Returns(Task.FromResult <Event>(null));

            // When
            HttpResponseMessage response = await Client.PutAsJsonAsync(EndPointFactory.UpdateEndpoint(), ViewModelFactory.CreateValidUpdateModel());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
            response.Content.Headers.ContentType.ToString().Should().Be("application/problem+json; charset=utf-8");
            A.CallTo(() => _fakeCommand.Update(A <Guid> .Ignored, A <UpdatePlantEventModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
示例#20
0
        public async Task GetListReturnsPlantNutrientsAndCorrectContentType()
        {
            // Given
            A.CallTo(() => _fakeQuery.GetByPlant(A <Guid> .Ignored)).Returns(A.Fake <IEnumerable <AdministeredNutrient> >());

            // When
            HttpResponseMessage response = await Client.GetAsync(EndPointFactory.ListEndpoint());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Headers.ContentType.ToString().Should().Be("application/json; charset=utf-8");
            A.CallTo(() => _fakeQuery.GetByPlant(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
        }
示例#21
0
        public async Task PutPlantEventReturnsNotFoundIfResourceNotFoundExceptionOccured()
        {
            // Given
            A.CallTo(() => _fakeCommand.Update(A <Guid> .Ignored, A <UpdatePlantEventModel> .Ignored))
            .Throws(A.Fake <ResourceNotFoundException>());

            // When
            HttpResponseMessage response = await Client.PutAsJsonAsync(EndPointFactory.UpdateEndpoint(), ViewModelFactory.CreateValidUpdateModel());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
            response.Content.Headers.ContentType.ToString().Should().Be("application/json; charset=utf-8");
            A.CallTo(() => _fakeCommand.Update(A <Guid> .Ignored, A <UpdatePlantEventModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
        public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownParallel()
        {
            // Arrange
            var endPointSource = EndPointFactory.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");
            });
        }
示例#23
0
        public async Task GetSummaryOfPlantEventReturnsNotFoundAndCorrectContentTypeIfResourceNotFoundExceptionOccured()
        {
            // Given
            A.CallTo(() => _fakeQuery.Summary(A <Guid> .Ignored, A <DateTime?> .Ignored, A <DateTime?> .Ignored))
            .Returns(Task.FromResult <IEnumerable <PlantEventOccurenceSummaryModel> >(null));

            // When
            HttpResponseMessage response = await Client.GetAsync(EndPointFactory.EventsSummaryEndpoint());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
            response.Content.Headers.ContentType.ToString().Should().Be("application/problem+json; charset=utf-8");
            A.CallTo(() => _fakeQuery.Summary(A <Guid> .Ignored, A <DateTime?> .Ignored, A <DateTime?> .Ignored))
            .MustHaveHappenedOnceExactly();
        }
        public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownSerial()
        {
            // Arrange
            var endPointSource = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp))
            {
                for (int i = 0; i < 10_000; i++)
                {
                    // Act and Assert
                    target.Send("mycustommetric:1|c");
                }
            }
        }
示例#25
0
        public async Task GetSummaryOfPlantEventReturnsSummaryAndCorrectContentType()
        {
            // Given
            DateTime fromDate = new DateTime(2018, 12, 01, 00, 00, 00);
            DateTime toDate   = new DateTime(2018, 12, 31, 23, 59, 59);

            A.CallTo(() => _fakeQuery.Summary(A <Guid> .Ignored, fromDate, toDate))
            .Returns(A.Fake <IEnumerable <PlantEventOccurenceSummaryModel> >());

            // When
            HttpResponseMessage response = await Client.GetAsync(EndPointFactory.EventsSummaryWithinDateRangeEndpoint());

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Headers.ContentType.ToString().Should().Be("application/json; charset=utf-8");
            A.CallTo(() => _fakeQuery.Summary(A <Guid> .Ignored, fromDate, toDate))
            .MustHaveHappenedOnceExactly();
        }
        public static void EndpointSwitchShouldNotCauseExceptionsSequential()
        {
            // Arrange
            var endPointSource1 = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            var endPointSource2 = EndPointFactory.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 = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            var endPointSource2 = EndPointFactory.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");
            });
        }
示例#28
0
        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 = EndPointFactory.MakeEndPointSource(
                config.Host, config.Port, config.DnsLookupInterval);

            _ipTransport = new SocketTransport(endpointSource, SocketProtocol.IP);
            _ipSender    = new BufferBasedStatsDPublisher(config, _ipTransport);
            _ipSender.Increment("startup.i");

            _udpTransport = new SocketTransport(endpointSource, SocketProtocol.Udp);
            _udpSender    = new BufferBasedStatsDPublisher(config, _udpTransport);
            _udpSender.Increment("startup.u");
        }
        public void Setup()
        {
            var config = new StatsDConfiguration
            {
                Host = "127.0.0.1",
            };

            var endpointSource1 = EndPointFactory.MakeEndPointSource(
                config.Host,
                config.Port,
                config.DnsLookupInterval);

            var endpointSource2 = EndPointFactory.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);
        }
示例#30
0
        /// <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 = EndPointFactory.MakeEndPointSource(
                configuration.Host, configuration.Port, configuration.DnsLookupInterval);

            var transport = new SocketTransport(endpointSource, configuration.SocketProtocol);

            _transport        = transport;
            _disposeTransport = true;

            _inner = new BufferBasedStatsDPublisher(configuration, transport);
        }