Ejemplo n.º 1
0
 public void CompletingAnIntegrationRemovesItFromActiveRequests()
 {
     var project = new ProjectStub();
     var queue = new Queue();
     var context = new IntegrationContext(project);
     queue.AskToIntegrate(context);
     context.Complete();
     Assert.AreEqual(0, queue.GetActiveRequests().Count());
     Assert.AreEqual(0, queue.GetPendingRequests().Count());
 }
Ejemplo n.º 2
0
 public void AskToIntegrateWillTriggerProjectIfFirst()
 {
     var project = new ProjectStub();
     var queue = new Queue();
     var context = new IntegrationContext(project);
     queue.AskToIntegrate(context);
     var canIntegrate = context.Wait(TimeSpan.FromSeconds(5));
     Assert.IsTrue(canIntegrate);
     var active = queue.GetActiveRequests();
     Assert.AreEqual(1, active.Count());
     Assert.AreEqual(0, queue.GetPendingRequests().Count());
     Assert.AreSame(active.First(), context);
 }
Ejemplo n.º 3
0
 public void CompletingReleasingSubsequentItems()
 {
     var queue = new Queue();
     var project1 = new ProjectStub();
     var project2 = new ProjectStub();
     var context1 = new IntegrationContext(project1);
     var context2 = new IntegrationContext(project2);
     queue.AskToIntegrate(context1);
     queue.AskToIntegrate(context2);
     context1.Complete();
     var active = queue.GetActiveRequests();
     Assert.AreEqual(1, active.Count());
     Assert.AreEqual(0, queue.GetPendingRequests().Count());
     Assert.AreSame(context2, active.First());
 }
Ejemplo n.º 4
0
 public void AskToIntegrateWillQueueSubsequentItems()
 {
     var queue = new Queue();
     var project1 = new ProjectStub();
     var project2 = new ProjectStub();
     var context1 = new IntegrationContext(project1);
     var context2 = new IntegrationContext(project2);
     queue.AskToIntegrate(context1);
     queue.AskToIntegrate(context2);
     var active = queue.GetActiveRequests();
     var pending = queue.GetPendingRequests();
     Assert.AreEqual(1, active.Count());
     Assert.AreEqual(1, pending.Count());
     Assert.AreSame(active.First(), context1);
     Assert.AreSame(pending.First(), context2);
 }
Ejemplo n.º 5
0
 public void ValidateDetectsDuplicateChildItems()
 {
     var errorAdded = false;
     var queue1 = new Queue("Queue");
     var queue2 = new Queue("Queue");
     var queue3 = new Queue("OtherQueue");
     var server = new Server("Server", queue1, queue2, queue3);
     var validationStub = new ValidationLogStub
                              {
                                  OnAddErrorMessage = (m, a) =>
                                                          {
                                                              Assert.AreEqual(
                                                                  "Duplicate {1} name detected: '{0}'", m);
                                                              CollectionAssert.AreEqual(
                                                                  new[] { "Queue", "child" },
                                                                  a);
                                                              errorAdded = true;
                                                          }
                              };
     server.Validate(validationStub);
     Assert.IsTrue(errorAdded);
 }
Ejemplo n.º 6
0
 public void LocateMatchesChild()
 {
     var childQueue = new Queue("ChildQueue");
     var queue = new Queue("RootQueue", childQueue);
     var server = new Server("Local", queue);
     var actual = server.Locate("urn:ccnet:local:rootQueue:childQueue");
     Assert.AreSame(childQueue, actual);
 }
Ejemplo n.º 7
0
 public void ListProjectsReturnsOnlyTheProjects()
 {
     var project = new Project();
     var childQueue = new Queue();
     var parentQueue = new Queue("Test", project, childQueue);
     var projects = parentQueue.ListProjects();
     var expected = new[] { project };
     CollectionAssert.AreEqual(expected, projects);
 }
