예제 #1
0
        public void Should_be_two_consumers_on_the_channel()
        {
            SelectiveConsumer <TestMessage> selectiveConsumer = x => y => { };

            var input = new ChannelAdapter();

            using (input.Connect(x =>
            {
                x.AddConsumerOf <TestMessage>()
                .UsingConsumer(message => { });

                x.AddConsumerOf <TestMessage>()
                .UsingSelectiveConsumer(selectiveConsumer);
            }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(BroadcastChannel),
                    typeof(TypedChannelAdapter <TestMessage>),
                    typeof(BroadcastChannel <TestMessage>),
                    typeof(ConsumerChannel <TestMessage>),
                    typeof(SelectiveConsumerChannel <TestMessage>),
                });
            }
        }
        public void Should_support_single_channels()
        {
            var input = new ChannelAdapter();

            using (input.Connect(x =>
            {
                x.AddConsumerOf <UpdateValue>()
                .UsingInstance()
                .Of <TestInstance>()
                .DistributedBy(m => m.Id)
                .PersistUsingNHibernate()
                .UsingSessionProvider(m => (ISession)null)
                .OnChannel(m => m.UpdateValueChannel)
                .CreateNewInstanceBy(m => new TestInstance(m.Id));
            }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(BroadcastChannel),
                    typeof(TypedChannelAdapter <UpdateValue>),
                    typeof(InstanceChannel <UpdateValue>),
                });
            }
        }
예제 #3
0
        public void Should_subscribe_the_last_message_consumer()
        {
            var input = new ChannelAdapter();

            using (input.Connect(x =>
            {
                x.AddConsumerOf <TestMessage>()
                .BufferFor(2.Seconds())
                .HandleOnCallingThread()
                .Last()
                .HandleOnCallingThread()
                .UsingConsumer(message =>
                {
                })
                .HandleOnCallingThread();
            }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(BroadcastChannel),
                    typeof(TypedChannelAdapter <TestMessage>),
                    typeof(IntervalChannel <TestMessage>),
                    typeof(LastChannel <TestMessage>),
                    typeof(ConsumerChannel <TestMessage>),
                });
            }
        }
        public void Sending_a_message_to_an_nhibernate_backed_state_machine()
        {
            TraceLogProvider.Configure(LogLevel.Debug);

            _newValue = new Random().Next(1, 500000)/100m;

            using (ISession session = SessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.CreateQuery("Delete TestStateMachineInstance").ExecuteUpdate();

                transaction.Commit();
            }

            var input = new ChannelAdapter();
            using (input.Connect(x =>
                {
                    x.AddConsumersFor<TestStateMachineInstance>()
                        .BindUsing<TestStateMachineInstanceBinding, int>()
                        .ExecuteOnProducerThread()
                        .CreateNewInstanceUsing(id => new TestStateMachineInstance(id))
                        .PersistUsingNHibernate()
                        .UseSessionProvider(() => SessionFactory.OpenSession());
                }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(TypedChannelAdapter<CreateOrder>),
                        typeof(InstanceChannel<CreateOrder>),
                        typeof(TypedChannelAdapter<UpdateOrder>),
                        typeof(InstanceChannel<UpdateOrder>),
                        typeof(TypedChannelAdapter<CompleteOrder>),
                        typeof(InstanceChannel<CompleteOrder>),
                    });

                var future = new Future<int>();
                TestStateMachineInstance.CompletedLatch = new CountdownLatch(1, future.Complete);
                //
                input.Send(new CreateOrder
                    {
                        Id = 27
                    });

                input.Send(new UpdateOrder
                    {
                        Id = 27,
                        Value = _newValue,
                    });

                input.Send(new CompleteOrder
                    {
                        Id = 27,
                    });

                future.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
            }
        }
