コード例 #1
0
        public void SetDefaultValueWhenReceivedInvalidTwin()
        {
            var diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Server);

            var twin = new Twin();

            twin.Properties.Desired["diag_enableInvalid"] = false;
            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagSamplingRateKey] = 10;

            diagnosticProvider.SetSamplingConfigFromTwin(twin.Properties.Desired);
            Assert.AreEqual(diagnosticProvider.SamplingOn, true);
            Assert.AreEqual(diagnosticProvider.SamplingRatePercentage, 10);

            twin = new Twin();
            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagEnableKey]       = "dddd";
            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagSamplingRateKey] = 10;

            diagnosticProvider.SetSamplingConfigFromTwin(twin.Properties.Desired);
            Assert.AreEqual(diagnosticProvider.SamplingOn, false);

            twin = new Twin();
            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagEnableKey]       = true;
            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagSamplingRateKey] = "xxx";

            diagnosticProvider.SetSamplingConfigFromTwin(twin.Properties.Desired);
            Assert.AreEqual(diagnosticProvider.SamplingRatePercentage, 0);

            twin = new Twin();
            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagEnableKey]       = true;
            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagSamplingRateKey] = 10;
            diagnosticProvider.SetSamplingConfigFromTwin(twin.Properties.Desired);
        }
コード例 #2
0
        public static DeviceClientWrapper CreateFromConnectionString(string connectionString, string deviceId, IDiagnosticProvider diagnosticProvider = null)
        {
            if (diagnosticProvider == null)
            {
                diagnosticProvider = new ContinuousDiagnosticProvider();
            }
            var deviceClient = DeviceClient.CreateFromConnectionString(connectionString, deviceId, TransportType.Mqtt);

            return(new DeviceClientWrapper(deviceClient, diagnosticProvider));
        }
コード例 #3
0
        public static DeviceClientWrapper Create(string hostname, IAuthenticationMethod authenticationMethod, [ReadOnlyArray] ITransportSettings[] transportSettings, IDiagnosticProvider diagnosticProvider = null)
        {
            if (diagnosticProvider == null)
            {
                diagnosticProvider = new ContinuousDiagnosticProvider();
            }
            var deviceClient = DeviceClient.Create(hostname, authenticationMethod, transportSettings);

            return(new DeviceClientWrapper(deviceClient, diagnosticProvider));
        }
コード例 #4
0
        public static DeviceClientWrapper Create(string hostname, IAuthenticationMethod authenticationMethod, IDiagnosticProvider diagnosticProvider = null)
        {
            if (diagnosticProvider == null)
            {
                diagnosticProvider = new ContinuousDiagnosticProvider();
            }
            var deviceClient = DeviceClient.Create(hostname, authenticationMethod);

            return(new DeviceClientWrapper(deviceClient, diagnosticProvider));
        }
コード例 #5
0
        public void DoNotSamplingWhenNeedSamplingIsFalse()
        {
            var diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.None);

            Assert.AreEqual(diagnosticProvider.SamplingOn, false);
            for (var i = 0; i < 100; i++)
            {
                diagnosticProvider.Process(new Message());
            }
            Assert.AreEqual(diagnosticProvider.GetSampledCount(), 0);
        }
コード例 #6
0
        public static DeviceClientWrapper CreateFromConnectionString(string connectionString, [ReadOnlyArray] ITransportSettings[] transportSettings, IDiagnosticProvider diagnosticProvider = null)
        {
            if (diagnosticProvider == null)
            {
                diagnosticProvider = new ContinuousDiagnosticProvider();
            }
            var mqttTransportSettings = GetMqttTransportSettings(transportSettings);

            var deviceClient = DeviceClient.CreateFromConnectionString(connectionString, mqttTransportSettings);

            return(new DeviceClientWrapper(deviceClient, diagnosticProvider));
        }
コード例 #7
0
        public void UpdateDiagnosticSettingsFromServer()
        {
            var diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Server);

            var twin = new Twin();

            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagEnableKey]       = true;
            twin.Properties.Desired[BaseDiagnosticProvider.TwinDiagSamplingRateKey] = 10;

            diagnosticProvider.SetSamplingConfigFromTwin(twin.Properties.Desired);
            Assert.AreEqual(diagnosticProvider.SamplingOn, true);
            Assert.AreEqual(diagnosticProvider.SamplingRatePercentage, 10);
        }
コード例 #8
0
        public void ThrowExceptionWhenSamplingRatePercentageOutOfRange()
        {
            var diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Client, 50);

            Assert.ThrowsException <SamplingPercentageOutOfRangeException>(() =>
            {
                diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Client, -1);
            });

            Assert.ThrowsException <SamplingPercentageOutOfRangeException>(() =>
            {
                diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Client, 101);
            });
        }
コード例 #9
0
        public void ContinuousDiagnosticProviderTest()
        {
            var diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Client, 100);

            for (var i = 1; i <= 100; i++)
            {
                diagnosticProvider.MessageNumber = i;
                Assert.AreEqual(diagnosticProvider.ShouldAddDiagnosticProperties(), true);
            }

            diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Client, 0);

            for (var i = 1; i <= 100; i++)
            {
                diagnosticProvider.MessageNumber = i;
                Assert.AreEqual(diagnosticProvider.ShouldAddDiagnosticProperties(), false);
            }

            diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Client, 50);
            for (var i = 1; i <= 100; i++)
            {
                diagnosticProvider.MessageNumber = i;
                Assert.AreEqual(diagnosticProvider.ShouldAddDiagnosticProperties(), i % 2 != 0);
            }

            diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Client, 25);

            for (var i = 1; i <= 100; i++)
            {
                diagnosticProvider.MessageNumber = i;
                Assert.AreEqual(diagnosticProvider.ShouldAddDiagnosticProperties(), (i - 1) % 4 == 0);
            }

            diagnosticProvider = new ContinuousDiagnosticProvider(SamplingRateSource.Client, 20);

            for (var i = 1; i <= 100; i++)
            {
                diagnosticProvider.MessageNumber = i;
                Assert.AreEqual(diagnosticProvider.ShouldAddDiagnosticProperties(), (i - 1) % 5 == 0);
            }
        }