Ejemplo n.º 8
0
 public void ValidateDetectsDuplicateChildItems()
 {
     var errorAdded = false;
     var project1 = new Project("Project");
     var project2 = new Project("Project");
     var project3 = new Project("OtherProject");
     var queue = new Queue("QueueName", project1, project2, project3);
     var validationStub = new ValidationLogStub
                              {
                                  OnAddErrorMessage = (m, a) =>
                                                          {
                                                              Assert.AreEqual(
                                                                  "Duplicate {1} name detected: '{0}'", m);
                                                              CollectionAssert.AreEqual(
                                                                  new[] { "Project", "child" },
                                                                  a);
                                                              errorAdded = true;
                                                          }
                              };
     queue.Validate(validationStub);
     Assert.IsTrue(errorAdded);
 }
Ejemplo n.º 9
0
 public void UniversalNameHandlesChildItem()
 {
     var child = new Queue("ChildQueue");
     var parent = new Queue("ParentQueue", child);
     new Server(parent)
         {
             Name = "ServerName"
         };
     var actual = child.UniversalName;
     Assert.AreEqual("urn:ccnet:ServerName:ParentQueue:ChildQueue", actual);
 }
Ejemplo n.º 10
0
 public void UniversalNameHandlesTopLevel()
 {
     var queue = new Queue("TestQueue");
     new Server(queue)
         {
             Name = "ServerName"
         };
     var actual = queue.UniversalName;
     Assert.AreEqual("urn:ccnet:ServerName:TestQueue", actual);
 }
Ejemplo n.º 11
0
 public void LocateMatchesTask()
 {
     var task = new Comment();
     var project = new Project("TestProject", task);
     var queue = new Queue("RootQueue", project);
     var server = new Server("Local", queue);
     var actual = server.Locate("urn:ccnet:local:testProject:comment");
     Assert.AreSame(task, actual);
 }
Ejemplo n.º 12
0
        public void ReadRoundRobinOfQueues()
        {
            var configuration = LoadConfiguration(
                            AssemblyHelper.RetrieveExampleFile("RoundRobinOfQueues"));

            Assert.IsNotNull(configuration);
            Assert.AreEqual("2.0", configuration.Version.ToString(2));
            var queue1 = new Queue("Queue1", new Project("Project1"), new Project("Project2"));
            var queue2 = new Queue("Queue2", new Project("Project3"), new Project("Project4"));
            this.VerifyChildren(
                configuration.Children,
                new RoundRobin("RoundRobin", queue1, queue2));
        }
Ejemplo n.º 13
0
 public void WriteSimpleQueue()
 {
     var project = new Project("Project1");
     Queue.SetPriority(project, 3);
     var configuration = new Queue(
         "Queue1",
         project,
         new Project("Project2"));
     PerformSerialisationTest(configuration, "SimpleQueue");
 }
Ejemplo n.º 14
0
        public void HandlesQueueOfQueues()
        {
            var integrations = new List<string>();
            var contexts = new List<IntegrationContext>();
            var projects = new Project[6];
            for (var loop = 0; loop < projects.Length; loop++)
            {
                var project = new Project("Project" + loop);
                projects[loop] = project;
            }

            var queue1 = new Queue("Queue1", projects[0], projects[1]);
            var queue2 = new Queue("Queue2", projects[2], projects[3]);
            var queue3 = new Queue("Queue3", projects[4], projects[5]);
            var queue4 = new Queue("Queue4", queue1, queue2, queue3)
                             {
                                 AllowedActive = 2
                             };

            // Trying to simulate async code here - need to fire the completion events in the
            // order they are released
            var completed = new List<IntegrationContext>();
            foreach (var project in projects)
            {
                var context = new IntegrationContext(project);
                contexts.Add(context);
                project.Host.AskToIntegrate(context);
                if (context.IsLocked)
                {
                    context.Released += (o, e) =>
                                            {
                                                var subContext = o as IntegrationContext;
                                                completed.Add(subContext);
                                                integrations.Add(subContext.Item.Name);
                                            };
                }
                else
                {
                    completed.Add(context);
                    integrations.Add(project.Name);
                }
            }

            // completed will be modified at the same time we are iterating through it so can't
            // use foreach here
            for (var loop = 0; loop < completed.Count; loop++)
            {
                completed[loop].Complete();
            }

            // These should both be empty at the end of the process
            Assert.AreEqual(0, queue4.GetActiveRequests().Count());
            Assert.AreEqual(0, queue4.GetPendingRequests().Count());

            // Check that there is the correct order
            var expected = new[]
                               {
                                   "Project0",
                                   "Project2",
                                   "Project4",
                                   "Project1",
                                   "Project3",
                                   "Project5"
                               };
            CollectionAssert.AreEqual(expected, integrations);
        }