예제 #5
0
		public void Should_properly_wrap_the_channel_as_synchronized()
		{
			Assert.IsNull(SynchronizationContext.Current);

			var fiber = new PoolFiber();

			var input = new ChannelAdapter();

			var context = new TestSynchronizationContext();

			var future = new Future<TestMessage>();

			SynchronizationContext.SetSynchronizationContext(context);

			Assert.IsNotNull(SynchronizationContext.Current);

			using (input.Connect(x =>
				{
					x.AddConsumerOf<TestMessage>()
						.OnCurrentSynchronizationContext()
						.UsingConsumer(message =>
							{
								Trace.WriteLine("Received on Thread: " + Thread.CurrentThread.ManagedThreadId);

								Assert.IsNotNull(SynchronizationContext.Current);
								Assert.AreEqual(context, SynchronizationContext.Current);

								future.Complete(message);
							});
				}))
			{
				Trace.WriteLine("Subscribed on Thread: " + Thread.CurrentThread.ManagedThreadId);

				SynchronizationContext.SetSynchronizationContext(null);

				input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
					{
						typeof(ChannelAdapter),
						typeof(BroadcastChannel),
						typeof(TypedChannelAdapter<TestMessage>),
						typeof(SynchronizedChannel<TestMessage>),
						typeof(ConsumerChannel<TestMessage>),
					});

				fiber.Add(() =>
					{
						Trace.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId);
						Assert.IsNull(SynchronizationContext.Current);

						input.Send(new TestMessage());
					});

				Assert.IsNull(SynchronizationContext.Current);

				future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
			}
		}
        public void Should_properly_wrap_the_channel_as_synchronized()
        {
            Assert.IsNull(SynchronizationContext.Current);

            var fiber = new ThreadPoolFiber();

            var input = new ChannelAdapter();

            var context = new TestSynchronizationContext();

            var future = new Future <TestMessage>();

            SynchronizationContext.SetSynchronizationContext(context);

            Assert.IsNotNull(SynchronizationContext.Current);

            using (input.Connect(x =>
            {
                x.AddConsumerOf <TestMessage>()
                .OnCurrentSynchronizationContext()
                .UsingConsumer(message =>
                {
                    Trace.WriteLine("Received on Thread: " + Thread.CurrentThread.ManagedThreadId);

                    Assert.IsNotNull(SynchronizationContext.Current);
                    Assert.AreEqual(context, SynchronizationContext.Current);

                    future.Complete(message);
                });
            }))
            {
                Trace.WriteLine("Subscribed on Thread: " + Thread.CurrentThread.ManagedThreadId);

                SynchronizationContext.SetSynchronizationContext(null);

                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(BroadcastChannel),
                    typeof(TypedChannelAdapter <TestMessage>),
                    typeof(SynchronizedChannel <TestMessage>),
                    typeof(ConsumerChannel <TestMessage>),
                });

                fiber.Add(() =>
                {
                    Trace.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId);
                    Assert.IsNull(SynchronizationContext.Current);

                    input.Send(new TestMessage());
                });

                Assert.IsNull(SynchronizationContext.Current);

                future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
            }
        }
        public void Sending_a_message_to_an_nhibernate_backed_state_machine()
        {
            TraceLogger.Configure(LogLevel.Debug);

            _newValue = new Random().Next(1, 500000) / 100m;

            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.CreateQuery("Delete TestStateMachineInstance").ExecuteUpdate();

                    transaction.Commit();
                }

            var input = new ChannelAdapter();

            using (input.Connect(x =>
            {
                x.AddConsumersFor <TestStateMachineInstance>()
                .BindUsing <TestStateMachineInstanceBinding, int>()
                .HandleOnCallingThread()
                .CreateNewInstanceBy(id => new TestStateMachineInstance(id))
                .PersistUsingNHibernate()
                .UseSessionProvider(() => SessionFactory.OpenSession());
            }))
            {
                _networkTypes = input.Flatten().Select(c => c.GetType());

                var future = new Future <int>();
                TestStateMachineInstance.CompletedLatch = new CountdownLatch(1, future.Complete);
                //
                input.Send(new UpdateOrder
                {
                    Id = 47
                });

                input.Send(new CreateOrder
                {
                    Id = 27
                });

                input.Send(new UpdateOrder
                {
                    Id    = 27,
                    Value = _newValue,
                });

                input.Send(new CompleteOrder
                {
                    Id = 27,
                });

                future.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
            }
        }
