public void create_from_graph_and_run_through_the_channel() { using (var graph = new ChannelGraph()) { var node = graph.ChannelFor <BusSettings>(x => x.Outbound); node.Uri = new Uri("memory://foo"); var transport = new InMemoryTransport(); transport.OpenChannels(graph); node.Channel.ShouldNotBeNull(); var envelope = new Envelope(); envelope.CorrelationId = Guid.NewGuid().ToString(); envelope.Headers["Foo"] = "Bar"; envelope.Data = new byte[] { 1, 2, 3, 4, 5 }; var receiver = new RecordingReceiver(); node.StartReceiving(receiver, new RecordingLogger()); node.Channel.Send(envelope.Data, envelope.Headers); Wait.Until(() => receiver.Received.Any(), timeoutInMilliseconds: 2000); var received = receiver.Received.Single(); received.CorrelationId.ShouldEqual(envelope.CorrelationId); received.ContentType.ShouldEqual(envelope.ContentType); received.Data.ShouldEqual(envelope.Data); } }
public void send_a_message_and_get_it_back() { var envelope = new Envelope { Data = new byte[] { 1, 2, 3, 4, 5 } }; envelope.Headers["foo"] = "bar"; var receiver = new RecordingReceiver(); node.StartReceiving(receiver, new RecordingLogger()); node.Channel.As <LightningQueuesChannel>().Send(envelope.Data, envelope.Headers); Wait.Until(() => receiver.Received.Any()); graph.Dispose(); queues.Dispose(); receiver.Received.Any().ShouldBeTrue(); var actual = receiver.Received.Single(); actual.Data.ShouldBe(envelope.Data); actual.Headers["foo"].ShouldBe("bar"); }
public void send_a_message_and_get_it_back_non_persistent() { SetupTransport("lq.tcp://localhost:2032/upstream", ChannelMode.DeliveryFastWithoutGuarantee); var envelope = new Envelope { Data = new byte[] { 1, 2, 3, 4, 5 } }; envelope.Headers["foo"] = "bar"; var receiver = new RecordingReceiver(); node.StartReceiving(receiver, new RecordingLogger()); node.Channel.As <LightningQueuesChannel>().Send(envelope.Data, envelope.Headers); Wait.Until(() => receiver.Received.Any()); graph.Dispose(); queues.Dispose(); receiver.Received.Any().ShouldBeTrue(); var actual = receiver.Received.Single(); actual.Data.ShouldBe(envelope.Data); actual.Headers["foo"].ShouldBe("bar"); }
public void create_from_graph_and_run_through_the_channel() { using (var graph = new ChannelGraph()) { var node = graph.ChannelFor<BusSettings>(x => x.Outbound); node.Uri = new Uri("memory://foo"); var transport = new InMemoryTransport(); transport.OpenChannels(graph); node.Channel.ShouldNotBeNull(); var envelope = new Envelope(); envelope.CorrelationId = Guid.NewGuid().ToString(); envelope.Headers["Foo"] = "Bar"; envelope.Data = new byte[] {1, 2, 3, 4, 5}; var receiver = new RecordingReceiver(); node.StartReceiving(receiver); node.Channel.Send(envelope.Data, envelope.Headers); Wait.Until(() => receiver.Received.Any(), timeoutInMilliseconds: 2000); var received = receiver.Received.Single(); received.CorrelationId.ShouldEqual(envelope.CorrelationId); received.ContentType.ShouldEqual(envelope.ContentType); received.Data.ShouldEqual(envelope.Data); } }
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.ShouldBe(20); }
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 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 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.ShouldBe(20); }
public void can_round_trip_an_envelope_through_the_queue() { var envelope = new EnvelopeToken(); envelope.CorrelationId = Guid.NewGuid().ToString(); envelope.Headers["Foo"] = "Bar"; envelope.Data = new byte[] { 1, 2, 3, 4, 5 }; var queue = new InMemoryQueue(new Uri("memory://foo")); var receiver = new RecordingReceiver(); var task = Task.Factory.StartNew(() => queue.Receive(receiver)); queue.Enqueue(envelope); Wait.Until(() => receiver.Received.Any(), timeoutInMilliseconds: 2000); var received = receiver.Received.Single(); received.CorrelationId.ShouldEqual(envelope.CorrelationId); received.ContentType.ShouldEqual(envelope.ContentType); received.Data.ShouldEqual(envelope.Data); task.SafeDispose(); }
public void can_be_used_after_clearing_all_messages() { using (var graph = new ChannelGraph()) { var node = graph.ChannelFor<BusSettings>(x => x.Outbound); node.Uri = new Uri("memory://foo"); var transport = new InMemoryTransport(); transport.OpenChannels(graph); var receiver = new RecordingReceiver(); node.StartReceiving(receiver); node.Channel.Send(new byte[] { 1, 2 }, new NameValueHeaders()); transport.ClearAll(); node.Channel.Send(new byte[] { 3, 4 }, new NameValueHeaders()); Wait.Until(() => receiver.Received.Count == 2); receiver.Received.ShouldHaveCount(2); } }
public void can_be_used_after_clearing_all_messages() { using (var graph = new ChannelGraph()) { var node = graph.ChannelFor <BusSettings>(x => x.Outbound); node.Uri = new Uri("memory://foo"); var transport = new InMemoryTransport(); transport.OpenChannels(graph); var receiver = new RecordingReceiver(); node.StartReceiving(receiver, new RecordingLogger()); node.Channel.Send(new byte[] { 1, 2 }, new NameValueHeaders()); transport.ClearAll(); node.Channel.Send(new byte[] { 3, 4 }, new NameValueHeaders()); Wait.Until(() => receiver.Received.Count == 2); receiver.Received.ShouldHaveCount(2); } }
public void can_round_trip_an_envelope_through_the_queue() { var envelope = new EnvelopeToken(); envelope.CorrelationId = Guid.NewGuid().ToString(); envelope.Headers["Foo"] = "Bar"; envelope.Data = new byte[] { 1, 2, 3, 4, 5 }; var queue = new InMemoryQueue(new Uri("memory://foo")); var receiver = new RecordingReceiver(); var task = Task.Factory.StartNew(() => queue.Receive(receiver)); queue.Enqueue(envelope); Wait.Until(() => receiver.Received.Count > 0, timeoutInMilliseconds: 2000); var received = receiver.Received.Single(); received.CorrelationId.ShouldEqual(envelope.CorrelationId); received.ContentType.ShouldEqual(envelope.ContentType); received.Data.ShouldEqual(envelope.Data); task.SafeDispose(); }