Esempio n. 1
0
        public SubscriptionCache(ChannelGraph graph, IEnumerable<ITransport> transports)
        {
            if (!transports.Any())
            {
                throw new Exception(
                    "No transports are registered.  FubuTransportation cannot function without at least one ITransport");
            }

            _graph = graph;
            _transports = transports;

            _volatileNodes = new Cache<Uri, ChannelNode>(uri =>
            {
                var transport = _transports.FirstOrDefault(x => x.Protocol == uri.Scheme);
                if (transport == null)
                {
                    throw new UnknownChannelException(uri);
                }

                var node = new ChannelNode { Uri = uri, Key = uri.ToString() };
                node.Channel = transport.BuildDestinationChannel(node.Uri);

                return node;
            });
        }
 public void setting_address_has_to_be_a_Uri()
 {
     var node = new ChannelNode();
     Exception<ArgumentOutOfRangeException>.ShouldBeThrownBy(() => {
         node.SettingAddress = ReflectionHelper.GetAccessor<FakeThing>(x => x.Name);
     });
 }
Esempio n. 3
0
 public Receiver(IHandlerPipeline pipeline, ChannelGraph graph, ChannelNode node)
 {
     _pipeline = pipeline;
     _graph = graph;
     _node = node;
     _address = node.Channel.Address;
 }
Esempio n. 4
0
        public EnvelopeSent(EnvelopeToken envelope, ChannelNode node)
        {
            Envelope = envelope;

            Uri = node.Uri;
            Key = node.Key;
        }
        private void addRow(TableRowTag row, ChannelNode channel)
        {
            addDescriptionCell(row, channel);

            addSchedulers(row, channel);

            addRoutingRules(row, channel);
        }
Esempio n. 6
0
 private static void addDescriptionCell(TableRowTag row, ChannelNode channel)
 {
     var cell = row.Cell();
     cell.Add("h5").Text(channel.Key);
     cell.Add("div/i").Text(channel.Uri.ToString());
     if (channel.DefaultContentType != null)
         cell.Add("div").Text("Default Content Type: " + channel.DefaultContentType);
 }
        public void setting_default_content_type_will_clear_the_serializer()
        {
            var node = new ChannelNode();
            node.DefaultSerializer = new BinarySerializer();

            node.DefaultContentType = "application/xml";

            node.DefaultContentType.ShouldEqual("application/xml");
            node.DefaultSerializer.ShouldBeNull();
        }
        public void FixtureSetup()
        {
            FubuTransport.AllQueuesInMemory = true;

            theRuntime = FubuTransport.For(x => { }).StructureMap(new Container()).Bootstrap();
            graph = theRuntime.Factory.Get<ChannelGraph>();

            var uri = graph.ReplyChannelFor(InMemoryChannel.Protocol);
            theReplyNode = graph.Single(x => x.Channel.Address == uri);
        }
        public void publishes_is_false_if_no_rules_pass()
        {
            var node = new ChannelNode();
            for (int i = 0; i < 5; i++)
            {
                node.Rules.Add(MockRepository.GenerateMock<IRoutingRule>());
            }

            node.Publishes(typeof(NewUser)).ShouldBeFalse();
        }
        /*
         * Changes
         * 1.) Do serialization within sendToChannel
         * 2.) do the cloning *outside* of sendToChannel
         * 3.) Make envelopeserializer smart enough not to replace the contents if it needs to
         */
        private void sendToChannel(Envelope envelope, ChannelNode node)
        {
            var replyUri = _router.ReplyUriFor(node);

            var headers = node.Send(envelope, _serializer, replyUri: replyUri);
            _logger.InfoMessage(() => new EnvelopeSent(new EnvelopeToken
            {
                Headers = headers,
                Message = envelope.Message
            }, node));
        }
        public void publishes_is_true_if_any_rule_passes()
        {
            var node = new ChannelNode();
            for (int i = 0; i < 5; i++)
            {
                node.Rules.Add(MockRepository.GenerateMock<IRoutingRule>());
            }

            node.Rules[2].Stub(x => x.Matches(typeof (NewUser))).Return(true);

            node.Publishes(typeof(NewUser)).ShouldBeTrue();
        }