예제 #8
0
		public void Sending_a_message_to_an_nhibernate_backed_state_machine()
		{
			_newValue = new Random().Next(1, 500000)/100m;

			using (ISession session = SessionFactory.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				session.CreateQuery("Delete TestStateMachineInstance").ExecuteUpdate();

				transaction.Commit();
			}

			var input = new ChannelAdapter();
			using (input.Connect(x =>
				{
					x.AddConsumersFor<TestStateMachineInstance>()
						.BindUsing<TestStateMachineInstanceBinding, int>()
						.HandleOnCallingThread()
						.CreateNewInstanceBy(id => new TestStateMachineInstance(id))
						.PersistUsingNHibernate()
						.UseSessionProvider(() => SessionFactory.OpenSession());
				}))
			{
				_networkTypes = input.Flatten().Select(c => c.GetType());

				var future = new Future<int>();
				TestStateMachineInstance.CompletedLatch = new CountdownLatch(1, future.Complete);
				//
				input.Send(new UpdateOrder
					{
						Id = 47
					});

				input.Send(new CreateOrder
					{
						Id = 27
					});

				input.Send(new UpdateOrder
					{
						Id = 27,
						Value = _newValue,
					});

				input.Send(new CompleteOrder
					{
						Id = 27,
					});

				future.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
			}
		}
예제 #9
0
        public void Should_be_an_empty_channel_adapter_with_no_consumers()
        {
            var input = new ChannelAdapter();

            using (input.Connect(x => { }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(ShuntChannel)
                });
            }
        }
예제 #10
0
        public void Should_add_an_untyped_channel_to_an_untyped_channel_adapter()
        {
            var next = new ChannelAdapter();

            var input = new ChannelAdapter();
            using (input.Connect(x => { x.AddUntypedChannel(next); }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(ChannelAdapter),
                        typeof(ShuntChannel),
                    });
            }
        }
예제 #11
0
        public void Sending_a_message_to_an_nhibernate_backed_state_machine()
        {
            TraceLogger.Configure(LogLevel.Debug);

            _newValue = new Random().Next(1, 500000) / 100m;

            var input = new ChannelAdapter();

            using (input.Connect(x =>
            {
                x.AddConsumersFor <TestStateMachineInstance>()
                .BindUsing <TestStateMachineInstanceBinding, int>()
                .HandleOnCallingThread()
                .CreateNewInstanceBy(id => new TestStateMachineInstance(id))
                .PersistInMemoryUsing(_cache);
            }))
            {
                _networkTypes = input.Flatten().Select(c => c.GetType());

                var future = new Future <int>();
                TestStateMachineInstance.CompletedLatch = new CountdownLatch(1, future.Complete);
                //
                input.Send(new UpdateOrder
                {
                    Id    = 47,
                    Value = _newValue,
                });

                input.Send(new CreateOrder
                {
                    Id = 27
                });

                input.Send(new UpdateOrder
                {
                    Id    = 27,
                    Value = _newValue,
                });

                input.Send(new CompleteOrder
                {
                    Id = 27,
                });

                future.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
            }
        }
예제 #12
0
        public void Should_add_an_untyped_channel_to_an_untyped_channel_adapter()
        {
            var next = new ChannelAdapter();

            var input = new ChannelAdapter();

            using (input.Connect(x => { x.AddUntypedChannel(next); }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(BroadcastChannel),
                    typeof(ChannelAdapter),
                    typeof(ShuntChannel),
                });
            }
        }
예제 #13
0
		public void Sending_a_message_to_an_nhibernate_backed_state_machine()
		{
			_newValue = new Random().Next(1, 500000)/100m;

			var input = new ChannelAdapter();
			using (input.Connect(x =>
				{
					x.AddConsumersFor<TestStateMachineInstance>()
						.BindUsing<TestStateMachineInstanceBinding, int>()
						.HandleOnCallingThread()
						.CreateNewInstanceBy(id => new TestStateMachineInstance(id))
						.PersistInMemoryUsing(_cache);
				}))
			{
				_networkTypes = input.Flatten().Select(c => c.GetType());

				var future = new Future<int>();
				TestStateMachineInstance.CompletedLatch = new CountdownLatch(1, future.Complete);
				//
				input.Send(new UpdateOrder
					{
						Id = 47,
						Value = _newValue,
					});

				input.Send(new CreateOrder
					{
						Id = 27
					});

				input.Send(new UpdateOrder
					{
						Id = 27,
						Value = _newValue,
					});

				input.Send(new CompleteOrder
					{
						Id = 27,
					});

				future.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
			}
		}
