/// <summary> /// Updates the information on a specific element into the data store. /// </summary> /// <param name="data">The element data.</param> public void UpdateDataStore(ElementsDataStoreData data) { lock (_dataStoreLock) { _dataStoreElementsData[data.ElementID] = new ElementsDataStoreData(data); } }
public void DistributeBaselineScenario_Nominal() { const string FUTURE_VERSION = "1.0.0.0"; // Common initialization CreateT2GServicesStub(); _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior(); InitializeTrain(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, TRAIN_IP_1, TRAIN_DATA_PACKAGE_PORT_1); InitializeDataPackageService(false); InitializePISGroundSession(); WaitPisGroundIsConnectedWithT2G(); WaitTrainOnlineWithPISGround(TRAIN_NAME_1, true); // Initializations specific to this test. ElementsDataStoreData data = new ElementsDataStoreData(TRAIN_NAME_1); data.FutureBaseline = FUTURE_VERSION; data.FutureBaselineActivationDate = RemoteDataStoreDataBase.ToString(DateTime.Today); data.FutureBaselineExpirationDate = RemoteDataStoreDataBase.ToString(DateTime.Now.AddMinutes(20)); _dataStoreServiceStub.UpdateDataStore(data); _dataStoreServiceStub.AddBaselineToRemoteDataStore(FUTURE_VERSION); // Request the datapackage service to distribute the baseline DataPackageResult result = _datapackageServiceStub.distributeBaseline(_pisGroundSessionId, null, new TargetAddressType(TRAIN_NAME_1), CreateDistributionAttribute(), false); Assert.AreEqual(DataPackageErrorEnum.REQUEST_ACCEPTED, result.error_code, "Distribute baseline to train {0} does not returned the expected value", TRAIN_NAME_1); // Wait that folder on T2G was created Assert.That(() => _fileTransferServiceStub.LastCreatedFolder.HasValue, Is.True.After(30 * ONE_SECOND, ONE_SECOND / 4), "Distribute baseline to train {0} failure. Transfer folder on T2G service not created", TRAIN_NAME_1); int transferFolderId = _fileTransferServiceStub.LastCreatedFolder.Value; _fileTransferServiceStub.LastCreatedFolder = null; Assert.That(() => _fileTransferServiceStub.LastCreatedTransfer.HasValue, Is.True.After(30 * ONE_SECOND, ONE_SECOND / 4), "Distribute baseline to train {0} failure. Transfer task on T2G service not created", TRAIN_NAME_1); int transferTaskId = _fileTransferServiceStub.LastCreatedTransfer.Value; _fileTransferServiceStub.LastCreatedTransfer = null; _fileTransferServiceStub.PerformTransferProgression(); // Probleme VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.TRANSFER_PLANNED); while (_fileTransferServiceStub.IsTaskRunning(transferTaskId)) { _fileTransferServiceStub.PerformTransferProgression(); BaselineProgressStatusEnum expectedProgress = _fileTransferServiceStub.GetTask(transferTaskId).BaselineProgress; VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, expectedProgress); Thread.Sleep(ONE_SECOND / 4); } Thread.Sleep(5 * ONE_SECOND); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.TRANSFER_COMPLETED); // Simulate that train retrieved the baseline on embedded side. BaselineMessage baselineInfo = new BaselineMessage(TRAIN_NAME_1); baselineInfo.CurrentVersion = DEFAULT_BASELINE; baselineInfo.FutureVersion = FUTURE_VERSION; _vehicleInfoServiceStub.UpdateMessageData(baselineInfo); WaitBaselineStatusBecomeInState(TRAIN_NAME_1, BaselineProgressStatusEnum.DEPLOYED); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.DEPLOYED); // Simulate that train replaced the current baseline with the future. baselineInfo.ArchivedVersion = baselineInfo.CurrentVersion; baselineInfo.CurrentVersion = baselineInfo.FutureVersion; baselineInfo.FutureVersion = string.Empty; _vehicleInfoServiceStub.UpdateMessageData(baselineInfo); WaitBaselineStatusBecomeInState(TRAIN_NAME_1, BaselineProgressStatusEnum.UPDATED); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, FUTURE_VERSION, "0.0.0.0", Guid.Empty, 0, BaselineProgressStatusEnum.UPDATED); }
public void DistributeBaselineScenario_TransferTask_Expire_During_Acquisition() { const string FUTURE_VERSION = "1.0.0.0"; // Common initialization CreateT2GServicesStub(); _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior(); InitializeTrain(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, TRAIN_IP_1, TRAIN_DATA_PACKAGE_PORT_1, CommLinkEnum.notApplicable); InitializeDataPackageService(false); InitializePISGroundSession(); WaitPisGroundIsConnectedWithT2G(); WaitTrainOnlineWithPISGround(TRAIN_NAME_1, true); // Initializations specific to this test. ElementsDataStoreData data = new ElementsDataStoreData(TRAIN_NAME_1); data.FutureBaseline = FUTURE_VERSION; data.FutureBaselineActivationDate = RemoteDataStoreDataBase.ToString(DateTime.Today); data.FutureBaselineExpirationDate = RemoteDataStoreDataBase.ToString(DateTime.Now.AddSeconds(40)); _dataStoreServiceStub.UpdateDataStore(data); _dataStoreServiceStub.AddBaselineToRemoteDataStore(FUTURE_VERSION); // Request the datapackage service to distribute the baseline DataPackageResult result = _datapackageServiceStub.distributeBaseline(_pisGroundSessionId, null, new TargetAddressType(TRAIN_NAME_1), CreateDistributionAttribute(), false); Assert.AreEqual(DataPackageErrorEnum.REQUEST_ACCEPTED, result.error_code, "Distribute baseline to train {0} does not returned the expected value", TRAIN_NAME_1); // Wait that folder on T2G was created Assert.That(() => _fileTransferServiceStub.LastCreatedFolder.HasValue, Is.True.After(30 * ONE_SECOND, ONE_SECOND / 4), "Distribute baseline to train {0} failure. Transfer folder on T2G service not created", TRAIN_NAME_1); int transferFolderId = _fileTransferServiceStub.LastCreatedFolder.Value; _fileTransferServiceStub.LastCreatedFolder = null; Assert.That(() => _fileTransferServiceStub.LastCreatedTransfer.HasValue, Is.True.After(30 * ONE_SECOND, ONE_SECOND / 4), "Distribute baseline to train {0} failure. Transfer task on T2G service not created", TRAIN_NAME_1); int transferTaskId = _fileTransferServiceStub.LastCreatedTransfer.Value; _fileTransferServiceStub.LastCreatedTransfer = null; _fileTransferServiceStub.SetTransferExpiration(transferTaskId, DateTime.UtcNow.AddSeconds(10)); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.TRANSFER_PLANNED); _fileTransferServiceStub.PerformTransferProgression(); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.TRANSFER_PLANNED); _fileTransferServiceStub.PerformTransferProgression(); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.TRANSFER_PLANNED); Assert.AreEqual(TaskPhaseEnum.acquisitionPhase, _fileTransferServiceStub.GetTask(transferTaskId).taskPhase, "The transfer task is supported to be in acquisition"); Assert.IsTrue(_fileTransferServiceStub.IsTaskRunning(transferTaskId), "The transfer task is not running as expected"); Assert.IsNull(_fileTransferServiceStub.LastCreatedFolder, "Folder created while expecting not"); Assert.IsNull(_fileTransferServiceStub.LastCreatedTransfer, "Transfer task created while expecting not"); Thread.Sleep(15 * ONE_SECOND); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.TRANSFER_PLANNED); Assert.IsNull(_fileTransferServiceStub.LastCreatedFolder, "Folder created while expecting not"); Assert.IsNull(_fileTransferServiceStub.LastCreatedTransfer, "Transfer task created while expecting not"); Assert.AreEqual(TaskPhaseEnum.acquisitionPhase, _fileTransferServiceStub.GetTask(transferTaskId).taskPhase, "The transfer task is supported to be in acquisition"); Assert.IsTrue(_fileTransferServiceStub.IsTaskRunning(transferTaskId), "The transfer task is not running as expected"); _fileTransferServiceStub.PerformTransferProgression(); Assert.AreEqual(TaskPhaseEnum.acquisitionPhase, _fileTransferServiceStub.GetTask(transferTaskId).taskPhase, "The transfer task is supported to be in acquisition"); Assert.IsFalse(_fileTransferServiceStub.IsTaskRunning(transferTaskId), "The transfer task is running while expecting not"); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, BaselineStatusUpdater.NoBaselineVersion, Guid.Empty, 0, BaselineProgressStatusEnum.UNKNOWN); Assert.IsNull(_fileTransferServiceStub.LastCreatedFolder, "Folder created while expecting not"); Assert.IsNull(_fileTransferServiceStub.LastCreatedTransfer, "Transfer task created while expecting not"); // Wait 5 seconds Thread.Sleep(5 * ONE_SECOND); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, BaselineStatusUpdater.NoBaselineVersion, Guid.Empty, 0, BaselineProgressStatusEnum.UNKNOWN); Assert.IsNull(_fileTransferServiceStub.LastCreatedFolder, "Folder created while expecting not"); Assert.IsNull(_fileTransferServiceStub.LastCreatedTransfer, "Transfer task created while expecting not"); }
public void DistributeBaselineScenario_WaitForCommunicationLink_RestartPisGround_ThenDistributionComplete() { const string FUTURE_VERSION = "1.0.0.0"; // Common initialization CreateT2GServicesStub(); _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior(); InitializeTrain(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, TRAIN_IP_1, TRAIN_DATA_PACKAGE_PORT_1, CommLinkEnum.notApplicable); InitializeDataPackageService(false); InitializePISGroundSession(); WaitPisGroundIsConnectedWithT2G(); WaitTrainOnlineWithPISGround(TRAIN_NAME_1, true); // Initializations specific to this test. ElementsDataStoreData data = new ElementsDataStoreData(TRAIN_NAME_1); data.FutureBaseline = FUTURE_VERSION; data.FutureBaselineActivationDate = RemoteDataStoreDataBase.ToString(DateTime.Today); data.FutureBaselineExpirationDate = RemoteDataStoreDataBase.ToString(DateTime.Now.AddMinutes(20)); _dataStoreServiceStub.UpdateDataStore(data); _dataStoreServiceStub.AddBaselineToRemoteDataStore(FUTURE_VERSION); // Request the datapackage service to distribute the baseline DataPackageResult result = _datapackageServiceStub.distributeBaseline(_pisGroundSessionId, null, new TargetAddressType(TRAIN_NAME_1), CreateDistributionAttribute(), false); Assert.AreEqual(DataPackageErrorEnum.REQUEST_ACCEPTED, result.error_code, "Distribute baseline to train {0} does not returned the expected value", TRAIN_NAME_1); // Wait that folder on T2G was created Assert.That(() => _fileTransferServiceStub.LastCreatedFolder.HasValue, Is.True.After(30 * ONE_SECOND, ONE_SECOND / 4), "Distribute baseline to train {0} failure. Transfer folder on T2G service not created", TRAIN_NAME_1); int transferFolderId = _fileTransferServiceStub.LastCreatedFolder.Value; _fileTransferServiceStub.LastCreatedFolder = null; Assert.That(() => _fileTransferServiceStub.LastCreatedTransfer.HasValue, Is.True.After(30 * ONE_SECOND, ONE_SECOND / 4), "Distribute baseline to train {0} failure. Transfer task on T2G service not created", TRAIN_NAME_1); int transferTaskId = _fileTransferServiceStub.LastCreatedTransfer.Value; _fileTransferServiceStub.LastCreatedTransfer = null; _fileTransferServiceStub.PerformTransferProgression(); while (_fileTransferServiceStub.GetTask(transferTaskId).taskPhase == T2GServiceInterface.FileTransfer.taskPhaseEnum.acquisitionPhase) { VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, _fileTransferServiceStub.GetTask(transferTaskId).BaselineProgress); _fileTransferServiceStub.PerformTransferProgression(); Assert.IsNull(_fileTransferServiceStub.LastCreatedFolder, "Folder created while expecting not"); Assert.IsNull(_fileTransferServiceStub.LastCreatedTransfer, "Transfer task created while expecting not"); Assert.IsTrue(_fileTransferServiceStub.IsTaskRunning(transferTaskId), "The transfer task is not running as expected"); Thread.Sleep(ONE_SECOND / 4); } VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, _fileTransferServiceStub.GetTask(transferTaskId).BaselineProgress); // Stop data package service. StopDataPackageService(); // Wait 2 seconds Thread.Sleep(2 * ONE_SECOND); // Restart the datapackage service InitializeDataPackageService(true); WaitPisGroundIsConnectedWithT2G(); WaitTrainOnlineWithPISGround(TRAIN_NAME_1, true); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, _fileTransferServiceStub.GetTask(transferTaskId).BaselineProgress); // Wait 2 seconds Thread.Sleep(2 * ONE_SECOND); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, _fileTransferServiceStub.GetTask(transferTaskId).BaselineProgress); // Update the communication link of the train _identificationServiceStub.UpdateSystem(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, 0, DEFAULT_MISSION, CommLinkEnum.wifi, TRAIN_IP_1); _fileTransferServiceStub.PerformTransferProgression(); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, _fileTransferServiceStub.GetTask(transferTaskId).BaselineProgress); _fileTransferServiceStub.PerformTransferProgression(); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.TRANSFER_IN_PROGRESS); Assert.That(() => { _fileTransferServiceStub.PerformTransferProgression(); return(_fileTransferServiceStub.GetTask(transferTaskId).IsInFinalState); }, Is.True.After(10 * ONE_SECOND, ONE_SECOND / 4), "Transfer does not complete as expected"); Assert.IsNull(_fileTransferServiceStub.LastCreatedFolder, "Folder created while expecting not"); Assert.IsNull(_fileTransferServiceStub.LastCreatedTransfer, "Transfer task created while expecting not"); { TransferTaskInfo task = _fileTransferServiceStub.GetTask(transferTaskId); Assert.AreEqual(TaskStateEnum.taskCompleted, task.taskState, "Transfer does not complete as expected"); } WaitBaselineStatusBecomeInState(TRAIN_NAME_1, BaselineProgressStatusEnum.TRANSFER_COMPLETED); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.TRANSFER_COMPLETED); // Simulate that train retrieved the baseline on embedded side. BaselineMessage baselineInfo = new BaselineMessage(TRAIN_NAME_1); baselineInfo.CurrentVersion = DEFAULT_BASELINE; baselineInfo.FutureVersion = FUTURE_VERSION; _vehicleInfoServiceStub.UpdateMessageData(baselineInfo); WaitBaselineStatusBecomeInState(TRAIN_NAME_1, BaselineProgressStatusEnum.DEPLOYED); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, DEFAULT_BASELINE, FUTURE_VERSION, result.reqId, transferTaskId, BaselineProgressStatusEnum.DEPLOYED); // Simulate that train replaced the current baseline with the future. baselineInfo.ArchivedVersion = baselineInfo.CurrentVersion; baselineInfo.CurrentVersion = baselineInfo.FutureVersion; baselineInfo.FutureVersion = string.Empty; _vehicleInfoServiceStub.UpdateMessageData(baselineInfo); WaitBaselineStatusBecomeInState(TRAIN_NAME_1, BaselineProgressStatusEnum.UPDATED); VerifyTrainBaselineStatusInHistoryLog(TRAIN_NAME_1, true, FUTURE_VERSION, "0.0.0.0", Guid.Empty, 0, BaselineProgressStatusEnum.UPDATED); }
/// <summary> /// Initializes a new instance of the <see cref="ElementsDataStoreData"/> class. /// </summary> /// <param name="other">The other object to copy.</param> public ElementsDataStoreData(ElementsDataStoreData other) : base(other) { }