public void Should_create_a_new_consumer_instance_for_each_message()
        {
            var message = new MyMessage();

            var result = MockRepository.GenerateMock<Channel<MyMessage>>();
            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock<ChannelProvider<MyMessage>>();
            provider.Expect(x => x.GetChannel(message)).Return(result).Repeat.Twice();

            var channel = new InstanceChannel<MyMessage>(new SynchronousFiber(), provider);

            channel.Send(message);
            channel.Send(message);

            result.VerifyAllExpectations();
            provider.VerifyAllExpectations();
        }
Example #2
0
        public void Should_create_a_new_consumer_instance_for_each_message()
        {
            var message = new MyMessage();

            var result = MockRepository.GenerateMock <Channel <MyMessage> >();

            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock <ChannelProvider <MyMessage> >();

            provider.Expect(x => x.GetChannel(message)).Return(result).Repeat.Twice();

            var channel = new InstanceChannel <MyMessage>(new SynchronousFiber(), provider);

            channel.Send(message);
            channel.Send(message);

            result.VerifyAllExpectations();
            provider.VerifyAllExpectations();
        }
Example #3
0
        public void Should_pull_the_matching_instance_from_the_cace()
        {
            var message = new MyMessage();

            var result = MockRepository.GenerateMock<Channel<MyMessage>>();
            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock<ChannelProvider<MyMessage>>();
            provider.Expect(x => x(message)).Return(result).Repeat.Once();

            KeyAccessor<MyMessage, Guid> messageKeyAccessor = x => x.Id;

            var channel = new InstanceChannel<MyMessage>(new KeyedChannelProvider<MyMessage, Guid>(provider, messageKeyAccessor).GetChannel);

            channel.Send(message);
            channel.Send(message);

            provider.VerifyAllExpectations();
            result.VerifyAllExpectations();
        }
Example #4
0
        public void Should_work_for_thread_static_instances()
        {
            int message = 27;

            var result = MockRepository.GenerateMock <Channel <int> >();

            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock <ChannelProvider <int> >();

            provider.Expect(x => x.GetChannel(message)).Return(result).Repeat.Twice();

            var channel = new InstanceChannel <int>(new SynchronousFiber(), new ThreadStaticChannelProvider <int>(provider));

            var first   = new Future <bool>();
            var second  = new Future <bool>();
            var started = new Future <bool>();

            ThreadPool.QueueUserWorkItem(x =>
            {
                channel.Send(message);
                started.Complete(true);

                second.WaitUntilCompleted(5.Seconds());
                first.Complete(true);
            });

            started.WaitUntilCompleted(5.Seconds());

            ThreadPool.QueueUserWorkItem(x =>
            {
                channel.Send(message);
                second.Complete(true);
            });

            first.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
            second.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();

            provider.VerifyAllExpectations();
            result.VerifyAllExpectations();
        }
Example #5
0
        public void Should_pull_the_matching_instance_from_the_cace()
        {
            var message = new MyMessage();

            var result = MockRepository.GenerateMock <Channel <MyMessage> >();

            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock <ChannelProvider <MyMessage> >();

            provider.Expect(x => x.GetChannel(message)).Return(result).Repeat.Once();

            KeyAccessor <MyMessage, Guid> messageKeyAccessor = x => x.Id;

            var channel = new InstanceChannel <MyMessage>(new SynchronousFiber(),
                                                          new KeyedChannelProvider <MyMessage, Guid>(provider, messageKeyAccessor));

            channel.Send(message);
            channel.Send(message);

            provider.VerifyAllExpectations();
            result.VerifyAllExpectations();
        }
Example #6
0
        public void Should_work_for_primitive_types_shorty()
        {
            int message = 27;

            var result = MockRepository.GenerateMock <Channel <int> >();

            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock <ChannelProvider <int> >();

            provider.Expect(x => x.GetChannel(message)).Return(result).Repeat.Once();

            KeyAccessor <int, int> messageKeyAccessor = x => x;

            var channel = new InstanceChannel <int>(new SynchronousFiber(),
                                                    new KeyedChannelProvider <int, int>(provider, messageKeyAccessor));


            channel.Send(message);
            channel.Send(message);

            provider.VerifyAllExpectations();
            result.VerifyAllExpectations();
        }
        public void Should_work_for_primitive_types_shorty()
        {
            int message = 27;

            var result = MockRepository.GenerateMock<Channel<int>>();
            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock<ChannelProvider<int>>();
            provider.Expect(x => x.GetChannel(message)).Return(result).Repeat.Once();

            KeyAccessor<int, int> messageKeyAccessor = x => x;

            var channel = new InstanceChannel<int>(new SynchronousFiber(),
                                                   new KeyedChannelProvider<int, int>(provider, messageKeyAccessor));

            channel.Send(message);
            channel.Send(message);

            provider.VerifyAllExpectations();
            result.VerifyAllExpectations();
        }
        public void Should_work_for_thread_static_instances()
        {
            int message = 27;

            var result = MockRepository.GenerateMock<Channel<int>>();
            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock<ChannelProvider<int>>();
            provider.Expect(x => x.GetChannel(message)).Return(result).Repeat.Twice();

            var channel = new InstanceChannel<int>(new SynchronousFiber(), new ThreadStaticChannelProvider<int>(provider));

            var first = new Future<bool>();
            var second = new Future<bool>();
            var started = new Future<bool>();

            ThreadPool.QueueUserWorkItem(x =>
                {
                    channel.Send(message);
                    started.Complete(true);

                    second.WaitUntilCompleted(5.Seconds());
                    first.Complete(true);
                });

            started.WaitUntilCompleted(5.Seconds());

            ThreadPool.QueueUserWorkItem(x =>
                {
                    channel.Send(message);
                    second.Complete(true);
                });

            first.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
            second.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();

            provider.VerifyAllExpectations();
            result.VerifyAllExpectations();
        }
Example #9
0
        public void Should_work_for_thread_static_instances()
        {
            int message = 27;

            var result = MockRepository.GenerateMock<Channel<int>>();
            result.Expect(x => x.Send(message)).Repeat.Twice();

            var provider = MockRepository.GenerateMock<ChannelProvider<int>>();
            provider.Expect(x => x(message)).Return(result).Repeat.Twice();

            var channel = new InstanceChannel<int>(new ThreadStaticChannelProvider<int>(provider).GetChannel);

            Future<bool> first = new Future<bool>();
            Future<bool> second = new Future<bool>();

            ThreadPool.QueueUserWorkItem(x =>
                {
                    long k;
                    for (int i = 0; i < 10000000; i++)
                    {
                        k = i*777;

                    }
                    channel.Send(message);
                    first.Complete(true);
                });
            ThreadPool.QueueUserWorkItem(x =>
                {
                    long k;
                    for (int i = 0; i < 10000000; i++)
                    {
                        k = i * 777;

                    }
                    channel.Send(message);
                    second.Complete(true);
                });

            first.IsAvailable(5.Seconds()).ShouldBeTrue();
            second.IsAvailable(5.Seconds()).ShouldBeTrue();

            provider.VerifyAllExpectations();
            result.VerifyAllExpectations();
        }