Esempio n. 12
0
 private static void addRoutingRules(TableRowTag row, ChannelNode channel)
 {
     var cell = row.Cell().AddClass("routing-rules");
     if (channel.Rules.Any())
     {
         cell.Add("ul", ul => { channel.Rules.Each(x => ul.Add("li").Text(x.Describe())); });
     }
     else
     {
         cell.Text("None");
     }
 }
Esempio n. 13
0
 private void addModifiers(TableRowTag row, ChannelNode channel)
 {
     var cell = row.Cell().AddClass("modifiers");
     if (channel.Modifiers.Any())
     {
         cell.Add("ul", ul => { channel.Modifiers.Each(x => ul.Add("li").Text(x.ToString())); });
     }
     else
     {
         cell.Text("None");
     }
 }
Esempio n. 14
0
 private static void addSchedulers(TableRowTag row, ChannelNode channel)
 {
     var cell = row.Cell();
     if (channel.Incoming)
     {
         var description = Description.For(channel.Scheduler);
         cell.Append(new DescriptionBodyTag(description));
     }
     else
     {
         cell.Text("None");
     }
 }
Esempio n. 15
0
        public void doesnt_throw_if_receive_only_fails_intermittently()
        {
            var channel = new FakeChannel { StopAfter = 20 };
            var node = new ChannelNode
            {
                Channel = channel,
                Scheduler = new FakeScheduler()
            };

            var logger = new RecordingLogger();
            var receiver = new RecordingReceiver();
            node.StartReceiving(receiver, logger);

            channel.HitCount.ShouldEqual(20);
        }
        public void builds_a_schedule_by_threads()
        {
            var settings = new ThreadSettings
            {
                Count = 7
            };

            var channelNode = new ChannelNode();
            new ByThreadScheduleMaker<ThreadSettings>(x => x.Count)
                .As<ISettingsAware>()
                .ApplySettings(settings, channelNode);

            channelNode.Scheduler.ShouldBeOfType<ThreadScheduler>()
                .ThreadCount.ShouldEqual(7);
        }
Esempio n. 17
0
        public void continuous_receive_errors()
        {
            var logger = new RecordingLogger();
            var receiver = new RecordingReceiver();
            var channel = MockRepository.GenerateMock<IChannel>();
            channel.Expect(x => x.Receive(receiver))
                .Throw(new Exception("I failed"));

            var node = new ChannelNode
            {
                Channel = channel,
                Scheduler = new FakeScheduler()
            };

            Assert.Throws<ReceiveFailureException>(() => node.StartReceiving(receiver, logger));
        }
        public void Serialize(Envelope envelope, ChannelNode node)
        {
            if (envelope.Message == null) throw new InvalidOperationException("No message on this envelope to serialize");

            var serializer = SelectSerializer(envelope, node);
            if (envelope.ContentType.IsEmpty())
            {
                envelope.ContentType = serializer.ContentType;
            }

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(envelope.Message, stream);
                stream.Position = 0;

                envelope.Data = stream.ReadAllBytes();
            }
        }
        public IMessageSerializer SelectSerializer(Envelope envelope, ChannelNode node)
        {
            if (envelope.ContentType.IsNotEmpty())
            {
                return findSerializer(envelope.ContentType);
            }

            if (node.DefaultSerializer != null)
            {
                return node.DefaultSerializer;
            }

            if (node.DefaultContentType.IsNotEmpty())
            {
                return findSerializer(node.DefaultContentType);
            }

            return findSerializer(_graph.DefaultContentType);
        }
        private void SetupTransport(string uri)
        {
            graph = new ChannelGraph();
            node = graph.ChannelFor<ChannelSettings>(x => x.Upstream);
            node.Uri = new Uri(uri);
            node.Incoming = true;

            var delayedCache = new DelayedMessageCache<MessageId>();
            queues = new PersistentQueues(new RecordingLogger(), delayedCache, new LightningQueueSettings());
            queues.ClearAll();
            transport = new LightningQueuesTransport(queues, new LightningQueueSettings(), delayedCache);

            transport.OpenChannels(graph);
        }
 protected override IChannel buildChannel(ChannelNode channelNode)
 {
     return LightningQueuesChannel.Build(new LightningUri(channelNode.Uri), _queues, _delayedMessages, channelNode.Incoming);
 }
        public void Setup()
        {
            graph = new ChannelGraph();
            node = graph.ChannelFor<ChannelSettings>(x => x.Upstream);
            node.Uri = new Uri("lq.tcp://localhost:2020/upstream");
            node.Incoming = true;

            var delayedCache = new DelayedMessageCache<MessageId>();
            queues = new PersistentQueues(new RecordingLogger(), delayedCache);
            queues.ClearAll();
            transport = new LightningQueuesTransport(queues, new LightningQueueSettings(), delayedCache);

            transport.OpenChannels(graph);
        }
