public C_DiscoverEndpointsTestTheory(IIoTMultipleNodesTestContext context, ITestOutputHelper output) { _output = output ?? throw new ArgumentNullException(nameof(output)); _context = context ?? throw new ArgumentNullException(nameof(context)); _context.OutputHelper = _output; _cancellationTokenSource = new CancellationTokenSource(TestConstants.MaxTestTimeoutMilliseconds); _restClient = new RestClient(_context.IIoTPlatformConfigHubConfig.BaseUrl) { Timeout = TestConstants.DefaultTimeoutInMilliseconds }; // Switch to Orchestrated mode TestHelper.SwitchToOrchestratedModeAsync(_context).GetAwaiter().GetResult(); // Get OAuth token var token = TestHelper.GetTokenAsync(_context, _cancellationTokenSource.Token).GetAwaiter().GetResult(); Assert.NotEmpty(token); // Get info about servers var simulatedOpcServers = TestHelper.GetSimulatedPublishedNodesConfigurationAsync(_context, _cancellationTokenSource.Token).GetAwaiter().GetResult(); var urls = simulatedOpcServers.Values.ToList().Select(s => s.EndpointUrl).ToList(); AddTestOpcServers(urls); dynamic result = TestHelper.WaitForDiscoveryToBeCompletedAsync(_context, _cancellationTokenSource.Token, requestedEndpointUrls: urls).GetAwaiter().GetResult(); _servers = result.items; // Remove servers var applicationIds = _servers.Select(s => s.applicationId?.ToString()); RemoveAllApplications(applicationIds.OfType <string>().ToList()); }
/// <summary> /// Create a multiple nodes model with opcplc nodes /// </summary> /// <param name="IIoTMultipleNodesTestContext">context</param> /// <param name="CancellationTokenSource">cancellation token</param> public static async Task <PublishedNodesEntryModel> CreateMultipleNodesModelAsync( IIoTMultipleNodesTestContext context, CancellationToken ct, int endpointIndex = 2, int numberOfNodes = 250) { await context.LoadSimulatedPublishedNodes(ct); PublishedNodesEntryModel nodesToPublish; if (context.SimulatedPublishedNodes.Count > 1) { var testPlc = context.SimulatedPublishedNodes.Skip(endpointIndex).First().Value; nodesToPublish = context.GetEntryModelWithoutNodes(testPlc); // We want to take several slow and fast nodes. // To make sure that we will not have missing values because of timing issues, // we will set publishing and sampling intervals to a lower value than the publishing // interval of the simulated OPC PLC. This will eliminate false-positives. nodesToPublish.OpcNodes = testPlc.OpcNodes .Where(node => !node.Id.Contains("bad", StringComparison.OrdinalIgnoreCase)) .Where(node => node.Id.Contains("slow", StringComparison.OrdinalIgnoreCase) || node.Id.Contains("fast", StringComparison.OrdinalIgnoreCase)) .Take(numberOfNodes) .Select(opcNode => { var opcPlcPublishingInterval = opcNode.OpcPublishingInterval; opcNode.OpcPublishingInterval = opcPlcPublishingInterval / 2; opcNode.OpcSamplingInterval = opcPlcPublishingInterval / 4; opcNode.QueueSize = 4; return(opcNode); }) .ToArray(); context.ConsumedOpcUaNodes.AddOrUpdate(testPlc.EndpointUrl, nodesToPublish); } else { var opcPlcIp = context.OpcPlcConfig.Urls.Split(TestConstants.SimulationUrlsSeparator)[endpointIndex]; nodesToPublish = new PublishedNodesEntryModel { EndpointUrl = $"opc.tcp://{opcPlcIp}:50000", UseSecurity = false }; var nodes = new List <OpcUaNodesModel>(); for (int i = 0; i < numberOfNodes; i++) { nodes.Add(new OpcUaNodesModel { Id = $"ns=2;s=SlowUInt{i + 1}", OpcPublishingInterval = 10000 / 2, OpcSamplingInterval = 10000 / 4, QueueSize = 4, }); } nodesToPublish.OpcNodes = nodes.ToArray(); context.ConsumedOpcUaNodes.Add(opcPlcIp, nodesToPublish); } return(nodesToPublish); }
public A_PublishSingleNodeStandaloneTestTheory( ITestOutputHelper output, IIoTMultipleNodesTestContext context ) { _output = output ?? throw new ArgumentNullException(nameof(output)); _context = context ?? throw new ArgumentNullException(nameof(context)); _context.OutputHelper = _output; }
public B_PublishMultipleNodesStandaloneDirectMethodTestTheory( ITestOutputHelper output, IIoTMultipleNodesTestContext context ) : base(output, context) { _cts = new CancellationTokenSource(TestConstants.MaxTestTimeoutMilliseconds); TestHelper.StopMonitoringIncomingMessagesAsync(_context, _cts.Token).Wait(); // Clean publishednodes.json. TestHelper.CleanPublishedNodesJsonFilesAsync(_context).Wait(); }
/// <summary> /// Constructor. /// </summary> public DirectMethodTestBase( ITestOutputHelper output, IIoTMultipleNodesTestContext context ) { _output = output ?? throw new ArgumentNullException(nameof(output)); _context = context ?? throw new ArgumentNullException(nameof(context)); _context.OutputHelper = _output; _iotHubPublisherDeviceName = _context.DeviceConfig.DeviceId; _serializer = new NewtonSoftJsonSerializer(); // Initialize DeviceServiceClient from IoT Hub connection string. _iotHubClient = TestHelper.DeviceServiceClient( _context.IoTHubConfig.IoTHubConnectionString, TransportType.Amqp_WebSocket_Only ); }
public A_PublishSingleNodeStandaloneDirectMethodTestTheory( ITestOutputHelper output, IIoTMultipleNodesTestContext context ) : base(output, context) { }
public B_PublishMultipleNodesOrchestratedTestTheory(IIoTMultipleNodesTestContext context, ITestOutputHelper output) { _output = output ?? throw new ArgumentNullException(nameof(output)); _context = context ?? throw new ArgumentNullException(nameof(context)); _context.OutputHelper = _output; }
/// <summary> /// Create a single node model with opcplc node /// </summary> /// <param name="IIoTMultipleNodesTestContext">context</param> /// <param name="CancellationTokenSource">cancellation token</param> public static async Task <PublishedNodesEntryModel> CreateSingleNodeModelAsync(IIoTMultipleNodesTestContext context, CancellationToken ct) { IDictionary <string, PublishedNodesEntryModel> simulatedPublishedNodesConfiguration = new Dictionary <string, PublishedNodesEntryModel>(0); // With the nested edge test servers don't have public IP addresses and cannot be accessed in this way if (context.IoTEdgeConfig.NestedEdgeFlag != "Enable") { simulatedPublishedNodesConfiguration = await GetSimulatedPublishedNodesConfigurationAsync(context, ct); } PublishedNodesEntryModel model; if (simulatedPublishedNodesConfiguration.Count > 0) { model = simulatedPublishedNodesConfiguration[simulatedPublishedNodesConfiguration.Keys.First()]; } else { var opcPlcIp = context.OpcPlcConfig.Urls.Split(TestConstants.SimulationUrlsSeparator)[0]; model = new PublishedNodesEntryModel { EndpointUrl = $"opc.tcp://{opcPlcIp}:50000", UseSecurity = false, OpcNodes = new OpcUaNodesModel[] { new OpcUaNodesModel { Id = "ns=2;s=SlowUInt1", OpcPublishingInterval = 10000, } } }; } // We want to take one of the slow nodes that updates each 10 seconds. // To make sure that we will not have missing values because of timing issues, // we will set publishing and sampling intervals to a lower value than the publishing // interval of the simulated OPC PLC. This will eliminate false-positives. model.OpcNodes = model.OpcNodes .Where(node => !node.Id.Contains("bad", StringComparison.OrdinalIgnoreCase)) .Where(opcNode => opcNode.Id.Contains("SlowUInt")) .Take(1).Select(opcNode => { var opcPlcPublishingInterval = opcNode.OpcPublishingInterval; opcNode.OpcPublishingInterval = opcPlcPublishingInterval / 2; opcNode.OpcSamplingInterval = opcPlcPublishingInterval / 4; opcNode.QueueSize = 4; return(opcNode); }) .ToArray(); return(model); }