Exemplo n.º 1
0
        public void testNullPriorityIsConsideredNormal()
        {
            PriorityChannel channel      = new PriorityChannel(5);
            IMessage        highPriority = CreatePriorityMessage(MessagePriority.HIGH);
            IMessage        lowPriority  = CreatePriorityMessage(MessagePriority.LOW);
            IMessage        nullPriority = new StringMessage("test-NULL");

            channel.Send(lowPriority);
            channel.Send(highPriority);
            channel.Send(nullPriority);
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("test-HIGH"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("test-NULL"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("test-LOW"));
        }
Exemplo n.º 2
0
        public void testDefaultComparator()
        {
            PriorityChannel channel   = new PriorityChannel(5);
            IMessage        priority1 = CreatePriorityMessage(MessagePriority.HIGHEST);
            IMessage        priority2 = CreatePriorityMessage(MessagePriority.HIGH);
            IMessage        priority3 = CreatePriorityMessage(MessagePriority.NORMAL);
            IMessage        priority4 = CreatePriorityMessage(MessagePriority.LOW);
            IMessage        priority5 = CreatePriorityMessage(MessagePriority.LOWEST);

            channel.Send(priority4);
            channel.Send(priority3);
            channel.Send(priority5);
            channel.Send(priority1);
            channel.Send(priority2);
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("test-HIGHEST"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("test-HIGH"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("test-NORMAL"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("test-LOW"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("test-LOWEST"));
        }
Exemplo n.º 3
0
        public void testCustomComparator()
        {
            PriorityChannel channel  = new PriorityChannel(5, new StringPayloadComparator());
            IMessage        messageA = new StringMessage("A");
            IMessage        messageB = new StringMessage("B");
            IMessage        messageC = new StringMessage("C");
            IMessage        messageD = new StringMessage("D");
            IMessage        messageE = new StringMessage("E");

            channel.Send(messageC);
            channel.Send(messageA);
            channel.Send(messageE);
            channel.Send(messageD);
            channel.Send(messageB);
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("A"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("B"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("C"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("D"));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo("E"));
        }
Exemplo n.º 4
0
        public void testCapacityEnforced()
        {
            PriorityChannel channel = new PriorityChannel(3);

            Assert.IsTrue(channel.Send(new StringMessage("test1"), TimeSpan.Zero));
            Assert.IsTrue(channel.Send(new StringMessage("test2"), TimeSpan.Zero));
            Assert.IsTrue(channel.Send(new StringMessage("test3"), TimeSpan.Zero));
            Assert.IsFalse(channel.Send(new StringMessage("test4"), TimeSpan.Zero));
            channel.Receive(TimeSpan.Zero);
            Assert.IsTrue(channel.Send(new StringMessage("test5")));
        }