public void Deserialize_NonexistingStateFile_ReturnsCloning() { var state = ProcessingState.Deserialize("ProjB"); Assert.That(state.ProjectCode, Is.EqualTo("ProjB")); Assert.That(state.SRState, Is.EqualTo(ProcessingState.SendReceiveStates.CLONING)); }
public void Deserialize_ValidStateFile_MatchesState() { var expectedState = new ProcessingState("ProjC", _env.Settings) { SRState = ProcessingState.SendReceiveStates.SYNCING, PercentComplete = 30, ElapsedTimeSeconds = 40, TimeRemainingSeconds = 50, TotalSteps = 3, CurrentStep = 2, RetryCounter = 1, UncommittedEditCounter = 0 }; expectedState.LastStateChangeTicks = 635683277459459160; // Make sure this gets set last so the value isn't UtcNow.Ticks const string json = "{\"SRState\":\"SYNCING\",\"LastStateChangeTicks\":635683277459459160," + "\"PercentComplete\":30,\"ElapsedTimeSeconds\":40,\"TimeRemainingSeconds\":50," + "\"TotalSteps\":3,\"CurrentStep\":2,\"RetryCounter\":1,\"UncommittedEditCounter\":0," + "\"ErrorMessage\":null,\"ErrorCode\":0,\"ProjectCode\":\"ProjC\"}"; Directory.CreateDirectory(_env.Settings.StateDirectory); var filename = _env.Settings.GetStateFileName("ProjC"); File.WriteAllText(filename, json); var state = ProcessingState.Deserialize("ProjC"); Assert.That(state, Is.EqualTo(expectedState)); }
public void CleanupAndRescheduleJobs_UnknownState(ProcessingState.SendReceiveStates srState) { // Setup var testName = TestContext.CurrentContext.Test.Name; var state = new ProcessingState(testName, _env.Settings) { SRState = srState }; state.Serialize(); // Execute var janitor = new Janitor(_env.Settings, _env.Logger); janitor.CleanupAndRescheduleJobs(); // Verify var queue = Queue.GetQueue(QueueNames.Synchronize); Assert.That(queue.QueuedProjects, Is.EqualTo(new[] { testName })); var newState = ProcessingState.Deserialize(testName); Assert.That(newState.SRState, Is.EqualTo(ProcessingState.SendReceiveStates.IDLE)); Assert.That(_exceptionLoggingDouble.Exceptions.Count, Is.EqualTo(1)); var report = _exceptionLoggingDouble.Exceptions[0]; Assert.That(report.OriginalException, Is.TypeOf <ProjectInUncleanStateException>()); Assert.That(report.OriginalException.Message, Is.EqualTo("QueueManager detected unknown state '42' for project 'CleanupAndRescheduleJobs_UnknownState(42)'; rescheduled")); }
public void CleanupAndRescheduleJobs_NothingToDo(ProcessingState.SendReceiveStates srState) { // Setup var state = new ProcessingState(TestContext.CurrentContext.Test.Name, _env.Settings) { SRState = srState }; state.Serialize(); // Execute var janitor = new Janitor(_env.Settings, _env.Logger); janitor.CleanupAndRescheduleJobs(); // Verify var queue = Queue.GetQueue(QueueNames.Synchronize); Assert.That(queue.IsEmpty, Is.True); var newState = ProcessingState.Deserialize(TestContext.CurrentContext.Test.Name); Assert.That(newState.SRState, Is.EqualTo(srState)); Assert.That(_exceptionLoggingDouble.Exceptions.Count, Is.EqualTo(0)); }
public void CleanupAndRescheduleJobs() { foreach (var file in Directory.EnumerateFiles(Settings.StateDirectory)) { var projectCode = Path.GetFileNameWithoutExtension(file); var state = ProcessingState.Deserialize(projectCode); switch (state.SRState) { case ProcessingState.SendReceiveStates.CLONED: case ProcessingState.SendReceiveStates.IDLE: case ProcessingState.SendReceiveStates.HOLD: case ProcessingState.SendReceiveStates.ERROR: // Nothing to do break; case ProcessingState.SendReceiveStates.CLONING: case ProcessingState.SendReceiveStates.SYNCING: RescheduleProject(projectCode, state, string.Format("QueueManager detected project '{0}' in unclean state '{1}'; rescheduled", projectCode, state.SRState)); break; default: RescheduleProject(projectCode, state, string.Format("QueueManager detected unknown state '{0}' for project '{1}'; rescheduled", state.SRState, projectCode)); break; } } }
public void Deserialize_EmptyStateFile_DoesntThrow() { const string json = ""; Directory.CreateDirectory(_env.Settings.StateDirectory); var filename = _env.Settings.GetStateFileName("ProjC"); File.WriteAllText(filename, json); Assert.DoesNotThrow(() => { var state = ProcessingState.Deserialize("ProjC"); Assert.That(state.SRState, Is.EqualTo(ProcessingState.SendReceiveStates.CLONING)); }); }
public void Serialization_Roundtrip() { var expectedState = new ProcessingState("ProjA", _env.Settings) { SRState = ProcessingState.SendReceiveStates.SYNCING, LastStateChangeTicks = DateTime.Now.Ticks, PercentComplete = 50, ElapsedTimeSeconds = 10, TimeRemainingSeconds = 20, TotalSteps = 5, CurrentStep = 1, RetryCounter = 2, UncommittedEditCounter = 0 }; expectedState.Serialize(); var state = ProcessingState.Deserialize("ProjA"); Assert.That(state, Is.EqualTo(expectedState)); }