public IntegrationQueueTreeNodeTag(IntegrationQueueTreeNodeAdaptor adaptor, QueueSnapshot queueSnapshot, QueuedRequestSnapshot queuedRequestSnapshot, int queueIndex) { this.Adaptor = adaptor; this.QueueSnapshot = queueSnapshot; this.QueuedRequestSnapshot = queuedRequestSnapshot; this.QueueIndex = queueIndex; }
public void NameReturnsQueueNameFromSnapshot() { var client = mocks.DynamicMock<CruiseServerClientBase>(); var server = InitialiseServer(); var status = new QueueSnapshot { QueueName = "Test BuildQueue" }; var queue = new BuildQueue(client, server, status); mocks.ReplayAll(); Assert.AreEqual(status.QueueName, queue.Name); }
public void ServerReturnsUnderlyingServer() { var client = mocks.DynamicMock<CruiseServerClientBase>(); var server = InitialiseServer(); var status = new QueueSnapshot(); var queue = new BuildQueue(client, server, status); mocks.ReplayAll(); Assert.AreSame(server, queue.Server); }
private CruiseServerSnapshot CreateEmptyQueuesSnapshot() { QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot(); QueueSnapshot queueSnapshot1 = new QueueSnapshot("Queue1"); queueSetSnapshot.Queues.Add(queueSnapshot1); QueueSnapshot queueSnapshot2 = new QueueSnapshot("Queue2"); queueSetSnapshot.Queues.Add(queueSnapshot2); return new CruiseServerSnapshot(null, queueSetSnapshot); }
private static void WriteQueueSnapshot(XmlWriter xmlWriter, QueueSnapshot queue) { xmlWriter.WriteStartElement("Queue"); xmlWriter.WriteAttributeString("name", queue.QueueName); foreach (QueuedRequestSnapshot request in queue.Requests) { WriteQueuedRequestSnapshot(xmlWriter, request); } xmlWriter.WriteEndElement(); }
/// <summary> /// Checks if a snapshot has changed. /// </summary> /// <param name="queueSetSnapshotToCompare"></param> /// <returns></returns> public bool IsQueueSetSnapshotChanged(QueueSetSnapshot queueSetSnapshotToCompare) { if (queueSetSnapshotToCompare == null) { if (queueSetSnapshot == null) { return(false); } else { return(true); } } if (queueSetSnapshot == null) { return(true); } if (queueSetSnapshotToCompare.Queues.Count != queueSetSnapshot.Queues.Count) { return(true); } for (int queueIndex = 0; queueIndex < queueSetSnapshot.Queues.Count; queueIndex++) { QueueSnapshot queueSnapshot = queueSetSnapshot.Queues[queueIndex]; QueueSnapshot queueSnapshotToCompare = queueSetSnapshotToCompare.Queues[queueIndex]; if (queueSnapshotToCompare.QueueName != queueSnapshot.QueueName) { return(true); } if (queueSnapshotToCompare.Requests.Count != queueSnapshot.Requests.Count) { return(true); } for (int requestIndex = 0; requestIndex < queueSnapshot.Requests.Count; requestIndex++) { QueuedRequestSnapshot request = queueSnapshot.Requests[requestIndex]; QueuedRequestSnapshot requestToCompare = queueSnapshotToCompare.Requests[requestIndex]; if (requestToCompare.ProjectName != request.ProjectName) { return(true); } if (requestToCompare.Activity != request.Activity) { return(true); } } } return(false); }
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); Assert.AreEqual(expected, actual); }
private static QueueSnapshot BuildQueueSnapshot(IIntegrationQueue queue) { QueueSnapshot queueSnapshot = new QueueSnapshot(queue.Name); for (int index = 0; index < queue.Count; index++) { IIntegrationQueueItem integrationQueueItem = (IIntegrationQueueItem)queue[index]; // The first request in the queue shows it's real activity of CheckingModifications or Building // Everything else is in a pending state. ProjectActivity projectActivity = ProjectActivity.Pending; if (index == 0) { projectActivity = integrationQueueItem.Project.CurrentActivity; } QueuedRequestSnapshot queuedRequestSnapshot = new QueuedRequestSnapshot( integrationQueueItem.Project.Name, projectActivity, integrationQueueItem.IntegrationRequest.RequestTime); queueSnapshot.Requests.Add(queuedRequestSnapshot); } return queueSnapshot; }
/// <summary> /// Parse the queue information. /// </summary> /// <param name="document"></param> /// <param name="snapshot"></param> private void ParseQueues(XmlDocument document, CruiseServerSnapshot snapshot) { foreach (XmlElement queueSnapshotEl in document.SelectNodes("/CruiseControl/Queues/Queue")) { // Retrieve the queue details var queueSnapshot = new QueueSnapshot { QueueName = RetrieveAttributeValue(queueSnapshotEl, "name", string.Empty) }; snapshot.QueueSetSnapshot.Queues.Add(queueSnapshot); // Retrieve the requests foreach (XmlElement requestEl in queueSnapshotEl.SelectNodes("Request")) { var request = new QueuedRequestSnapshot { Activity = new ProjectActivity(RetrieveAttributeValue(requestEl, "activity", "Unknown")), ProjectName = RetrieveAttributeValue(requestEl, "projectName", string.Empty) }; queueSnapshot.Requests.Add(request); } } }
private QueueSetSnapshot ConvertDashboardQueues(DashboardQueue[] dashboardQueues) { QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot(); if (dashboardQueues != null) { foreach (DashboardQueue dashboardQueue in dashboardQueues) { QueueSnapshot queueSnapshot = new QueueSnapshot(dashboardQueue.Name); if (dashboardQueue.Requests != null) { foreach (DashboardQueuedRequest dashboardQueuedRequest in dashboardQueue.Requests) { QueuedRequestSnapshot queuedRequestSnapshot = new QueuedRequestSnapshot( dashboardQueuedRequest.ProjectName, new ProjectActivity(dashboardQueuedRequest.Activity)); queueSnapshot.Requests.Add(queuedRequestSnapshot); } } queueSetSnapshot.Queues.Add(queueSnapshot); } } return queueSetSnapshot; }
private CruiseServerSnapshot BuildCruiseServerSnapshot() { List<ProjectStatus> projectStatus = new List<ProjectStatus>(); CheckProjectStatusCache(); _projectListCache.ForEach(project => { lock (_statusCacheLock) { if (!_projectStatusCache.ContainsKey(project.ProjectName)) { _projectStatusCache.Add(project.ProjectName, _manager.GetProjectStatus(project.ProjectName)); _projectStatusLastUpdate.Add(project.ProjectName, DateTime.Now); } if (!_lastQueuedBuildsCheck.ContainsKey(project.ProjectName) || _lastQueuedBuildsCheck[project.ProjectName].AddSeconds(CHECK_QUEUED_BUILDS_TIMEOUT_SECONDS) < DateTime.Now) { if (!IsBuildDefinitionTracked(project.ProjectName)) { if (AttachToNextBuild(project.ProjectName)) { if (!_lastQueuedBuildsCheck.ContainsKey(project.ProjectName)) { _lastQueuedBuildsCheck.Add(project.ProjectName, DateTime.Now); } else { _lastQueuedBuildsCheck[project.ProjectName] = DateTime.Now; } } } } } projectStatus.Add(_projectStatusCache[project.ProjectName]); }); CheckBuildQueueCache(); lock (_statusCacheLock) { if (_buildQueue == null) { _buildQueue = new QueueSetSnapshot(); } if (_buildQueue.Queues.Count <= 0) { IBuildController[] controllers = _manager.GetBuildControllers(); for (int i = 0; i < controllers.Length; i++) { IQueuedBuild[] builds = _manager.GetBuildQueue(controllers[i]); QueueSnapshot queue = new QueueSnapshot(controllers[i].Name); _buildQueue.Queues.Add(queue); if (builds.Length > 0) { for (int j = 0; j < builds.Length; j++) { queue.Requests.Add(new QueuedRequestSnapshot(builds[j].BuildDefinition.Name, TFSServerManager.GetProjectActivity(builds[j].Status), builds[j].QueueTime)); } } } _lastBuildQueueCheck = DateTime.Now; } } return new CruiseServerSnapshot(projectStatus.ToArray(), _buildQueue); }
public void QueueNameGetSetTest() { QueueSnapshot activity = new QueueSnapshot(); activity.QueueName = "testing"; Assert.AreEqual("testing", activity.QueueName); }
public void UpdateFiresPropertyChangedWhenMessageIsRemoved() { mocks = new MockRepository(); var client = mocks.DynamicMock<CruiseServerClientBase>(); var server = InitialiseServer(); var status = new QueueSnapshot { Requests = { new QueuedRequestSnapshot{ ProjectName = "Project 1" }, new QueuedRequestSnapshot{ ProjectName = "Project 2" } } }; var queue = new BuildQueue(client, server, status); mocks.ReplayAll(); var eventFired = false; queue.Update(status); var newStatus = new QueueSnapshot { Requests = { new QueuedRequestSnapshot{ ProjectName = "Project 2" } } }; queue.BuildQueueRequestRemoved += (o, e) => { eventFired = true; }; queue.Update(newStatus); Assert.IsTrue(eventFired, "BuildQueueRequestRemoved for Requests change not fired"); }
public void RequestsReturnsRequestsFromStatus() { var client = mocks.DynamicMock<CruiseServerClientBase>(); var server = InitialiseServer(); var status = new QueueSnapshot { Requests = { new QueuedRequestSnapshot{ ProjectName = "Project 1" } } }; var queue = new BuildQueue(client, server, status); mocks.ReplayAll(); }
public IntegrationQueueTreeNodeTag(IntegrationQueueTreeNodeAdaptor adaptor, QueueSnapshot queueSnapshot) : this(adaptor, queueSnapshot, null, -1) { }
/// <summary> /// Wraps the specified queue status. /// </summary> /// <param name="owningClient">The owning client.</param> /// <param name="queueStatus">The queue status.</param> /// <param name="connection">The connection.</param> /// <returns> /// The new <see cref="CCProject"/>. /// </returns> internal static CCQueue Wrap(CruiseServerClientBase owningClient, QueueSnapshot queueStatus, CCConnection connection) { var queue = new CCQueue(owningClient, queueStatus.QueueName, queueStatus.Requests) { Connection = connection }; return queue; }
public void UpdateValidatesArguments() { var client = mocks.DynamicMock<CruiseServerClientBase>(); var server = InitialiseServer(); var status = new QueueSnapshot { QueueName = "Testing" }; var queue = new BuildQueue(client, server, status); mocks.ReplayAll(); try { queue.Update(null); Assert.Fail("ArgumentNullException was expected"); } catch (ArgumentNullException) { } }