示例#1
0
        public async Task GrpcInputTests_StopsAndRestarts()
        {
            // ARRANGE
            int         instancesReceived = 0;
            InstanceMsg receivedInstance  = null;

            int port  = Common.GetPort();
            var input = new GrpcInput("localhost", port, instance =>
            {
                instancesReceived++;
                receivedInstance = instance;
            });

            input.Start();

            Assert.IsTrue(SpinWait.SpinUntil(() => input.IsRunning, GrpcInputTests.DefaultTimeout));

            var grpcWriter = new GrpcWriter(port);

            var request = new HandleTraceSpanRequest();

            request.Instances.Add(new InstanceMsg()
            {
                SourceName = "SourceName1"
            });

            await grpcWriter.Write(request).ConfigureAwait(false);

            Common.AssertIsTrueEventually(
                () => input.GetStats().InstancesReceived == 1 && instancesReceived == 1 &&
                receivedInstance.SourceName == "SourceName1", GrpcInputTests.DefaultTimeout);

            // ACT
            input.Stop();

            Common.AssertIsTrueEventually(
                () => !input.IsRunning && input.GetStats().InstancesReceived == 1 && instancesReceived == 1 &&
                receivedInstance.SourceName == "SourceName1", GrpcInputTests.DefaultTimeout);

            input.Start();

            Assert.IsTrue(SpinWait.SpinUntil(() => input.IsRunning, GrpcInputTests.DefaultTimeout));

            grpcWriter = new GrpcWriter(port);
            request.Instances.Single().SourceName = "SourceName2";
            await grpcWriter.Write(request).ConfigureAwait(false);

            // ASSERT
            Common.AssertIsTrueEventually(
                () => input.IsRunning && input.GetStats().InstancesReceived == 1 && instancesReceived == 2 &&
                receivedInstance.SourceName == "SourceName2", GrpcInputTests.DefaultTimeout);
        }
示例#2
0
        public void GrpcInputTests_ReceivesDataFromMultipleClients()
        {
            // ARRANGE
            int         instancesReceived = 0;
            InstanceMsg receivedInstance  = null;

            int port  = Common.GetPort();
            var input = new GrpcInput("localhost", port, instance =>
            {
                Interlocked.Increment(ref instancesReceived);
                receivedInstance = instance;
            });

            input.Start();
            Assert.IsTrue(SpinWait.SpinUntil(() => input.IsRunning, GrpcInputTests.DefaultTimeout));

            // ACT
            var request = new HandleTraceSpanRequest();

            request.Instances.Add(new InstanceMsg()
            {
                SourceName = "SourceName1"
            });

            Parallel.For(0, 1000, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 1000
            }, async i =>
            {
                var grpcWriter = new GrpcWriter(port);

                await grpcWriter.Write(request).ConfigureAwait(false);
            });

            // ASSERT
            Common.AssertIsTrueEventually(
                () => input.GetStats().InstancesReceived == 1000 && instancesReceived == 1000, GrpcInputTests.DefaultTimeout);

            input.Stop();
            Assert.IsTrue(SpinWait.SpinUntil(() => !input.IsRunning, GrpcInputTests.DefaultTimeout));
        }