/// <summary> /// Worker method to translate the browse path. /// </summary> public static BrowsePathResultCollection TranslateBrowsePathWorker( IServerTestServices services, ReferenceDescriptionCollection referenceDescriptions, RequestHeader requestHeader, OperationLimits operationLimits) { // Browse template var startingNode = Objects.RootFolder; requestHeader.Timestamp = DateTime.UtcNow; // TranslateBrowsePath bool verifyMaxNodesPerBrowse = operationLimits.MaxNodesPerTranslateBrowsePathsToNodeIds > 0; var browsePaths = new BrowsePathCollection( referenceDescriptions.Select(r => new BrowsePath() { RelativePath = new RelativePath(r.BrowseName), StartingNode = startingNode }) ); BrowsePathResultCollection allBrowsePaths = new BrowsePathResultCollection(); while (browsePaths.Any()) { if (verifyMaxNodesPerBrowse && browsePaths.Count > operationLimits.MaxNodesPerTranslateBrowsePathsToNodeIds) { verifyMaxNodesPerBrowse = false; // Test if server responds with BadTooManyOperations var sre = Assert.Throws <ServiceResultException>(() => _ = services.TranslateBrowsePathsToNodeIds(requestHeader, browsePaths, out var results, out var infos)); Assert.AreEqual(StatusCodes.BadTooManyOperations, sre.StatusCode); } var browsePathSnippet = (operationLimits.MaxNodesPerTranslateBrowsePathsToNodeIds > 0) ? browsePaths.Take((int)operationLimits.MaxNodesPerTranslateBrowsePathsToNodeIds).ToArray() : browsePaths; ResponseHeader response = services.TranslateBrowsePathsToNodeIds(requestHeader, browsePathSnippet, out var browsePathResults, out var diagnosticInfos); ServerFixtureUtils.ValidateResponse(response); ServerFixtureUtils.ValidateDiagnosticInfos(diagnosticInfos, browsePathSnippet); allBrowsePaths.AddRange(browsePathResults); foreach (var result in browsePathResults) { if (result.Targets?.Count > 0) { TestContext.Out.WriteLine("BrowsePath {0}", result.Targets[0].ToString()); } } if (operationLimits.MaxNodesPerTranslateBrowsePathsToNodeIds == 0) { browsePaths.Clear(); } else { browsePaths = browsePaths.Skip((int)operationLimits.MaxNodesPerTranslateBrowsePathsToNodeIds).ToArray(); } } return(allBrowsePaths); }
/// <summary> /// Reads an verifies all of the nodes. /// </summary> private bool DoMultiHopTest(int hops) { // follow tree from each starting node. bool success = true; Log("Starting TranslatePath with {2} hops for {0} Nodes ({1}% Coverage)", AvailableNodes.Values.Count, Configuration.Coverage, hops + 1); // collect the available paths. BrowsePathCollection availablePaths = new BrowsePathCollection(); int counter = 0; foreach (Node node in AvailableNodes.Values) { if (!CheckCoverage(ref counter)) { continue; } if (hops <= 0) { AddSingleHopPaths(node, availablePaths); } else { AddMultiHopPaths(node, node, null, availablePaths, hops); } } // process paths in blocks. int paths = 0; double increment = MaxProgress / availablePaths.Count; double position = 0; BrowsePathCollection pathsToTranslate = new BrowsePathCollection(); for (int ii = 0; ii < availablePaths.Count; ii++) { paths++; pathsToTranslate.Add(availablePaths[ii]); // process batch. if (pathsToTranslate.Count > 500) { if (!Translate(pathsToTranslate)) { success = false; break; } if (paths > availablePaths.Count / 5) { Log("Translated {0} browse paths.", paths); paths = 0; } pathsToTranslate.Clear(); } position += increment; ReportProgress(position); } // process final batch. if (success) { if (pathsToTranslate.Count > 0) { if (!Translate(pathsToTranslate)) { success = false; } else { Log("Translated {0} browse paths.", paths); } } } return(success); }
/// <summary> /// Reads an verifies all of the nodes. /// </summary> private bool DoMultiHopTest(int hops) { // follow tree from each starting node. bool success = true; Log("Starting TranslatePath with {2} hops for {0} Nodes ({1}% Coverage)", AvailableNodes.Values.Count, Configuration.Coverage, hops+1); // collect the available paths. BrowsePathCollection availablePaths = new BrowsePathCollection(); int counter = 0; foreach (Node node in AvailableNodes.Values) { if (!CheckCoverage(ref counter)) { continue; } if (hops <= 0) { AddSingleHopPaths(node, availablePaths); } else { AddMultiHopPaths(node, node, null, availablePaths, hops); } } // process paths in blocks. int paths = 0; double increment = MaxProgress/availablePaths.Count; double position = 0; BrowsePathCollection pathsToTranslate = new BrowsePathCollection(); for (int ii = 0; ii < availablePaths.Count; ii++) { paths++; pathsToTranslate.Add(availablePaths[ii]); // process batch. if (pathsToTranslate.Count > 500) { if (!Translate(pathsToTranslate)) { success = false; break; } if (paths > availablePaths.Count/5) { Log("Translated {0} browse paths.", paths); paths = 0; } pathsToTranslate.Clear(); } position += increment; ReportProgress(position); } // process final batch. if (success) { if (pathsToTranslate.Count > 0) { if (!Translate(pathsToTranslate)) { success = false; } else { Log("Translated {0} browse paths.", paths); } } } return success; }