/// <summary> /// Attempt to retrieve a snapshot from the remote server. /// </summary> private void RetrieveSnapshot() { // Retrieve the snapshot ServerUpdateArgs args; try { CruiseServerSnapshot snapshot = null; try { snapshot = client.GetCruiseServerSnapshot(); } catch (NotImplementedException) { // This is an older style server, try fudging the snapshot snapshot = new CruiseServerSnapshot { ProjectStatuses = client.GetProjectStatus() }; } args = new ServerUpdateArgs(snapshot); } catch (Exception error) { args = new ServerUpdateArgs(error); } // Fire the update if (Update != null) { Update(this, args); } }
public void ReturnsCorrectProjectDetailsFromProjectsAndQueuesXml() { DashboardXmlParser parser = new DashboardXmlParser(); CruiseServerSnapshot snapshot = parser.ExtractAsCruiseServerSnapshot(CRUISE_SERVER_XML); Assert.IsNotNull(snapshot); Assert.AreEqual(2, snapshot.ProjectStatuses.Length); AssertProjectsSerializedCorrectly(snapshot); Assert.AreEqual(2, snapshot.QueueSetSnapshot.Queues.Count); QueueSnapshot queueSnapshot1 = snapshot.QueueSetSnapshot.Queues[0]; Assert.AreEqual("Queue1", queueSnapshot1.QueueName); Assert.AreEqual("projectName", queueSnapshot1.Requests[0].ProjectName); Assert.AreEqual(ProjectActivity.CheckingModifications, queueSnapshot1.Requests[0].Activity); Assert.AreEqual("SVNTest", queueSnapshot1.Requests[1].ProjectName); Assert.AreEqual(ProjectActivity.Pending, queueSnapshot1.Requests[1].Activity); QueueSnapshot queueSnapshot2 = snapshot.QueueSetSnapshot.Queues[1]; Assert.AreEqual("Queue2", queueSnapshot2.QueueName); Assert.AreEqual("Missing", queueSnapshot2.Requests[0].ProjectName); Assert.AreEqual(ProjectActivity.Building, queueSnapshot2.Requests[0].Activity); }
private void AssertQueueSetChanged(bool result, QueueSetSnapshot firstSnapshot, QueueSetSnapshot secondSnapshot) { CruiseServerSnapshot cruiseServerSnapshot1 = new CruiseServerSnapshot(null, firstSnapshot); CruiseServerSnapshot cruiseServerSnapshot2 = new CruiseServerSnapshot(null, secondSnapshot); Assert.AreEqual(result, cruiseServerSnapshot1.IsQueueSetSnapshotChanged(cruiseServerSnapshot2.QueueSetSnapshot)); }
public TestWatcher() { Snapshot = new CruiseServerSnapshot { ProjectStatuses = new ProjectStatus[] { new ProjectStatus { Name = "Project1", BuildStatus = IntegrationStatus.Success }, new ProjectStatus { Name = "Project2", BuildStatus = IntegrationStatus.Success } }, QueueSetSnapshot = new QueueSetSnapshot { Queues = { new QueueSnapshot { QueueName = "Queue1" } } } }; }
private static void DisplayServerStatus(CruiseServerClientBase client, bool isQuiet) { try { if (!isQuiet) { WriteLine("Retrieving snapshot from " + client.TargetServer, ConsoleColor.Gray); } CruiseServerSnapshot snapShot = client.GetCruiseServerSnapshot(); if (xml) { XmlSerializer serializer = new XmlSerializer(typeof(CruiseServerSnapshot)); Stream console = Console.OpenStandardOutput(); serializer.Serialize(console, snapShot); console.Close(); } else { foreach (ProjectStatus prj in snapShot.ProjectStatuses) { DisplayProject(prj); } } } catch (Exception error) { WriteError("ERROR: Unable to retrieve server details", error); } }
public void WhenOneCruiseServerSnapshotIsReturnedThisIsContainedInTheReturnedXml() { CruiseServerSnapshot cruiseServerSnapshot = CreateCruiseServerSnapshot(); CruiseServerSnapshotOnServer cruiseServerSnapshotOnServer = new CruiseServerSnapshotOnServer(cruiseServerSnapshot, null); mockFarmService.Setup(service => service.GetCruiseServerSnapshotListAndExceptions(null)). Returns(new CruiseServerSnapshotListAndExceptions(new CruiseServerSnapshotOnServer[] { cruiseServerSnapshotOnServer }, new CruiseServerException[0])). Verifiable(); XmlFragmentResponse response = (XmlFragmentResponse)reportAction.Execute(null); string xml = response.ResponseFragment; // cannot just compare the xml string, since we correctly expect the string to vary based on the // timezone in which this code is executing XmlDocument doc = XPathAssert.LoadAsDocument(xml); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@name", "HelloWorld"); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@activity", "Sleeping"); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@lastBuildStatus", "Success"); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@lastBuildLabel", "build_7"); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@lastBuildTime", LastBuildTime); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@nextBuildTime", NextBuildTime); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@webUrl", "http://blah"); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@category", "category"); XPathAssert.Matches(doc, "/CruiseControl/Projects/Project/@serverName", Environment.MachineName); XPathAssert.Matches(doc, "/CruiseControl/Queues/Queue/@name", "Queue1"); XPathAssert.Matches(doc, "/CruiseControl/Queues/Queue/Request/@projectName", "HelloWorld"); XPathAssert.Matches(doc, "/CruiseControl/Queues/Queue/Request/@activity", "CheckingModifications"); mockFarmService.Verify(); }
/// <summary> /// Polls this server for the latest cruise control server project statuses and queues. /// </summary> public void Poll() { try { CruiseServerSnapshot cruiseServerSnapshot = cruiseServerManager.GetCruiseServerSnapshot(); if ((lastCruiseServerSnapshot == null) || (cruiseServerSnapshot == null) || lastCruiseServerSnapshot.IsQueueSetSnapshotChanged(cruiseServerSnapshot.QueueSetSnapshot)) { OnQueueChanged(new MonitorServerQueueChangedEventArgs(this)); } lastCruiseServerSnapshot = cruiseServerSnapshot; // Find any changes DetectAnyChanges(cruiseServerSnapshot); } catch (Exception ex) { Trace.WriteLine("ServerMonitorPoll Exception: " + ex); lastCruiseServerSnapshot = null; connectException = ex; OnQueueChanged(new MonitorServerQueueChangedEventArgs(this)); } OnPolled(new MonitorServerPolledEventArgs(this)); }
public void IfTheQueueTimeStampHasChangedAQueueChangedEventIsFired() { Assert.AreEqual(0, queueChangedCount); CruiseServerSnapshot snapshot = CreateCruiseServerSnapshot(); mockServerManager.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(snapshot).Verifiable(); monitor.Poll(); Assert.AreEqual(1, queueChangedCount); mockServerManager.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(snapshot).Verifiable(); monitor.Poll(); Assert.AreEqual(1, queueChangedCount); mockServerManager.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(CreateCruiseServerSnapshot2()).Verifiable(); monitor.Poll(); Assert.AreEqual(2, queueChangedCount); mockServerManager.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(CreateCruiseServerSnapshot()).Verifiable(); monitor.Poll(); Assert.AreEqual(3, queueChangedCount); }
public void IfTheQueueTimeStampHasChangedAQueueChangedEventIsFired() { Assert.AreEqual(0, queueChangedCount); CruiseServerSnapshot snapshot = CreateCruiseServerSnapshot(); mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot); monitor.Poll(); Assert.AreEqual(1, queueChangedCount); mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot); monitor.Poll(); Assert.AreEqual(1, queueChangedCount); mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", CreateCruiseServerSnapshot2()); monitor.Poll(); Assert.AreEqual(2, queueChangedCount); mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", CreateCruiseServerSnapshot()); monitor.Poll(); Assert.AreEqual(3, queueChangedCount); }
private CruiseServerSnapshot CreateCruiseServerSnapshot2() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); snapshot.QueueSetSnapshot.Queues.Add(new QueueSnapshot("Test")); snapshot.QueueSetSnapshot.Queues[0].Requests.Add(new QueuedRequestSnapshot("Project", ProjectActivity.CheckingModifications)); return(snapshot); }
public CruiseServerSnapshot GetCruiseServerSnapshot() { if (cachedSnapshot == null) { cachedSnapshot = wrappedManager.GetCruiseServerSnapshot(); } return(cachedSnapshot); }
private void DisplayIntegrationQueueInTreeViewNode() { serverTreeNode.Nodes.Clear(); CruiseServerSnapshot cruiseServerSnapshot = serverMonitor.CruiseServerSnapshot; if (cruiseServerSnapshot == null) { return; } QueueSetSnapshot queueSetSnapshot = serverMonitor.CruiseServerSnapshot.QueueSetSnapshot; if (queueSetSnapshot != null && queueSetSnapshot.Queues != null && queueSetSnapshot.Queues.Count > 0) { foreach (QueueSnapshot queue in queueSetSnapshot.Queues) { string queueNodeTitle = queue.QueueName; int queueImageIndex = IntegrationQueueNodeType.QueueEmpty.ImageIndex; if (!queue.IsEmpty) { queueNodeTitle = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} ({1})", queue.QueueName, queue.Requests.Count); queueImageIndex = IntegrationQueueNodeType.QueuePopulated.ImageIndex; } TreeNode queueNode = new TreeNode(queueNodeTitle, queueImageIndex, queueImageIndex); queueNode.Tag = new IntegrationQueueTreeNodeTag(this, queue); serverTreeNode.Nodes.Add(queueNode); for (int index = 0; index < queue.Requests.Count; index++) { QueuedRequestSnapshot queuedRequest = queue.Requests[index]; TreeNode queuedItemNode = new TreeNode(queuedRequest.ProjectName); queuedItemNode.Tag = new IntegrationQueueTreeNodeTag(this, queue, queuedRequest, index); int requestImageIndex = IntegrationQueueNodeType.PendingInQueue.ImageIndex; if (queuedRequest.Activity == ProjectActivity.CheckingModifications) { requestImageIndex = IntegrationQueueNodeType.CheckingModifications.ImageIndex; } else if (queuedRequest.Activity == ProjectActivity.Building) { requestImageIndex = IntegrationQueueNodeType.Building.ImageIndex; } queuedItemNode.ImageIndex = queuedItemNode.SelectedImageIndex = requestImageIndex; queueNode.Nodes.Add(queuedItemNode); } } } serverTreeNode.Expand(); QueueTreeView queueTreeView = serverTreeNode.TreeView as QueueTreeView; if (queueTreeView != null) { queueTreeView.RestoreExpandedNodes(serverTreeNode); } }
public void ShouldReturnNullIfNamedProjectNotFound() { ProjectStatus[] projectStatuses = new ProjectStatus[1]; projectStatuses[0] = new ProjectStatus("no names", IntegrationStatus.Failure, DateTime.Now); CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, null); Assert.IsNull(cruiseServerSnapshot.GetProjectStatus("this doesn't match")); }
public void RetrieveSnapshotFromManager() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); Mock.Get(serverClient).Setup(_serverClient => _serverClient.GetCruiseServerSnapshot()).Returns(snapshot); CruiseServerSnapshot actual = manager.GetCruiseServerSnapshot(); Assert.AreSame(snapshot, actual); }
public void CanHandleTimeouts() { Mock.Get(serverClient).Setup(_serverClient => _serverClient.GetCruiseServerSnapshot()).Throws(new WebException("The operation has timed out")); CruiseServerSnapshot actual = manager.GetCruiseServerSnapshot(); Assert.IsNotNull(actual); // mainly want to make sure that the exception is caught, and return is not null. }
public void ShouldDelegateFirstSnapshotGet() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); wrappedManagerMock.ExpectAndReturn("GetCruiseServerSnapshot", snapshot); Assert.AreSame(snapshot, cachingManager.GetCruiseServerSnapshot()); wrappedManagerMock.Verify(); }
public void ExposesTheCruiseServerSnapshotOfTheContainedServer() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot); monitor.Poll(); Assert.AreEqual(snapshot, monitor.CruiseServerSnapshot); }
public void ExposesTheCruiseServerSnapshotOfTheContainedServer() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); mockServerManager.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(snapshot).Verifiable(); monitor.Poll(); Assert.AreEqual(snapshot, monitor.CruiseServerSnapshot); }
public void ShouldDelegateFirstSnapshotGet() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); wrappedManagerMock.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(snapshot).Verifiable(); Assert.AreSame(snapshot, cachingManager.GetCruiseServerSnapshot()); wrappedManagerMock.Verify(); }
public void RetrieveSnapshotFromManager() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); Expect.Call(serverClient.GetCruiseServerSnapshot()).Return(snapshot); mocks.ReplayAll(); CruiseServerSnapshot actual = manager.GetCruiseServerSnapshot(); Assert.AreSame(snapshot, actual); }
public void CorrectAssignmentOfConstructorArguments() { ProjectStatus[] projectStatuses = new ProjectStatus[0]; QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot(); CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, queueSetSnapshot); Assert.AreSame(projectStatuses, cruiseServerSnapshot.ProjectStatuses); Assert.AreSame(queueSetSnapshot, cruiseServerSnapshot.QueueSetSnapshot); }
public void CanHandleTimeouts() { Expect.Call(serverClient.GetCruiseServerSnapshot()).Throw(new WebException("The operation has timed out")); mocks.ReplayAll(); CruiseServerSnapshot actual = manager.GetCruiseServerSnapshot(); Assert.IsNotNull(actual); // mainly want to make sure that the exception is caught, and return is not null. }
public void RetrieveSnapshotFromManager() { var snapshot = new CruiseServerSnapshot(); Mock.Get(cruiseManagerMock).Setup(_cruiseManagerMock => _cruiseManagerMock.GetCruiseServerSnapshot()) .Returns(snapshot); CruiseServerSnapshot result = manager.GetCruiseServerSnapshot(); Assert.AreEqual(snapshot, result); }
public void ShouldFindProjectStatusBasedOnProjectName() { ProjectStatus[] projectStatuses = new ProjectStatus[2]; projectStatuses[0] = new ProjectStatus("test1", IntegrationStatus.Failure, DateTime.Now); projectStatuses[1] = new ProjectStatus("test2", IntegrationStatus.Success, DateTime.Now); CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, null); Assert.AreSame(projectStatuses[0], cruiseServerSnapshot.GetProjectStatus("test1")); Assert.AreSame(projectStatuses[1], cruiseServerSnapshot.GetProjectStatus("test2")); }
public void ReturnsCorrectProjectDetailsFromProjectsOnlyXml() { DashboardXmlParser parser = new DashboardXmlParser(); CruiseServerSnapshot snapshot = parser.ExtractAsCruiseServerSnapshot(PROJECTS_XML); Assert.IsNotNull(snapshot); Assert.AreEqual(2, snapshot.ProjectStatuses.Length); AssertProjectsSerializedCorrectly(snapshot); }
public void WhenPollIsCalledRetrievesANewCopyOfTheCruiseServerSnapshot() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot); monitor.Poll(); // deliberately called twice: should not go back to server on 2nd call Assert.AreSame(snapshot, monitor.CruiseServerSnapshot); Assert.AreSame(snapshot, monitor.CruiseServerSnapshot); }
public void WhenPollIsCalledRetrievesANewCopyOfTheCruiseServerSnapshot() { CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); mockServerManager.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(snapshot).Verifiable(); monitor.Poll(); // deliberately called twice: should not go back to server on 2nd call Assert.AreSame(snapshot, monitor.CruiseServerSnapshot); Assert.AreSame(snapshot, monitor.CruiseServerSnapshot); }
public void ToStringSerialisesAllValues() { QueueSnapshot queueSnapshot = new QueueSnapshot("queue1"); queueSnapshot.Requests.Add(new QueuedRequestSnapshot("test project", ProjectActivity.Pending)); QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot(); queueSetSnapshot.Queues.Add(queueSnapshot); ProjectStatus projectStatus = new ProjectStatus("test project", IntegrationStatus.Success, DateTime.Now); CruiseServerSnapshot snapshot = new CruiseServerSnapshot( new ProjectStatus[] { projectStatus }, queueSetSnapshot); SnapshotResponse response = new SnapshotResponse(); response.ErrorMessages.Add(new ErrorMessage("Error 1")); response.ErrorMessages.Add(new ErrorMessage("Error 2")); response.RequestIdentifier = "request"; response.Result = ResponseResult.Success; response.Timestamp = DateTime.Now; response.Snapshot = snapshot; string actual = response.ToString(); string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture, "<snapshotResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + "timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" result=\"{1}\">" + "<error>Error 1</error>" + "<error>Error 2</error>" + "<snapshot>" + "<projects>" + "<projectStatus showForceBuildButton=\"true\" showStartStopButton=\"true\" serverName=\"{6}\" status=\"Running\" buildStatus=\"Success\" name=\"test project\" " + "queuePriority=\"0\" lastBuildDate=\"{3:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\" nextBuildTime=\"{4:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" + "<activity type=\"Sleeping\" />" + "<parameters />" + "</projectStatus>" + "</projects>" + "<queueSet>" + "<queue name=\"queue1\">" + "<queueRequest projectName=\"test project\" time=\"{5:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" + "<activity type=\"Pending\" />" + "</queueRequest>" + "</queue>" + "</queueSet>" + "</snapshot>" + "</snapshotResponse>", response.RequestIdentifier, response.Result, response.Timestamp, projectStatus.LastBuildDate, projectStatus.NextBuildTime, DateTime.MinValue, Environment.MachineName); XDocument.Parse(actual).Should().BeEquivalentTo(XDocument.Parse(expected)); }
public void RetrieveSnapshotFromManager() { var snapshot = new CruiseServerSnapshot(); Expect.Call(cruiseManagerMock.GetCruiseServerSnapshot()) .IgnoreArguments() .Return(snapshot); mocks.ReplayAll(); CruiseServerSnapshot result = manager.GetCruiseServerSnapshot(); Assert.AreEqual(snapshot, result); }
public void ThePollEventIsFiredWhenPollIsInvoked() { Assert.AreEqual(0, pollCount); CruiseServerSnapshot snapshot = new CruiseServerSnapshot(); mockServerManager.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(snapshot).Verifiable(); monitor.Poll(); Assert.AreEqual(1, pollCount); mockServerManager.Setup(_manager => _manager.GetCruiseServerSnapshot()).Returns(snapshot).Verifiable(); monitor.Poll(); Assert.AreEqual(2, pollCount); }
/// <summary> /// Initialise a new <see cref="ServerUpdateArgs"/>. /// </summary> /// <param name="snapshot">The current snapshot.</param> public ServerUpdateArgs(CruiseServerSnapshot snapshot) { Snapshot = snapshot; }