public void Should_capture_the_instance_channel()
        {
            var provider = new DelegateChannelProvider<int>(x => new ConsumerChannel<int>(new SynchronousFiber(), y => { }));
            var channel = new InstanceChannel<int>(provider);

            new ChannelVisitor().Visit(channel);
        }
Beispiel #2
0
        public void Should_capture_the_instance_channel()
        {
            var provider = new DelegateChannelProvider <int>(x => new ConsumerChannel <int>(new SynchronousFiber(), y => { }));
            var channel  = new InstanceChannel <int>(new SynchronousFiber(), provider);

            new ChannelVisitor().Visit(channel);
        }
        public Channel <TChannel> GetChannel(TChannel message)
        {
            TKey key = _keyAccessor(message);

            Fiber fiber = _fiberProvider.GetFiber(key);

            var channel = new InstanceChannel <TChannel>(fiber, _channelProvider);

            return(channel);
        }
Beispiel #4
0
        protected override Channel <T> Visitor <T>(InstanceChannel <T> channel)
        {
            _current = GetVertex(channel.GetHashCode(), () => "Instance", typeof(InstanceChannel <T>), typeof(T));

            if (_stack.Count > 0)
            {
                _edges.Add(new Edge(_stack.Peek(), _current, _current.TargetType.Name));
            }

            return(WithVertex(() => base.Visitor(channel)));
        }
        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();
        }
Beispiel #6
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();
        }
        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();
        }
Beispiel #8
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();
        }
Beispiel #9
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();
		}
Beispiel #10
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();
        }
Beispiel #11
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();
        }
Beispiel #12
0
        protected virtual Channel <T> Visitor <T>(InstanceChannel <T> channel)
        {
            Visit(channel.Provider);

            return(channel);
        }
        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();
        }
Beispiel #14
0
        protected override Channel <T> Visitor <T>(InstanceChannel <T> channel)
        {
            Trace.WriteLine("InstanceChannel<{0}>".FormatWith(typeof(T).Name));

            return(base.Visitor(channel));
        }
Beispiel #15
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();
        }