예제 #14
0
        public void Should_include_the_filter_channel()
        {
            var input = new ChannelAdapter();

            using (input.Connect(x =>
            {
                x.AddConsumerOf <TestMessage>()
                .Where(message => message.Value == 47)
                .UsingConsumer(message => { });
            }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(BroadcastChannel),
                    typeof(TypedChannelAdapter <TestMessage>),
                    typeof(FilterChannel <TestMessage>),
                    typeof(ConsumerChannel <TestMessage>)
                });
            }
        }
예제 #15
0
        public void Should_be_able_to_configure_a_wcf_host_via_the_connect_dsl()
        {
            var future = new Future<TestMessage>();

            var input = new ChannelAdapter();
            using (input.Connect(x =>
                {
            //					x.ReceiveFromNamedPipe(new Uri("net.pipe://localhost/pipe"), "test");

                    x.AddConsumerOf<TestMessage>()
                        .UsingConsumer(future.Complete);
                }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(TypedChannelAdapter<TestMessage>),
                        typeof(ConsumerChannel<TestMessage>),
                    });
            }
        }
예제 #16
0
        public void Should_be_an_distinct_interval_consumer_on_the_channel()
        {
            var future = new Future <int>();

            var input    = new ChannelAdapter();
            int expected = 5;

            using (input.Connect(x =>
            {
                x.AddConsumerOf <TestMessage>()
                .BufferFor(2.Seconds())
                .Distinct(c => c.Value)
                .UsingConsumer(message => future.Complete(message.Count))
                .HandleOnCallingThread();
            }))
            {
                for (int i = 0; i < expected; i++)
                {
                    input.Send(new TestMessage
                    {
                        Value = i
                    });
                }

                future.WaitUntilCompleted(6.Seconds()).ShouldBeTrue();
                future.Value.ShouldEqual(expected);

                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(BroadcastChannel),
                    typeof(TypedChannelAdapter <TestMessage>),
                    typeof(IntervalChannel <TestMessage>),
                    typeof(DistinctChannel <TestMessage, int>),
                    typeof(ConsumerChannel <IDictionary <int, TestMessage> >),
                });
            }
        }
예제 #17
0
        public void Should_be_an_distinct_interval_consumer_on_the_channel()
        {
            var future = new Future<int>();

            var input = new ChannelAdapter();
            int expected = 5;

            using (input.Connect(x =>
                {
                    x.AddConsumerOf<TestMessage>()
                        .BufferFor(2.Seconds())
                        .Distinct(c => c.Value)
                        .UsingConsumer(message => future.Complete(message.Count))
                        .HandleOnCallingThread();
                }))
            {
                for (int i = 0; i < expected; i++)
                {
                    input.Send(new TestMessage
                        {
                            Value = i
                        });
                }

                future.WaitUntilCompleted(6.Seconds()).ShouldBeTrue();
                future.Value.ShouldEqual(expected);

                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(TypedChannelAdapter<TestMessage>),
                        typeof(IntervalChannel<TestMessage>),
                        typeof(DistinctChannel<TestMessage, int>),
                        typeof(ConsumerChannel<IDictionary<int, TestMessage>>),
                    });
            }
        }
예제 #18
0
        public void Should_be_able_to_configure_a_wcf_host_via_the_connect_dsl()
        {
            var future = new Future <TestMessage>();

            var input = new ChannelAdapter();

            using (input.Connect(x =>
            {
//					x.ReceiveFromNamedPipe(new Uri("net.pipe://localhost/pipe"), "test");

                x.AddConsumerOf <TestMessage>()
                .UsingConsumer(future.Complete);
            }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                {
                    typeof(ChannelAdapter),
                    typeof(BroadcastChannel),
                    typeof(TypedChannelAdapter <TestMessage>),
                    typeof(ConsumerChannel <TestMessage>),
                });
            }
        }
