public void ApplicationStatesToRemoveTestGettingItEmpty() { StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters(); // I want it to return a 0 length array rather than a null Assert.AreEqual(0, maintanenceParameters.ApplicationStatesToRemove.Length); }
public void AddApplicationStatesToRemoveTestNull() { StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters(); maintanenceParameters.AddApplicationStatesToRemove(null); Assert.AreEqual(0, maintanenceParameters.ApplicationStatesToRemove.Length); }
public void AddApplicationStateToRemoveTestAddOne() { StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters(); maintanenceParameters.AddApplicationStateToRemove(ApplicationState.Ready); Assert.AreEqual(1, maintanenceParameters.ApplicationStatesToRemove.Length); Assert.AreEqual(ApplicationState.Ready, maintanenceParameters.ApplicationStatesToRemove[0]); }
public void PerformMaintenanceTestNothingToRemove() { Maintenance maintenance = new Maintenance(); StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters(); PrepareComplexStorageForMaintenanceTests(); maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters); Assert.AreEqual(4, m_managerStorage.GetExecutors().Length); Assert.AreEqual(5, m_managerStorage.GetApplications().Length); }
public void AddApplicationStatesToRemoveTestAddingFromArray() { StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters(); ApplicationState[] states = new ApplicationState[2]; states[0] = ApplicationState.Ready; states[1] = ApplicationState.Stopped; maintanenceParameters.AddApplicationStatesToRemove(states); Assert.AreEqual(2, maintanenceParameters.ApplicationStatesToRemove.Length); Assert.AreEqual(ApplicationState.Ready, maintanenceParameters.ApplicationStatesToRemove[0]); Assert.AreEqual(ApplicationState.Stopped, maintanenceParameters.ApplicationStatesToRemove[1]); }
public void PerformMaintenanceTestMultipleParameters() { Maintenance maintenance = new Maintenance(); StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters(); maintenanceParameters.AddApplicationStateToRemove(ApplicationState.AwaitingManifest); maintenanceParameters.ExecutorPingTimeCutOff = new TimeSpan(20, 0, 0); PrepareComplexStorageForMaintenanceTests(); maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters); Assert.AreEqual(2, m_managerStorage.GetExecutors().Length); Assert.AreEqual(3, m_managerStorage.GetApplications().Length); }
/// <summary> /// Perform various maintenance actions as defined in the maintenance parameters. /// </summary> /// <param name="storage"></param> /// <param name="maintenanceParameters"></param> public void PerformMaintenance(IManagerStorage storage, StorageMaintenanceParameters maintenanceParameters) { RemoveApplications(storage, maintenanceParameters.ApplicationStatesToRemove); if (maintenanceParameters.RemoveAllApplications) { RemoveAllApplications(storage); } if (maintenanceParameters.RemoveAllExecutors) { RemoveAllExecutors(storage); } if (maintenanceParameters.ApplicationTimeCreatedCutOffSet) { RemoveApplications(storage, maintenanceParameters.ApplicationTimeCreatedCutOff); } if (maintenanceParameters.ExecutorPingTimeCutOffSet) { RemoveExecutors(storage, maintenanceParameters.ExecutorPingTimeCutOff); } if (maintenanceParameters.ApplicationTimeCompletedCutOffSet) { DateTime timeCompletedCutOff = DateTime.Now.Subtract(maintenanceParameters.ApplicationTimeCompletedCutOff); ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { if (application.TimeCompletedSet && application.TimeCompleted < timeCompletedCutOff) { storage.DeleteApplication(application); } } } }
public void PerformMaintenanceTestRemoveExecutorsByPingTime() { Maintenance maintenance = new Maintenance(); StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters(); maintenanceParameters.ExecutorPingTimeCutOff = new TimeSpan(20, 0, 0); PrepareComplexStorageForMaintenanceTests(); maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters); Assert.AreEqual(2, m_managerStorage.GetExecutors().Length); Assert.AreEqual(5, m_managerStorage.GetApplications().Length); }
public void PerformMaintenanceTestRemoveApplicationsByTimeCompleted() { Maintenance maintenance = new Maintenance(); StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters(); maintenanceParameters.ApplicationTimeCompletedCutOff = new TimeSpan(20, 0, 0); PrepareComplexStorageForMaintenanceTests(); maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters); Assert.AreEqual(4, m_managerStorage.GetExecutors().Length); // we should have left the one that didn't have the time completed set // and 2 more that were not in the cut-off range Assert.AreEqual(3, m_managerStorage.GetApplications().Length); }
public void PerformMaintenanceTestRemoveApplicationByState() { Maintenance maintenance = new Maintenance(); StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters(); maintenanceParameters.AddApplicationStateToRemove(ApplicationState.AwaitingManifest); maintenanceParameters.AddApplicationStateToRemove(ApplicationState.Ready); PrepareComplexStorageForMaintenanceTests(); maintenance.PerformMaintenance(m_managerStorage, maintenanceParameters); Assert.AreEqual(4, m_managerStorage.GetExecutors().Length); Assert.AreEqual(2, m_managerStorage.GetApplications().Length); }
/// <summary> /// convert the controls options into the StorageMaintenanceParameters object /// </summary> /// <returns></returns> private StorageMaintenanceParameters GetStorageMaintenanceParameters() { StorageMaintenanceParameters result = new StorageMaintenanceParameters(); // application level options result.RemoveAllApplications = chkRemoveAllApplications.Checked; if (chkRemoveApplicationsByState.Checked) { IEnumerator enumerator = lstApplicationStatesToRemove.SelectedItems.GetEnumerator(); while (enumerator.MoveNext()) { result.AddApplicationStateToRemove((ApplicationState)enumerator.Current); } } if (chkRemoveApplicationsByTimeCreated.Checked) { result.ApplicationTimeCreatedCutOff = new TimeSpan(0, Convert.ToInt32(numTimeApplicationCreatedCutOffInMinutes.Value), 0); } if (chkRemoveApplicationsByTimeCompleted.Checked) { result.ApplicationTimeCompletedCutOff = new TimeSpan(0, Convert.ToInt32(numTimeApplicationCompletedCutOffInMinutes.Value), 0); } // executor level options result.RemoveAllExecutors = chkRemoveAllExecutors.Checked; if (chkRemoveExecutorsByTimePinged.Checked) { result.ExecutorPingTimeCutOff = new TimeSpan(0, Convert.ToInt32(numTimeExecutorPingedCutOffInMinutes.Value), 0); } return result; }
private void btnPerformMaintenance_Click(object sender, EventArgs e) { m_maintenanceParameters = GetStorageMaintenanceParameters(); m_success = false; m_maintenanceThread = new Thread(new ThreadStart(MaintenanceWorkerThread)); m_maintenanceThread.Start(); //wait a bit to see if it is done already and if so no longer display the wait dialog. m_maintenanceThread.Join(1000); if (m_maintenanceThread.ThreadState != System.Threading.ThreadState.Stopped) { // put up the display dialog m_pleaseWait = new PleaseWait(); if (m_pleaseWait.ShowDialog() != DialogResult.OK) { m_maintenanceThread.Join(1000); m_maintenanceThread.Abort(); } } m_maintenanceThread = null; StringBuilder message = new StringBuilder(); if (m_success) { message.Append("Maintenance task completed."); } else { message.Append("Maintenance task aborted."); if (m_errorMessage != null) { message.AppendFormat(" Error message: {0}", m_errorMessage); } } MessageBox.Show(message.ToString()); }
public void Admon_PerformStorageMaintenanceTestWithParameters() { SetupApplicationsGroupsAndUsers(Permission.ManageAllApps); SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5)); _managerStorage.AddApplication(new ApplicationStorageView("username1")); _managerStorage.AddExecutor(new ExecutorStorageView(true, true, DateTime.Now, "test", 1, "test", 1, 1, 1, 1)); StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters(); maintenanceParameters.RemoveAllExecutors = true; maintenanceParameters.RemoveAllApplications = true; // just to keep things honest make sure there is something there Assert.AreNotEqual(0, _managerStorage.GetExecutors().Length); Assert.AreNotEqual(0, _managerStorage.GetApplications().Length); Admon_PerformStorageMaintenance(sc, maintenanceParameters); Assert.AreEqual(0, _managerStorage.GetExecutors().Length); Assert.AreEqual(0, _managerStorage.GetApplications().Length); }
public void Admon_PerformStorageMaintenanceTestNotEnoughPermissions() { SetupApplicationsGroupsAndUsers(Permission.ManageOwnApp); SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5)); StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters(); try { Admon_PerformStorageMaintenance(sc, maintenanceParameters); } catch (AuthorizationException) { Assert.IsTrue(true); return; } Assert.IsFalse(true, "The authorization should fail"); }
public void Admon_PerformStorageMaintenanceTestNoAuthentication() { SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5)); StorageMaintenanceParameters maintenanceParameters = new StorageMaintenanceParameters(); try { Admon_PerformStorageMaintenance(sc, maintenanceParameters); } catch (AuthenticationException) { Assert.IsTrue(true); return; } Assert.IsFalse(true, "The authentication should fail"); }
public void ApplicationTimeCreatedCutOffSetTestSettingIt() { StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters(); Assert.IsFalse(maintanenceParameters.ApplicationTimeCreatedCutOffSet); maintanenceParameters.ApplicationTimeCreatedCutOff = new TimeSpan(1, 0, 0); Assert.IsTrue(maintanenceParameters.ApplicationTimeCreatedCutOffSet); }
public void Admon_PerformStorageMaintenance(SecurityCredentials sc, StorageMaintenanceParameters maintenanceParameters) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ManageAllApps); logger.Debug(String.Format("Performing maintenance with parameters {0}.", maintenanceParameters)); Maintenance maintenance = new Maintenance(); maintenance.PerformMaintenance(ManagerStorageFactory.ManagerStorage(), maintenanceParameters); }
public void ExecutorPingTimeCutOffSetTestSettingIt() { StorageMaintenanceParameters maintanenceParameters = new StorageMaintenanceParameters(); Assert.IsFalse(maintanenceParameters.ExecutorPingTimeCutOffSet); maintanenceParameters.ExecutorPingTimeCutOff = new TimeSpan(1, 0, 0); Assert.IsTrue(maintanenceParameters.ExecutorPingTimeCutOffSet); }