public void IntegrationIsStoppedWhenInsufficientSpace() { // Initialise the file system var fileSystem = mocks.DynamicMock <IFileSystem>(); SetupResult.For(fileSystem.GetFreeDiskSpace("c:\\")) .Return(102400); // Initialise the server var server = mocks.DynamicMock <ICruiseServer>(); SetupResult.For(server.RetrieveService(typeof(IFileSystem))) .Return(fileSystem); server.IntegrationStarted += null; LastCall.IgnoreArguments(); var eventRaiser = LastCall.GetEventRaiser(); // Initialise the extension var extension = new DiskSpaceMonitorExtension(); var configuration = new ExtensionConfiguration(); configuration.Items = new XmlElement[] { CreateSizeElement("Mb", 1, "C:\\") }; mocks.ReplayAll(); // Run the actual test extension.Initialise(server, configuration); var args = new IntegrationStartedEventArgs(null, "Project 1"); eventRaiser.Raise(null, args); Assert.AreEqual(IntegrationStartedEventArgs.EventResult.Cancel, args.Result); }
public void IntegrationIsStoppedWhenInsufficientSpace() { // Initialise the file system var fileSystem = mocks.Create <IFileSystem>().Object; Mock.Get(fileSystem) .Setup(_fileSystem => _fileSystem.GetFreeDiskSpace("c:\\")) .Returns(102400); // Initialise the server var server = mocks.Create <ICruiseServer>().Object; Mock.Get(server) .Setup(_server => _server.RetrieveService(typeof(IFileSystem))) .Returns(fileSystem); // Initialise the extension var extension = new DiskSpaceMonitorExtension(); var configuration = new ExtensionConfiguration(); configuration.Items = new XmlElement[] { CreateSizeElement("Mb", 1, "C:\\") }; // Run the actual test extension.Initialise(server, configuration); var args = new IntegrationStartedEventArgs(null, "Project 1"); Mock.Get(server).Raise(_server => _server.IntegrationStarted += null, args); Assert.AreEqual(IntegrationStartedEventArgs.EventResult.Cancel, args.Result); }
public void IntegrationStartAllowedAtTopOfQueue() { var extension = new IntegrationRequestThrottleExtension(); var serverMock = this.mocks.StrictMock <ICruiseServer>(); var config = new ExtensionConfiguration(); var completeRaiser = Expect .Call(() => serverMock.IntegrationCompleted += null) .IgnoreArguments() .GetEventRaiser(); var startRaiser = Expect .Call(() => serverMock.IntegrationStarted += null) .IgnoreArguments() .GetEventRaiser(); var eventArgs = new IntegrationStartedEventArgs(null, "TestProject"); this.mocks.ReplayAll(); extension.Initialise(serverMock, config); extension.NumberOfRequestsAllowed = 1; startRaiser.Raise(serverMock, new IntegrationStartedEventArgs(null, "First")); startRaiser.Raise(serverMock, eventArgs); startRaiser.Raise(serverMock, new IntegrationStartedEventArgs(null, "Third")); completeRaiser.Raise( serverMock, new IntegrationCompletedEventArgs(null, "First", IntegrationStatus.Success)); startRaiser.Raise(serverMock, eventArgs); this.mocks.VerifyAll(); Assert.AreEqual(IntegrationStartedEventArgs.EventResult.Continue, eventArgs.Result); }
/// <summary> /// Fires the IntegrationStarted event. /// </summary> /// <param name="request">The integration request.</param> /// <param name="projectName"></param> protected virtual IntegrationStartedEventArgs.EventResult FireIntegrationStarted(IntegrationRequest request, string projectName) { IntegrationStartedEventArgs.EventResult result = IntegrationStartedEventArgs.EventResult.Continue; if (IntegrationStarted != null) { IntegrationStartedEventArgs args = new IntegrationStartedEventArgs(request, projectName); IntegrationStarted(this, args); result = args.Result; } return(result); }
/// <summary> /// Handles the IntegrationStarted event of the server control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ThoughtWorks.CruiseControl.Remote.Events.IntegrationStartedEventArgs"/> instance containing the event data.</param> private void server_IntegrationStarted(object sender, IntegrationStartedEventArgs e) { Log.Debug(string.Format( CultureInfo.CurrentCulture, "Checking if '{0}' can integrate", e.ProjectName)); int numberOfRequests = 0; string[] currentRequests = new string[0]; lock (updateLock) { if (!requests.Contains(e.ProjectName)) { requests.Add(e.ProjectName); } numberOfRequests = requests.Count; currentRequests = requests.ToArray(); } if (numberOfRequests <= this.NumberOfRequestsAllowed) { Log.Debug(string.Format(CultureInfo.CurrentCulture, "'{0}' can integrate", e.ProjectName)); e.Result = IntegrationStartedEventArgs.EventResult.Continue; } else { Log.Debug(string.Format( CultureInfo.CurrentCulture, "'{0}' is delayed - number of requests ({1}) has been exceeded ({2})", e.ProjectName, this.NumberOfRequestsAllowed, numberOfRequests)); bool isAllowed = false; for (int loop = 0; loop < this.NumberOfRequestsAllowed; loop++) { if (currentRequests[loop] == e.ProjectName) { isAllowed = true; break; } } if (isAllowed) { e.Result = IntegrationStartedEventArgs.EventResult.Continue; } else { e.Result = IntegrationStartedEventArgs.EventResult.Delay; } } }
public void IntegrationStartIsAllowedWhenWithinLimit() { var extension = new IntegrationRequestThrottleExtension(); var serverMock = this.mocks.Create <ICruiseServer>(MockBehavior.Strict).Object; var config = new ExtensionConfiguration(); Mock.Get(serverMock).SetupAdd(_serverMock => _serverMock.IntegrationCompleted += It.IsAny <EventHandler <IntegrationCompletedEventArgs> >()).Verifiable(); Mock.Get(serverMock).SetupAdd(_serverMock => _serverMock.IntegrationStarted += It.IsAny <EventHandler <IntegrationStartedEventArgs> >()).Verifiable(); var eventArgs = new IntegrationStartedEventArgs(null, "TestProject"); extension.Initialise(serverMock, config); Mock.Get(serverMock).Raise(_serverMock => _serverMock.IntegrationStarted += null, eventArgs); mocks.VerifyAll(); Assert.AreEqual(IntegrationStartedEventArgs.EventResult.Continue, eventArgs.Result); }
public void IntegrationStartIsAllowedWhenWithinLimit() { var extension = new IntegrationRequestThrottleExtension(); var serverMock = this.mocks.StrictMock <ICruiseServer>(); var config = new ExtensionConfiguration(); Expect.Call(() => serverMock.IntegrationCompleted += null).IgnoreArguments(); var startRaiser = Expect .Call(() => serverMock.IntegrationStarted += null) .IgnoreArguments() .GetEventRaiser(); var eventArgs = new IntegrationStartedEventArgs(null, "TestProject"); this.mocks.ReplayAll(); extension.Initialise(serverMock, config); startRaiser.Raise(serverMock, eventArgs); this.mocks.VerifyAll(); Assert.AreEqual(IntegrationStartedEventArgs.EventResult.Continue, eventArgs.Result); }