Esempio n. 23
0
        void ISettingsAware.ApplySettings(object settings, ChannelNode node)
        {
            int threadCount = (int)ReflectionHelper.GetAccessor(_expression).GetValue(settings);

            node.Scheduler = buildScheduler(threadCount);
        }
Esempio n. 24
0
 public void Serialize(Envelope envelope, ChannelNode node)
 {
     throw new EnvelopeDeserializationException("Error");
 }
        public void setting_the_default_serializer_will_clear_the_default_content_type()
        {
            var node = new ChannelNode
            {
                DefaultContentType = "application/xml"
            };

            node.DefaultSerializer = new BinarySerializer();

            node.DefaultSerializer.ShouldBeOfType<BinarySerializer>();
            node.DefaultContentType.ShouldBeNull();
        }
        public void SetUp()
        {
            theEnvelope = new Envelope()
            {
                Data = new byte[]{1,2,3,4},

            };

            theSerializer = MockRepository.GenerateMock<IEnvelopeSerializer>();

            theEnvelope.Headers["A"] = "1";
            theEnvelope.Headers["B"] = "2";
            theEnvelope.Headers["C"] = "3";
            theEnvelope.CorrelationId = Guid.NewGuid().ToString();

            theChannel = new RecordingChannel();

            theNode = new ChannelNode
            {
                Channel = theChannel,
                Key = "Foo",
                Uri = "foo://bar".ToUri()
            };

            theNode.Modifiers.Add(new HeaderSetter("D", "4"));
            theNode.Modifiers.Add(new HeaderSetter("E", "5"));

            theNode.Send(theEnvelope, theSerializer);
        }
        public void SetUp()
        {
            theEnvelope = new Envelope()
            {
                Data = new byte[]{1,2,3,4},

            };

            theEnvelope.Headers["A"] = "1";
            theEnvelope.Headers["B"] = "2";
            theEnvelope.Headers["C"] = "3";

            theChannel = new RecordingChannel();

            theNode = new ChannelNode
            {
                Channel = theChannel,
                Key = "Foo",
                Uri = "foo://bar".ToUri()
            };

            theNode.Send(theEnvelope);
        }
 public void no_publishing_rules_is_always_false()
 {
     var node = new ChannelNode();
     node.Publishes(typeof(NewUser)).ShouldBeFalse();
 }
Esempio n. 29
0
 public Uri ReplyUriFor(ChannelNode destination)
 {
     return _graph.ReplyChannelFor(destination.Protocol());
 }
Esempio n. 30
0
 private void addSerialization(TableRowTag row, ChannelNode channel)
 {
     var cell = row.Cell().AddClass("serialization");
     if (channel.DefaultContentType.IsNotEmpty())
     {
         cell.Text(channel.DefaultContentType);
     }
     else if (channel.DefaultSerializer != null)
     {
         cell.Text(channel.DefaultSerializer.ToString());
     }
     else
     {
         cell.Text("None");
     }
 }
Esempio n. 31
0
 protected abstract IChannel buildChannel(ChannelNode channelNode);