/// <summary> /// Operational competes a behavior /// </summary> /// <param name="report"></param> public override void OnCompletionReport(CompletionReport report) { try { if (report.Result == CompletionResult.Success) { ArbiterOutput.OutputNoLog("Received Completion Report: " + report.BehaviorType.ToString() + ", Result: " + report.Result.ToString()); } else if (this.ArbiterBlockageHandler != null && report is TrajectoryBlockedReport) { this.ArbiterBlockageHandler.OnBlockageReport((TrajectoryBlockedReport)report); } lock (this.recentReports) { this.recentReports = new List <KeyValuePair <CompletionReport, DateTime> >(this.recentReports.ToArray()); this.recentReports.Add(new KeyValuePair <CompletionReport, DateTime>(report, DateTime.Now)); } } catch (Exception e) { try { ArbiterOutput.OutputNoLog("Error in completion report"); ArbiterOutput.WriteToLog(e.ToString()); } catch (Exception) { } } }
/// <summary> /// Test executue a behavior /// </summary> /// <param name="b"></param> /// <param name="completionReport"></param> public bool TestExecute(Behavior b, out CompletionReport completionReport) { if (this.operationalTestFacade != null) { try { b.TimeStamp = CoreCommon.Communications.GetVehicleState().Timestamp; completionReport = this.operationalTestFacade.TestExecuteBehavior(b); ArbiterOutput.OutputNoLog("test execute: " + b.ShortBehaviorInformation() + " completion report: " + completionReport.GetType().ToString()); return(completionReport.Result == CompletionResult.Success); } catch (Exception e) { completionReport = new SuccessCompletionReport(b.GetType()); ArbiterOutput.OutputNoLog("test execute: " + b.ShortBehaviorInformation() + " encountered error: " + e.ToString()); this.TryOperationalTestFacadeConnect(); return(true); } } else { completionReport = new SuccessCompletionReport(b.GetType()); ArbiterOutput.OutputNoLog("test execute: " + b.ShortBehaviorInformation() + " encountered error: operational test facade does not exist"); this.TryOperationalTestFacadeConnect(); return(true); } }
private static void OnPackageOperationCompleted(object sender, CompletionReport e) { switch (e.Operation) { case PackageOperation.Installing: routeDescriptionBox.Text = Translations.GetInterfaceString("packages_install_success") + Environment.NewLine + Environment.NewLine + Translations.GetInterfaceString("packages_install_success_files") + Environment.NewLine + installedFiles; currentFile = string.Empty; installedFiles = string.Empty; switch (currentPackage.PackageType) { case PackageType.Route: Database.currentDatabase.InstalledRoutes.Remove(currentPackage); Database.currentDatabase.InstalledRoutes.Add(currentPackage); break; case PackageType.Train: Database.currentDatabase.InstalledTrains.Remove(currentPackage); Database.currentDatabase.InstalledTrains.Add(currentPackage); break; default: Database.currentDatabase.InstalledOther.Remove(currentPackage); Database.currentDatabase.InstalledOther.Add(currentPackage); break; } currentPackage = null; Database.SaveDatabase(); break; } }
public CompletionReport TestBehavior(Behavior b) { IOperationalBehavior operBehavior = null; try { testMode = true; Console.WriteLine("Testing behavior " + b.ToString() + " -- type " + b.GetType().Name); cachedCompletionReport = new SuccessCompletionReport(b.GetType()); HandleDecorators(b.Decorators); operBehavior = MapBehavior(b); operBehavior.Initialize(b); operBehavior.Process(null); Console.WriteLine("Result: " + cachedCompletionReport.ToString()); cachedCompletionReport.BehaviorId = b.UniqueId(); return(cachedCompletionReport); } catch (Exception ex) { TraceSource.TraceEvent(TraceEventType.Error, 0, "error testing behavior {0}: {1}", b.GetType(), ex); throw; } finally { if (operBehavior != null && operBehavior is IDisposable) { ((IDisposable)operBehavior).Dispose(); } } }
public void VerifyResult() { DownloadCompletionAndUsageReportExample example = new DownloadCompletionAndUsageReportExample(Props.GetInstance()); example.Run(); // Assert correct download of completion report CompletionReport completionReport = example.sdkCompletionReport; Assert.GreaterOrEqual(completionReport.Senders.Count, 1, "There should be only 1 sender."); Assert.GreaterOrEqual(completionReport.Senders[0].Packages.Count, 1, "Number of package completion reports should be greater than 1."); Assert.GreaterOrEqual(completionReport.Senders[0].Packages[0].Documents.Count, 1, "Number of document completion reports should be greater than 1."); Assert.GreaterOrEqual(completionReport.Senders[0].Packages[0].Signers.Count, 1, "Number of signer completion reports should be greater than 1."); Assert.IsNotNull(example.csvCompletionReport); Assert.IsNotEmpty(example.csvCompletionReport); // Assert correct download of usage report UsageReport usageReport = example.sdkUsageReport; Assert.Greater(usageReport.SenderUsageReports.Count, 0, "There should be only 1 sender."); Assert.Greater(usageReport.SenderUsageReports[0].CountByUsageReportCategory.Count, 0, "Number of dictionary entries should be greater than 0."); Assert.IsTrue(usageReport.SenderUsageReports[0].CountByUsageReportCategory.ContainsKey(UsageReportCategory.DRAFT), "There should be at a draft key in packages map."); Assert.Greater(usageReport.SenderUsageReports[0].CountByUsageReportCategory[UsageReportCategory.DRAFT], 0, "Number of drafts should be greater than 0."); Assert.IsNotNull(example.csvUsageReport, "Usage report in csv cannot be null."); Assert.IsNotEmpty(example.csvUsageReport, "Usage report in csv cannot be empty."); }
/* * /// <summary> * /// Enter a behavior in the test execute queue * /// </summary> * /// <param name="testTurnBehavior"></param> * /// <param name="resetQueue"></param> * public void AsynchronousTestExecute(TurnBehavior testTurnBehavior, bool resetQueue) * { * if (resetQueue || this.testAsyncExecuteQueue.Count > 10) * { * Queue<Behavior> tmp = new Queue<Behavior>(); * tmp.Enqueue(testTurnBehavior); * this.testAsyncExecuteQueue = tmp; * } * else * { * Queue<Behavior> tmp = new Queue<Behavior>(this.testAsyncExecuteQueue); * tmp.Enqueue(testTurnBehavior); * this.testAsyncExecuteQueue = tmp; * } * }*/ /// <summary> /// Check if we have completed testing a behavior /// </summary> /// <param name="testBehavior"></param> /// <param name="completionReport"></param> /// <param name="idMatch"></param> /// <returns></returns> public bool AsynchronousTestHasCompleted(Behavior testBehavior, out CompletionReport completionReport, bool idMatch) { completionReport = null; foreach (TestBehaviorCompletion tbc in this.testModeRecentCompleted) { // check type if (tbc.Behavior.GetType().Equals(testBehavior.GetType())) { if (idMatch) { if (testBehavior.UniqueId().Equals(tbc.Behavior.UniqueId())) { completionReport = tbc.Report; return(true); } } else { return(true); } } } return(false); }
private void AssertCreatedPackageIncludedInCompletionReport(CompletionReport completionReport, string sender, PackageId packageId, string packageStatus) { PackageCompletionReport createdPackageCompletionReport = GetCreatedPackageCompletionReport(completionReport, sender, packageId); Assert.IsNotNull(createdPackageCompletionReport); Assert.IsNotNull(createdPackageCompletionReport.DocumentPackageStatus); Assert.AreEqual(packageStatus, createdPackageCompletionReport.DocumentPackageStatus.GetName()); }
private int GetCompletionReportCount(CompletionReport completionReport) { int count = 0; foreach (SenderCompletionReport senderCompletionReport in completionReport.Senders) { count += senderCompletionReport.Packages.Count; } return(count); }
public void CompletionReportResponse(string executionNodeID, CompletionReport report) { Application.Current.Dispatcher.Invoke(delegate { try { CentralMessagingHub.iccController.SetCompletionReport(executionNodeID, report, Context); } catch (Exception ex) { Debug.WriteLine("Setting Source Report error. " + ex.Message); } }); }
private SenderCompletionReport GetSenderCompletionReport(CompletionReport completionReport, string sender) { foreach (SenderCompletionReport senderCompletionReport in completionReport.Senders) { if (senderCompletionReport.Sender.Id.Equals(sender)) { return(senderCompletionReport); } } return(null); }
public void SetCompletionReport(string executionNodeID, CompletionReport report, HubCallerContext context) { Application.Current.Dispatcher.Invoke(delegate { if (clientTabControls.ContainsKey(context.ConnectionId)) { ClientTabControl client = clientTabControls[context.ConnectionId]; client.SetCompletionReportText(report); ClientControl client2 = clientControls[context.ConnectionId]; client2.iterationRecords = report; } }); }
protected override void ForwardCompletionReport(CompletionReport report) { if (reverseGear && report is TrajectoryBlockedReport) { // just because we're assholes, replace the blockage with a success when we're in reverse and // execute a hold brake Services.BehaviorManager.Execute(new HoldBrakeBehavior(), null, true); base.ForwardCompletionReport(new SuccessCompletionReport(typeof(StayInLaneBehavior))); } else { base.ForwardCompletionReport(report); } }
private PackageCompletionReport GetCreatedPackageCompletionReport(CompletionReport completionReport, string sender, PackageId packageId) { SenderCompletionReport senderCompletionReport = GetSenderCompletionReport(completionReport, sender); IList <PackageCompletionReport> packageCompletionReports = senderCompletionReport.Packages; foreach (PackageCompletionReport packageCompletionReport in packageCompletionReports) { if (packageCompletionReport.Id.Equals(packageId.Id)) { return(packageCompletionReport); } } return(null); }
internal void SendCompletionReport(string executionNodeID, CompletionReport report) { if (localOnly) { logger.Info("Completion Report"); logger.Info(report); } else { logger.Info("Completion Report"); logger.Info(report.ToString()); Task.Run(() => { this.hubProxy.Invoke("CompletionReportResponse", executionNodeID, report); }); } }
public void ForwardCompletionReport(CompletionReport report) { if (testMode) { cachedCompletionReport = report; Console.WriteLine("forward comp report: " + report.ToString()); } else { if (report is TrajectoryBlockedReport) { ((TrajectoryBlockedReport)report).SAUDILevel = saudiLevel; } if (Services.Operational != null) { Services.Operational.SendCompletionReport(report); } } }
protected override void ForwardCompletionReport(CompletionReport report) { // we only want to forward success completion reports if (report is SuccessCompletionReport) { base.ForwardCompletionReport(report); } else { // otherwise, we have a blockage // if it's dynamically infeasible, then we want to do a reverse and try again Console.WriteLine("zone trizavel: intercepted blockage report"); if (reverseGear) { Console.WriteLine("in reverse, switch to forward"); // we're in reverse, switch back to forward reverseGear = false; lastDynInfeasibleTime = null; prevCurvature = double.NaN; } else { if (arcMode) { Console.WriteLine("arc mode blocked, switch to reverse"); reverseGear = true; lastDynInfeasibleTime = null; prevCurvature = double.NaN; InitializeReverse(); } else { Console.WriteLine("switch to arc mode"); arcMode = true; lastDynInfeasibleTime = null; arcModeTimer = Stopwatch.StartNew(); prevCurvature = double.NaN; } } } }
public TestBehaviorCompletion(double completionTs, CompletionReport cr, Behavior b) { this.CompletionTimestamp = completionTs; this.Report = cr; this.Behavior = b; }
public abstract void OnCompletionReport(CompletionReport report);
public void VerifyResult() { lock (lockThis) { DownloadReportExample example = new DownloadReportExample(); example.Run(); // Assert correct download of completion report for a sender CompletionReport completionReportForSender = example.sdkCompletionReportForSenderDraft; SenderCompletionReport senderCompletionReportForSenderId1 = getSenderCompletionReportForSenderId(example.sdkCompletionReportForSenderDraft.Senders, example.senderUID); Assert.AreEqual(completionReportForSender.Senders.Count, 1, "There should be only 1 sender."); Assert.GreaterOrEqual(senderCompletionReportForSenderId1.Packages.Count, 1, "Number of package completion reports should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId1.Packages[0].Documents.Count, 1, "Number of document completion reports should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId1.Packages[0].Signers.Count, 1, "Number of signer completion reports should be greater than 1."); AssertCreatedPackageIncludedInCompletionReport(completionReportForSender, example.senderUID, example.PackageId, "DRAFT"); Assert.IsNotNull(example.csvCompletionReportForSenderDraft); Assert.IsNotEmpty(example.csvCompletionReportForSenderDraft); CSVReader reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvCompletionReportForSenderDraft)))); IList <string[]> rows = reader.readAll(); if (senderCompletionReportForSenderId1.Packages.Count > 0) { Assert.GreaterOrEqual(rows.Count, senderCompletionReportForSenderId1.Packages.Count - 1); Assert.LessOrEqual(rows.Count, senderCompletionReportForSenderId1.Packages.Count + 3); } AssertCreatedPackageIncludedInCSV(rows, example.PackageId, "DRAFT"); SenderCompletionReport senderCompletionReportForSenderId3 = getSenderCompletionReportForSenderId(example.sdkCompletionReportForSenderSent.Senders, example.senderUID); completionReportForSender = example.sdkCompletionReportForSenderSent; Assert.AreEqual(completionReportForSender.Senders.Count, 1, "There should be only 1 sender."); Assert.GreaterOrEqual(senderCompletionReportForSenderId3.Packages.Count, 1, "Number of package completion reports should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId3.Packages[0].Documents.Count, 1, "Number of document completion reports should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId3.Packages[0].Signers.Count, 1, "Number of signer completion reports should be greater than 1."); AssertCreatedPackageIncludedInCompletionReport(completionReportForSender, example.senderUID, example.package2Id, "SENT"); Assert.IsNotNull(example.csvCompletionReportForSenderSent); Assert.IsNotEmpty(example.csvCompletionReportForSenderSent); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvCompletionReportForSenderSent)))); rows = reader.readAll(); if (senderCompletionReportForSenderId3.Packages.Count > 0) { Assert.GreaterOrEqual(rows.Count, senderCompletionReportForSenderId3.Packages.Count - 1); Assert.LessOrEqual(rows.Count, senderCompletionReportForSenderId3.Packages.Count + 3); } AssertCreatedPackageIncludedInCSV(rows, example.package2Id, "SENT"); // Assert correct download of completion report for all senders CompletionReport completionReport = example.sdkCompletionReportDraft; SenderCompletionReport senderCompletionReportForSenderId2 = getSenderCompletionReportForSenderId(completionReport.Senders, example.senderUID); Assert.GreaterOrEqual(completionReport.Senders.Count, 1, "Number of sender should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId2.Packages.Count, 0, "Number of package completion reports should be greater than 0."); AssertCreatedPackageIncludedInCompletionReport(completionReport, example.senderUID, example.PackageId, "DRAFT"); Assert.IsNotNull(example.csvCompletionReportDraft); Assert.IsNotEmpty(example.csvCompletionReportDraft); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvCompletionReportDraft)))); rows = reader.readAll(); if (senderCompletionReportForSenderId2.Packages.Count > 0) { Assert.GreaterOrEqual(rows.Count, GetCompletionReportCount(completionReport) - 1); Assert.LessOrEqual(rows.Count, GetCompletionReportCount(completionReport) + 3); } AssertCreatedPackageIncludedInCSV(rows, example.PackageId, "DRAFT"); completionReport = example.sdkCompletionReportSent; Assert.GreaterOrEqual(completionReport.Senders.Count, 1, "Number of sender should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId2.Packages.Count, 0, "Number of package completion reports should be greater than 0."); AssertCreatedPackageIncludedInCompletionReport(completionReport, example.senderUID, example.package2Id, "SENT"); Assert.IsNotNull(example.csvCompletionReportSent); Assert.IsNotEmpty(example.csvCompletionReportSent); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvCompletionReportSent)))); rows = reader.readAll(); if (senderCompletionReportForSenderId2.Packages.Count > 0) { Assert.GreaterOrEqual(rows.Count, GetCompletionReportCount(completionReport) - 1); Assert.LessOrEqual(rows.Count, GetCompletionReportCount(completionReport) + 3); } AssertCreatedPackageIncludedInCSV(rows, example.package2Id, "SENT"); // Assert correct download of usage report UsageReport usageReport = example.sdkUsageReport; SenderUsageReport senderUsageReportForSenderId = getSenderUsageReportForSenderId(usageReport.SenderUsageReports, example.senderUID); Assert.Greater(usageReport.SenderUsageReports.Count, 0, "There should be only 1 sender."); Assert.GreaterOrEqual(senderUsageReportForSenderId.CountByUsageReportCategory.Count, 1, "Number of map entries should be greater or equal to 1."); Assert.IsTrue(senderUsageReportForSenderId.CountByUsageReportCategory.ContainsKey(UsageReportCategory.DRAFT), "There should be at a draft key in packages map."); Assert.GreaterOrEqual(senderUsageReportForSenderId.CountByUsageReportCategory[UsageReportCategory.DRAFT], 1, "Number of drafts should be greater or equal to 1."); Assert.IsNotNull(example.csvUsageReport, "Usage report in csv cannot be null."); Assert.IsNotEmpty(example.csvUsageReport, "Usage report in csv cannot be empty."); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvUsageReport)))); rows = reader.readAll(); if (usageReport.SenderUsageReports.Count > 0) { Assert.GreaterOrEqual(rows.Count, usageReport.SenderUsageReports.Count - 1); Assert.LessOrEqual(rows.Count, usageReport.SenderUsageReports.Count + 3); } // Assert correct download of delegation report DelegationReport delegationReportForAccountWithoutDate = example.sdkDelegationReportForAccountWithoutDate; Assert.GreaterOrEqual(delegationReportForAccountWithoutDate.DelegationEvents.Count, 0, "Number of DelegationEventReports should be greater than 0."); Assert.IsNotNull(example.csvDelegationReportForAccountWithoutDate, "Delegation report in csv cannot be null."); Assert.IsNotEmpty(example.csvDelegationReportForAccountWithoutDate, "Delegation report in csv cannot be empty."); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvDelegationReportForAccountWithoutDate)))); rows = reader.readAll(); if (delegationReportForAccountWithoutDate.DelegationEvents.Count > 0) { rows = GetRowsBySender(rows, example.senderUID); Assert.AreEqual(delegationReportForAccountWithoutDate.DelegationEvents[example.senderUID].Count, rows.Count); } DelegationReport delegationReportForAccount = example.sdkDelegationReportForAccount; Assert.GreaterOrEqual(delegationReportForAccount.DelegationEvents.Count, 0, "Number of DelegationEventReports should be greater than 0."); Assert.IsNotNull(example.csvDelegationReportForAccount, "Delegation report in csv cannot be null."); Assert.IsNotEmpty(example.csvDelegationReportForAccount, "Delegation report in csv cannot be empty."); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvDelegationReportForAccount)))); rows = reader.readAll(); if (delegationReportForAccount.DelegationEvents.Count > 0) { rows = GetRowsBySender(rows, example.senderUID); Assert.AreEqual(delegationReportForAccount.DelegationEvents[example.senderUID].Count, rows.Count); } DelegationReport delegationReportForSender = example.sdkDelegationReportForSender; Assert.GreaterOrEqual(delegationReportForSender.DelegationEvents.Count, 0, "Number of DelegationEventReports should be greater than 0."); Assert.IsNotNull(example.csvDelegationReportForSender, "Delegation report in csv cannot be null."); Assert.IsNotEmpty(example.csvDelegationReportForSender, "Delegation report in csv cannot be empty."); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvDelegationReportForSender)))); rows = reader.readAll(); if (delegationReportForSender.DelegationEvents.Count > 0) { rows = GetRowsBySender(rows, example.senderUID); Assert.AreEqual(delegationReportForSender.DelegationEvents[example.senderUID].Count, rows.Count); } } }
internal void SetCompletionReportText(CompletionReport report) { Application.Current.Dispatcher.Invoke((Action) delegate { CompletionReport = report; }); }
/// <summary> /// Manages excution of the test behaviros /// </summary> private void AsynchronousExecutionManager() { // execute ten times per second MMWaitableTimer mmwt = new MMWaitableTimer(100); // initialize this.testAsyncExecuteQueue = new Queue <Behavior>(); this.testBehaviorExecutionStopwatch = new Stopwatch(); this.testModeRecentCompleted = new List <TestBehaviorCompletion>(); this.testCurrentTest = null; this.testCompletionReport = null; // loop constantly while (true) { // make sre we are timing properly mmwt.WaitEvent.WaitOne(); // reset values this.testCurrentTest = null; this.testCompletionReport = null; // update the list of completed to only include those in last 10 seconds List <TestBehaviorCompletion> updatedRecent = new List <TestBehaviorCompletion>(); foreach (TestBehaviorCompletion tbc in this.testModeRecentCompleted) { if (this.GetVehicleState().Timestamp - tbc.CompletionTimestamp < 10.0) { updatedRecent.Add(tbc); } } this.testModeRecentCompleted = updatedRecent; try { if (!this.testComponentNeedsRoadNetwork && this.testComponentExists && testAsyncExecuteQueue.Count > 0) { // reset timer this.testBehaviorExecutionStopwatch.Stop(); this.testBehaviorExecutionStopwatch.Reset(); // eavior this.testCurrentTest = testAsyncExecuteQueue.Dequeue(); // thread the execution this.testBehaviorExecutionThread = new Thread(TestBehaviorExecutionThread); this.testBehaviorExecutionThread.IsBackground = true; this.testBehaviorExecutionStopwatch.Start(); this.testBehaviorExecutionThread.Start(); // test execution time while (this.testBehaviorExecutionThread.IsAlive) { // check time if (this.testBehaviorExecutionStopwatch.ElapsedMilliseconds / 1000.0 > 3.0) { try { ArbiterOutput.OutputNoLog("Test Behavior Execution took Longer than 3 seconds, aborting"); this.testBehaviorExecutionThread.Abort(); } catch (Exception) { } } // fine else { // take 10ms Thread.Sleep(100); } } // check completion report status if (this.testCompletionReport != null) { List <TestBehaviorCompletion> updated = new List <TestBehaviorCompletion>(this.testModeRecentCompleted.ToArray()); updated.Add(new TestBehaviorCompletion(this.GetVehicleState().Timestamp, this.testCompletionReport, this.testCurrentTest)); this.testModeRecentCompleted = updated; } this.testCompletionReport = null; this.testCurrentTest = null; } else { try { this.operationalTestFacade.Ping(); this.testComponentExists = true; } catch (Exception) { this.testComponentExists = false; this.testComponentNeedsRoadNetwork = true; this.TryOperationalTestFacadeConnect(); } if (!this.testComponentExists || this.testComponentNeedsRoadNetwork) { this.TryOperationalTestFacadeConnect(); } } } catch (Exception e) { } } }