예제 #19
0
		public void Should_support_single_channels()
		{
			var input = new ChannelAdapter();
			using (input.Connect(x =>
				{
					x.AddConsumerOf<UpdateValue>()
						.UsingInstance()
						.Of<TestInstance>()
						.DistributedBy(m => m.Id)
						.PersistUsingNHibernate()
						.UsingSessionProvider(m => (ISession)null)
						.OnChannel(m => m.UpdateValueChannel)
						.CreateNewInstanceBy(m => new TestInstance(m.Id));
				}))
			{
				input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
					{
						typeof(ChannelAdapter),
						typeof(BroadcastChannel),
						typeof(TypedChannelAdapter<UpdateValue>),
						typeof(InstanceChannel<UpdateValue>),
					});
			}
		}
예제 #20
0
        public void Should_be_an_interval_consumer_on_the_channel()
        {
            var future = new Future<int>();

            var input = new ChannelAdapter();
            int expected = 5;
            using (input.Connect(x =>
                {
                    x.AddConsumerOf<TestMessage>()
                        .BufferFor(2.Seconds())
                        .UsingConsumer(message =>
                            {
                                future.Complete(message.Count);
                            })
                        .ExecuteOnProducerThread();
                }))
            {
                for (int i = 0; i < expected; i++)
                    input.Send(new TestMessage());

                future.WaitUntilCompleted(6.Seconds()).ShouldBeTrue();
                future.Value.ShouldEqual(expected);

                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(TypedChannelAdapter<TestMessage>),
                        typeof(IntervalChannel<TestMessage>),
                        typeof(ConsumerChannel<ICollection<TestMessage>>),
                    });
            }
        }
예제 #21
0
        public void Should_be_two_consumers_on_the_channel()
        {
            SelectiveConsumer<TestMessage> selectiveConsumer = x => y => { };

            var input = new ChannelAdapter();
            using (input.Connect(x =>
                {
                    x.AddConsumerOf<TestMessage>()
                        .UsingConsumer(message => { });

                    x.AddConsumerOf<TestMessage>()
                        .UsingSelectiveConsumer(selectiveConsumer);
                }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(TypedChannelAdapter<TestMessage>),
                        typeof(BroadcastChannel<TestMessage>),
                        typeof(ConsumerChannel<TestMessage>),
                        typeof(SelectiveConsumerChannel<TestMessage>),
                    });
            }
        }
예제 #22
0
 public void Should_include_the_filter_channel()
 {
     var input = new ChannelAdapter();
     using (input.Connect(x =>
         {
             x.AddConsumerOf<TestMessage>()
                 .Where(message => message.Value == 47)
                 .UsingConsumer(message => { });
         }))
     {
         input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
             {
                 typeof(ChannelAdapter),
                 typeof(BroadcastChannel),
                 typeof(TypedChannelAdapter<TestMessage>),
                 typeof(FilterChannel<TestMessage>),
                 typeof(ConsumerChannel<TestMessage>)
             });
     }
 }
예제 #23
0
 public void Should_subscribe_the_last_message_consumer()
 {
     var input = new ChannelAdapter();
     using (input.Connect(x =>
         {
             x.AddConsumerOf<TestMessage>()
                 .BufferFor(2.Seconds())
                 .HandleOnCallingThread()
                 .Last()
                 .HandleOnCallingThread()
                 .UsingConsumer(message =>
                     {
                     })
                 .HandleOnCallingThread();
         }))
     {
         input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
             {
                 typeof(ChannelAdapter),
                 typeof(BroadcastChannel),
                 typeof(TypedChannelAdapter<TestMessage>),
                 typeof(IntervalChannel<TestMessage>),
                 typeof(LastChannel<TestMessage>),
                 typeof(ConsumerChannel<TestMessage>),
             });
     }
 }
예제 #24
0
 public void Should_be_an_empty_channel_adapter_with_no_consumers()
 {
     var input = new ChannelAdapter();
     using (input.Connect(x => { }))
     {
         input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
             {
                 typeof(ChannelAdapter),
                 typeof(ShuntChannel)
             });
     }
 }