Ejemplo n.º 15
0
 public void StartingAQueueWithAProjectSetsTheHost()
 {
     var project = new Project();
     var queue = new Queue("Test", project);
     Assert.AreSame(queue, project.Host);
 }
Ejemplo n.º 16
0
 public void AddingAQueueSetsItsHostToTheQueue()
 {
     var queue1 = new Queue();
     var queue2 = new Queue();
     queue1.Children.Add(queue2);
     Assert.AreSame(queue1, queue2.Host);
 }
Ejemplo n.º 17
0
 public void AddingAProjectSetsItsHostToTheQueue()
 {
     var queue = new Queue();
     var project = new Project();
     queue.Children.Add(project);
     Assert.AreSame(queue, project.Host);
 }
Ejemplo n.º 18
0
 public void ItemTypeIsQueue()
 {
     var item = new Queue();
     Assert.AreEqual("Queue", item.ItemType);
 }
Ejemplo n.º 19
0
 public void LocateReturnsNullIfItemIsNotProjectOrRootStructure()
 {
     var project = new Project("TestProject");
     var queue = new Queue("RootQueue", project);
     var server = new Server("Local", queue);
     var actual = server.Locate("urn:ccnet:local:somethingElse");
     Assert.IsNull(actual);
 }
Ejemplo n.º 20
0
 public void ValidateValidatesChildren()
 {
     var validated = false;
     var projectStub = new ProjectStub
                           {
                               OnValidate = vl => validated = true
                           };
     var validationMock = new Mock<IValidationLog>();
     var queue = new Queue("Test", projectStub);
     queue.Validate(validationMock.Object);
     Assert.IsTrue(validated);
 }
Ejemplo n.º 21
0
 public void UniversalNameHandlesProjectAsChild()
 {
     var project = new Project("ProjectName");
     var queue = new Queue("QueueName", project);
     new Server(queue)
         {
             Name = "ServerName"
         };
     var actual = project.UniversalName;
     Assert.AreEqual("urn:ccnet:ServerName:ProjectName", actual);
 }
Ejemplo n.º 22
0
 public void WriteQueueOfQueues()
 {
     var queue1 = new Queue("Queue1", new Project("Project1"), new Project("Project2"));
     var queue2 = new Queue("Queue2", new Project("Project3"), new Project("Project4"));
     var configuration = new Queue("Queue3", queue1, queue2)
                             {
                                 AllowedActive = 2
                             };
     PerformSerialisationTest(configuration, "QueueOfQueues");
 }
Ejemplo n.º 23
0
 public void RemovingAChildResetsItsParent()
 {
     var project = new Project();
     var queue = new Queue("Test", project);
     queue.Children.Remove(project);
     Assert.IsNull(project.Host);
 }
Ejemplo n.º 24
0
 public void WriteRoundRobinOfQueues()
 {
     var queue1 = new Queue("Queue1", new Project("Project1"), new Project("Project2"));
     var queue2 = new Queue("Queue2", new Project("Project3"), new Project("Project4"));
     var configuration = new RoundRobin("RoundRobin", queue1, queue2);
     PerformSerialisationTest(configuration, "RoundRobinOfQueues");
 }
Ejemplo n.º 25
0
 public void ValidateDetectsDuplicateProjects()
 {
     var errorAdded = false;
     var project1 = new Project("Project");
     var project2 = new Project("Project");
     var childQueue = new Queue("Test", project2);
     var project3 = new Project("OtherProject");
     var server = new Server("Server", project1, childQueue, project3);
     var validationStub = new ValidationLogStub
                              {
                                  OnAddErrorMessage = (m, a) =>
                                                          {
                                                              Assert.AreEqual(
                                                                  "Duplicate {1} name detected: '{0}'", m);
                                                              CollectionAssert.AreEqual(
                                                                  new[] { "Project", "project" },
                                                                  a);
                                                              errorAdded = true;
                                                          }
                              };
     server.Validate(validationStub);
     Assert.IsTrue(errorAdded);
 }