public void Sending_a_bid_request_should_get_a_response() { var response = new FutureChannel<Response<Status>>(); UntypedChannel responseChannel = new ChannelAdapter(); responseChannel.Connect(x => x.AddChannel(response)); Auction.Request(new Ask(Id), responseChannel); response.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.Body.AuctionId.ShouldEqual(Id); // ThreadUtil.Sleep(2.Seconds()); // go ahead and buy something var purchased = new FutureChannel<Response<Purchased>>(); responseChannel.Connect(x => x.AddChannel(purchased)); Auction.Request(new Buy { Quantity = 15, Token = response.Value.Body.Token }, responseChannel); purchased.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for purchase"); purchased.Value.Body.Quantity.ShouldEqual(15); purchased.Value.Body.Price.ShouldEqual(response.Value.Body.CurrentBid); }
public void Sending_a_bid_request_should_get_a_response() { var response = new FutureChannel <Response <Status> >(); UntypedChannel responseChannel = new ChannelAdapter(); responseChannel.Connect(x => x.AddChannel(response)); Auction.Request(new Ask(Id), responseChannel); response.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for response"); response.Value.Body.AuctionId.ShouldEqual(Id); // ThreadUtil.Sleep(2.Seconds()); // go ahead and buy something var purchased = new FutureChannel <Response <Purchased> >(); responseChannel.Connect(x => x.AddChannel(purchased)); Auction.Request(new Buy { Quantity = 15, Token = response.Value.Body.Token }, responseChannel); purchased.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for purchase"); purchased.Value.Body.Quantity.ShouldEqual(15); purchased.Value.Body.Price.ShouldEqual(response.Value.Body.CurrentBid); }
public void A_request_is_sent_via_wcf() { _pipeUri = new Uri("net.pipe://localhost/pipe"); _response = new Future<Response<TestMessage>>(); _client = new ChannelAdapter(); _clientConnection = _client.Connect(x => { x.SendToWcfChannel(_pipeUri, _pipeName) .HandleOnCallingThread(); x.AddConsumerOf<Response<TestMessage>>() .UsingConsumer(_response.Complete); }); _server = new ChannelAdapter(); _serverConnection = _server.Connect(x => { x.ReceiveFromWcfChannel(_pipeUri, _pipeName); x.AddConsumerOf<Request<TestMessage>>() .UsingConsumer(request => request.Respond(request.Body)); }); }
public void Sending_a_message_to_an_nhibernate_instance_channel() { _newValue = new Random().Next(1, 500000) / 100m; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.CreateQuery("Delete TestInstance").ExecuteUpdate(); session.Save(new TestInstance(27)); transaction.Commit(); } var input = new ChannelAdapter(); using (input.Connect(x => { x.AddConsumerOf <UpdateValue>() .UsingInstance() .Of <TestInstance>() .HandleOnCallingThread() .DistributedBy(msg => msg.Id) .PersistUsingNHibernate() .UsingSessionProvider(m => SessionFactory.OpenSession()) .OnChannel(m => m.UpdateValueChannel) .CreateNewInstanceBy(m => new TestInstance(m.Id)); })) { // input.Send(new UpdateValue(27, _newValue)); } }
public void EstablishContext() { using (var startEvent = new ManualResetEvent(false)) { _srv = new TestService(); _channelAdaptor = new ChannelAdapter(); _hostChannel = WellknownAddresses.GetServiceCoordinatorHost(_channelAdaptor); using (_channelAdaptor.Connect(config => config.AddConsumerOf<ServiceStarted>().UsingConsumer(msg => startEvent.Set()))) { ServiceConfigurator<TestService> c = new ServiceConfigurator<TestService>(); c.WhenStarted(s => s.Start()); c.WhenStopped(s => s.Stop()); c.WhenPaused(s => { _wasPaused = true; }); c.WhenContinued(s => { _wasContinued = true; }); c.HowToBuildService(name => _srv); _serviceController = c.Create(WellknownAddresses.GetServiceCoordinatorProxy()); _serviceController.Start(); startEvent.WaitOne(5.Seconds()); _serviceController.State.ShouldEqual(ServiceState.Started); } } }
public void Should_properly_arrive_at_the_destination() { var serviceUri = new Uri("net.pipe://localhost/pipe"); string pipeName = "test"; var future = new Future<TestMessage>(); var message = new TestMessage { Id = Guid.NewGuid(), Name = "Alpha", }; UntypedChannel adapter = new ChannelAdapter(); using (var remote = new WcfChannelHost(new SynchronousFiber(), adapter, serviceUri, pipeName)) { using (adapter.Connect(x => { x.AddConsumerOf<TestMessage>() .UsingConsumer(m => future.Complete(m)); })) { var client = new WcfChannelProxy(new SynchronousFiber(), serviceUri, pipeName); client.Send(message); future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue(); } } future.Value.ShouldNotBeNull(); future.Value.ShouldEqual(message); future.Value.ShouldNotBeTheSameAs(message); }
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_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>), }); } }
/// <summary> /// Creates a PollingFileSystemEventProducer /// </summary> /// <param name="directory">The directory to watch</param> /// <param name="channel">The channel where events should be sent</param> /// <param name="scheduler">Event scheduler</param> /// <param name="fiber">Fiber to schedule on</param> /// <param name="checkInterval">The maximal time between events or polls on a given file</param> /// <param name="checkSubDirectory">Indicates if subdirectorys will be checked or ignored</param> public PollingFileSystemEventProducer(string directory, UntypedChannel channel, [NotNull] Scheduler scheduler, Fiber fiber, TimeSpan checkInterval, bool checkSubDirectory) { if (scheduler == null) { throw new ArgumentNullException("scheduler"); } _directory = directory; _channel = channel; _fiber = fiber; _hashes = new Dictionary <string, Guid>(); _scheduler = scheduler; _checkInterval = checkInterval; _scheduledAction = scheduler.Schedule(3.Seconds(), _fiber, HashFileSystem); var myChannel = new ChannelAdapter(); _connection = myChannel.Connect(connectionConfigurator => { connectionConfigurator.AddConsumerOf <FileSystemChanged>().UsingConsumer(HandleFileSystemChangedAndCreated); connectionConfigurator.AddConsumerOf <FileSystemCreated>().UsingConsumer(HandleFileSystemChangedAndCreated); connectionConfigurator.AddConsumerOf <FileSystemRenamed>().UsingConsumer(HandleFileSystemRenamed); connectionConfigurator.AddConsumerOf <FileSystemDeleted>().UsingConsumer(HandleFileSystemDeleted); }); _fileSystemEventProducer = new FileSystemEventProducer(directory, myChannel, checkSubDirectory); }
public TResponse MakeRequest <TRequest, TResponse>(TRequest message) where TRequest : CashboxMessage { var response = new Magnum.Future <object>(); var channel = new ChannelAdapter(); Exception ex = null; using (channel.Connect(config => { config.AddConsumerOf <ReturnValue>() .UsingConsumer(msg => response.Complete(msg.Value)); config.AddConsumerOf <ReturnException>() .UsingConsumer(msg => ex = msg.Exception); })) { _input.Request(message, channel); if (!response.WaitUntilCompleted(TimeSpan.FromSeconds(180)) && ex != null) { throw ex; } if (response.Value == null) { return(default(TResponse)); } return((TResponse)response.Value); } }
public void Should_properly_arrive_at_the_destination() { var serviceUri = new Uri("net.pipe://localhost/pipe"); string pipeName = "test"; var future = new Future <TestMessage>(); var message = new TestMessage { Id = Guid.NewGuid(), Name = "Alpha", }; UntypedChannel adapter = new ChannelAdapter(); using (var remote = new WcfChannelHost(new SynchronousFiber(), adapter, serviceUri, pipeName)) { using (adapter.Connect(x => { x.AddConsumerOf <TestMessage>() .UsingConsumer(m => future.Complete(m)); })) { var client = new WcfChannelProxy(new SynchronousFiber(), serviceUri, pipeName); client.Send(message); future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue(); } } future.Value.ShouldNotBeNull(); future.Value.ShouldEqual(message); future.Value.ShouldNotBeTheSameAs(message); }
public void A_file_is_created() { _baseDirectory = AppDomain.CurrentDomain.BaseDirectory; _filename = "test2.dat"; _path = Path.Combine(_baseDirectory, _filename); System.IO.File.Delete(_path); _listener = new Future<FileCreated>(); _channel = new ChannelAdapter(); FiberFactory fiberFactory = () => new SynchronousFiber(); _scheduler = new TimerScheduler(fiberFactory()); _producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, fiberFactory(), 20.Seconds()); Thread.Sleep(5.Seconds()); using (_channel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(m => _listener.Complete(m)))) { System.IO.File.Create(_path); _listener.WaitUntilCompleted(25.Seconds()); } _producer.Dispose(); }
public void Should_property_adapt_itself_to_a_channel_network() { TraceLogger.Configure(LogLevel.Debug); ILogger log = Logger.GetLogger<Sending_a_message_through_a_wcf_channel>(); log.Debug("Starting"); var serviceUri = new Uri("net.pipe://localhost/Pipe"); string pipeName = "Test"; Channel<TestMessage> adapter = new ChannelAdapter<TestMessage>(); using (var host = new WcfChannelHost<TestMessage>(adapter, serviceUri, pipeName)) { log.Debug("Host started"); var future = new Future<TestMessage>(); using (adapter.Connect(x => { x.AddConsumer(m => { log.Debug(l => l.Write("Received: {0}", m.Value)); future.Complete(m); }); })) { var client = new WcfChannelProxy<TestMessage>(new SynchronousFiber(), serviceUri, pipeName); log.Debug("Client started"); client.Send(new TestMessage("Hello!")); future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue(); log.Debug("Complete"); } } }
public void Sending_messages_to_an_instance_stored_using_nhibernate() { var input = new ChannelAdapter(); using (input.Connect(x => { })) ; }
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>), }); } }
/// <summary> /// Creates a PollingFileSystemEventProducer /// </summary> /// <param name="directory">The directory to watch</param> /// <param name="channel">The channel where events should be sent</param> /// <param name="scheduler">Event scheduler</param> /// <param name="fiber">Fiber to schedule on</param> /// <param name="checkInterval">The maximal time between events or polls on a given file</param> /// <param name="checkSubDirectory">Indicates if subdirectorys will be checked or ignored</param> public PollingFileSystemEventProducer(string directory, UntypedChannel channel, [NotNull] Scheduler scheduler, Fiber fiber, TimeSpan checkInterval, bool checkSubDirectory) { if (scheduler == null) throw new ArgumentNullException("scheduler"); _directory = directory; _channel = channel; _fiber = fiber; _hashes = new Dictionary<string, Guid>(); _scheduler = scheduler; _checkInterval = checkInterval; _scheduledAction = scheduler.Schedule(3.Seconds(), _fiber, HashFileSystem); var myChannel = new ChannelAdapter(); _connection = myChannel.Connect(connectionConfigurator => { connectionConfigurator.AddConsumerOf<FileSystemChanged>().UsingConsumer(HandleFileSystemChangedAndCreated); connectionConfigurator.AddConsumerOf<FileSystemCreated>().UsingConsumer(HandleFileSystemChangedAndCreated); connectionConfigurator.AddConsumerOf<FileSystemRenamed>().UsingConsumer(HandleFileSystemRenamed); connectionConfigurator.AddConsumerOf<FileSystemDeleted>().UsingConsumer(HandleFileSystemDeleted); }); _fileSystemEventProducer = new FileSystemEventProducer(directory, myChannel, checkSubDirectory); }
public void Starting_a_socket_server() { TraceLogger.Configure(LogLevel.Debug); _startingEventReceived = new Future <ServerStarting>(); _runningEventReceived = new Future <ServerRunning>(); _input = new ChannelAdapter(); _connection = _input.Connect(x => { x.AddConsumerOf <ServerStarting>() .UsingConsumer(_startingEventReceived.Complete) .HandleOnCallingThread(); x.AddConsumerOf <ServerRunning>() .UsingConsumer(_runningEventReceived.Complete) .HandleOnCallingThread(); }); ServerUri = new Uri("http://localhost:8008/Topshelf"); _server = new HttpServer(ServerUri, new ThreadPoolFiber(), _input, new[] { new VersionConnectionHandler(), }); _server.Start(); }
public void Sending_a_message_to_an_nhibernate_instance_channel() { _newValue = new Random().Next(1, 500000)/100m; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.CreateQuery("Delete TestInstance").ExecuteUpdate(); session.Save(new TestInstance(27)); transaction.Commit(); } var input = new ChannelAdapter(); using (input.Connect(x => { x.AddConsumerOf<UpdateValue>() .UsingInstance() .Of<TestInstance>() .HandleOnCallingThread() .DistributedBy(msg => msg.Id) .PersistUsingNHibernate() .UsingSessionProvider(m => SessionFactory.OpenSession()) .OnChannel(m => m.UpdateValueChannel) .CreateNewInstanceBy(m => new TestInstance(m.Id)); })) { // input.Send(new UpdateValue(27, _newValue)); } }
public void A_file_is_created() { _baseDirectory = AppDomain.CurrentDomain.BaseDirectory; _filename = "test2.dat"; _path = Path.Combine(_baseDirectory, _filename); System.IO.File.Delete(_path); _listener = new Future <FileCreated>(); _channel = new ChannelAdapter(); FiberFactory fiberFactory = () => new SynchronousFiber(); _scheduler = new TimerScheduler(fiberFactory()); _producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, fiberFactory(), 20.Seconds()); Thread.Sleep(5.Seconds()); using (_channel.Connect(x => x.AddConsumerOf <FileCreated>().UsingConsumer(m => _listener.Complete(m)))) { System.IO.File.Create(_path); _listener.WaitUntilCompleted(25.Seconds()); } _producer.Dispose(); }
public void A_request_is_sent_via_wcf() { _pipeUri = new Uri("net.pipe://localhost/pipe"); _response = new Future <Response <TestMessage> >(); _client = new ChannelAdapter(); _clientConnection = _client.Connect(x => { x.SendToWcfChannel(_pipeUri, _pipeName) .HandleOnCallingThread(); x.AddConsumerOf <Response <TestMessage> >() .UsingConsumer(_response.Complete); }); _server = new ChannelAdapter(); _serverConnection = _server.Connect(x => { x.AddConsumerOf <Request <TestMessage> >() .UsingConsumer(request => request.Respond(request.Body)); }); _host = new WcfChannelHost(new PoolFiber(), _server, _pipeUri, _pipeName); }
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(); } }
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(); } }
void CreateChannelNetwork() { _connectionChannel = new ChannelAdapter <ConnectionContext>(); _connectionChannelConnection = _connectionChannel.Connect(x => { var channelProvider = new HttpConnectionChannelProvider(_connectionHandlers); var threadPoolChannel = new ThreadPoolChannel <ConnectionContext>(channelProvider, _concurrentConnectionLimit); x.AddChannel(threadPoolChannel); }); }
public void Should_allow_the_selective_consumer_channel_type() { var input = new ChannelAdapter(); using (input.Connect(x => { x.AddConsumerOf <TestMessage>() .UsingSelectiveConsumer(message => m => { }); })) { } }
public void Should_allow_the_selective_consumer_channel_type() { var input = new ChannelAdapter(); using (input.Connect(x => { x.AddConsumerOf<TestMessage>() .UsingSelectiveConsumer(message => m => { }); })) { } }
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(); } }
public void Should_manage_interleaved_changes_the_the_chain() { var firstFuture = new Future <TestMessage>(); var secondFuture = new Future <TestMessage>(); var adapter = new ChannelAdapter <TestMessage>(new ShuntChannel <TestMessage>()); var first = new ConsumerChannel <TestMessage>(_fiber, firstFuture.Complete); var firstScope = adapter.Connect(x => x.AddChannel(first)); var second = new ConsumerChannel <TestMessage>(_fiber, secondFuture.Complete); var secondScope = adapter.Connect(x => x.AddChannel(second)); firstScope.Dispose(); new TraceChannelVisitor().Visit(adapter); adapter.Send(new TestMessage()); firstFuture.IsCompleted.ShouldBeFalse(); secondFuture.IsCompleted.ShouldBeTrue(); }
public void Should_allow_an_interval_channel_to_be_created() { var input = new ChannelAdapter(); using (input.Connect(x => { x.AddConsumerOf <TestMessage>() .BufferFor(15.Seconds()) .UsingConsumer(messages => { }); })) { } }
public void Should_allow_an_interval_channel_to_be_created() { var input = new ChannelAdapter(); using (input.Connect(x => { x.AddConsumerOf<TestMessage>() .BufferFor(15.Seconds()) .UsingConsumer(messages => { }); })) { } }
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) }); } }
public void A_message_is_sent_to_an_instance() { _auctionId = CombGuid.Generate(); _input = new ChannelAdapter(); _connection = _input.Connect(x => { x.AddConsumerOf <Bid>() .UsingInstance().Of <Auction>() .ObtainedBy(m => new Auction(m.AuctionId)) .OnChannel(auction => auction.BidChannel); }); }
public void A_message_is_sent_to_an_instance() { _auctionId = CombGuid.Generate(); _input = new ChannelAdapter(); _connection = _input.Connect(x => { x.AddConsumerOf<Bid>() .UsingInstance().Of<Auction>() .ObtainedBy(m => new Auction(m.AuctionId)) .OnChannel(auction => auction.BidChannel); }); }
public void Should_allow_the_consumer_channel_type() { var input = new ChannelAdapter(); using (input.Connect(x => { x.AddConsumerOf <TestMessage>() .OnCurrentSynchronizationContext() .UsingConsumer(message => { }) .HandleOnPoolFiber(); })) { } }
public void Should_allow_the_consumer_channel_type() { var input = new ChannelAdapter(); using (input.Connect(x => { x.AddConsumerOf<TestMessage>() .OnCurrentSynchronizationContext() .UsingConsumer(message => { }) .HandleOnPoolFiber(); })) { } }
public IDisposable Watch(string directoryToWatch, Action<Directory> actionToTake) { if (!System.IO.Directory.Exists(directoryToWatch)) System.IO.Directory.CreateDirectory(directoryToWatch); _actionToTake = actionToTake; _eventChannel = new ChannelAdapter(); _eventChannel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(ProcessNewFile)); _scheduler = new TimerScheduler(_fiberFactory()); _watcher = new PollingFileSystemEventProducer(directoryToWatch, _eventChannel, _scheduler, _fiberFactory(), 1.Seconds()); return _watcher; }
public void Identifies_changed_services_to_pipeline() { long count = 0; string baseDir = AppDomain.CurrentDomain.BaseDirectory; using (var manualResetEvent = new ManualResetEvent(false)) using (var dm = new DirectoryMonitor(".", _coordinator)) { var myChannel = new ChannelAdapter(); dm.Start(); myChannel.Connect(sc => sc.AddConsumerOf <ServiceFolderChanged>() .UsingConsumer(fsc => { if (fsc.ServiceName.Equals("bottle", StringComparison.OrdinalIgnoreCase)) { return; // gotta skip the bottle directory } long localCount = Interlocked.Increment(ref count); //Console.WriteLine(fsc.ShelfName); if (localCount % 2 == 0) { manualResetEvent.Set(); } })); //Console.WriteLine(baseDir); //Console.WriteLine("-- Directories"); Directory.CreateDirectory(Path.Combine(baseDir, "Service1")); Directory.CreateDirectory(Path.Combine(baseDir, "Service2")); manualResetEvent.WaitOne(15.Seconds()); count.ShouldEqual(2); manualResetEvent.Reset(); //Console.WriteLine("-- Files"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service1", "test.out")), "Testing stuff"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service2", "test.out")), "Testing stuff"); File.AppendAllText(Path.Combine(baseDir, Path.Combine("Service1", "test2.out")), "Testing stuff"); manualResetEvent.WaitOne(10.Seconds()); //Console.WriteLine("-- Done"); count.ShouldEqual(4); } }
public void Should_receive_the_response_message_type_of_declared_type() { var requestChannel = new ChannelAdapter(); requestChannel.Connect(x => { x.AddConsumerOf <Request <Simple> >() .UsingConsumer(request => request.Respond <Simple, Simple>(new SimpleImpl())) .HandleOnCallingThread(); }); requestChannel.Request <Simple>(_channel); _received.IsCompleted.ShouldBeTrue("Message was not received"); }
public void A_state_machine_is_connected_to_an_untyped_channel() { _instance = new SampleStateMachine(); _input = new ChannelAdapter(); _disconnect = _input.Connect(x => { // adds a single state machine instance to the channel via listeners x.AddConsumersFor <SampleStateMachine>() .UsingInstance(_instance) .HandleOnCallingThread(); }); _input.Send(new SampleStarted()); _input.Send(new SampleStopped()); }
public void Should_work_through_a_channel_network() { var received = new FutureChannel <Request <Simple> >(); UntypedChannel channel = new ChannelAdapter(); channel.Connect(x => x.AddChannel(received)); var simpleImpl = new SimpleImpl(); channel.Send(new RequestImpl <SimpleImpl>(null, simpleImpl)); received.IsCompleted.ShouldBeTrue(); received.Value.ShouldNotBeNull(); received.Value.Body.ShouldEqual(simpleImpl); }
public ServiceCoordinator(Action<IServiceCoordinator> beforeStartingServices, Action<IServiceCoordinator> beforeStart, Action<IServiceCoordinator> afterStop) { _beforeStartingServices = beforeStartingServices; _beforeStart = beforeStart; _afterStop = afterStop; _serviceConfigurators = new List<Func<IServiceController>>(); _myChannel = new ChannelAdapter(); _hostChannel = WellknownAddresses.GetHostHost(_myChannel); _myChannel.Connect(s => { s.AddConsumerOf<ShelfFault>().UsingConsumer(HandleServiceFault); s.AddConsumerOf<ServiceStarted>().UsingConsumer(msg => ServiceStartedAction.Invoke(msg)); }); }
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), }); } }
public void Should_remove_a_consumer_from_an_adapter_chain() { var adapter = new ChannelAdapter <TestMessage>(new ShuntChannel <TestMessage>()); var future = new Future <TestMessage>(); var consumer = new ConsumerChannel <TestMessage>(_fiber, future.Complete); using (ChannelConnection scope = adapter.Connect(x => x.AddChannel(consumer))) {} new TraceChannelVisitor().Visit(adapter); adapter.Send(new TestMessage()); future.IsCompleted.ShouldBeFalse(); }
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(); } }
public Auctioneer(Fiber fiber, Scheduler scheduler, ActorRepository <Seller, string> sellerRepository) { _fiber = fiber; _sellerRepository = sellerRepository; _registerSeller = new DefaultMailbox <RegisterSeller>(fiber, scheduler); _input = new ChannelAdapter(); _subscriptions = _input.Connect(x => { x.Consume <RegisterSeller>() .Using(message => _registerSeller.Send(message)); }); _registerSeller.Receive(OnRegisterSeller); }
public void Should_remove_my_consumer() { var input = new ChannelAdapter(); var futureA = new Future <TestMessage>(); var consumerA = new ConsumerChannel <TestMessage>(new SynchronousFiber(), futureA.Complete); using (ChannelConnection connection = input.Connect(x => x.AddChannel(consumerA))) { } new TraceChannelVisitor().Visit(input); input.Send(new TestMessage()); futureA.IsCompleted.ShouldBeFalse(); }
public IDisposable Watch(string directoryToWatch, Action<Directory> actionToTake) { _actionToTake = actionToTake; Func<Fiber> fiberFactory = () => new SynchronousFiber(); if (!System.IO.Directory.Exists(directoryToWatch)) System.IO.Directory.CreateDirectory(directoryToWatch); var eventChannel = new ChannelAdapter(); eventChannel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(ProcessNewFile)); Scheduler scheduler = new TimerScheduler(fiberFactory()); var watcher = new PollingFileSystemEventProducer(directoryToWatch, eventChannel, scheduler, fiberFactory(), 1.Seconds()); return watcher; }
public IDisposable Watch(string directoryToWatch, Action<Directory> actionToTake) { if (actionToTake == null) throw new ArgumentNullException("actionToTake"); _actionToTake = actionToTake; if (!_fileSystem.DirectoryExists(directoryToWatch)) _fileSystem.CreateDirectory(directoryToWatch); Func<Fiber> fiberFactory = () => new SynchronousFiber(); UntypedChannel eventChannel = new ChannelAdapter(); eventChannel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(ProcessNewFile)); Scheduler scheduler = new TimerScheduler(fiberFactory()); var watcher = new PollingFileSystemEventProducer(directoryToWatch, eventChannel, scheduler, fiberFactory(), 1.Seconds()); return watcher; }
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(); } }
public void Run() { var provider = new CommandLineValueProvider(); var buildUri = new UriBuilder("http://localhost:8008/MagnumBenchmark"); provider.GetValue("port", x => { buildUri.Port = int.Parse(x.ToString()); return true; }); provider.GetValue("path", x => { buildUri.Path = x.ToString(); return true; }); var input = new ChannelAdapter(); ChannelConnection connection = input.Connect(x => { x.AddConsumerOf<ServerEvent>() .OnCurrentSynchronizationContext() .UsingConsumer(m => Console.WriteLine("Server " + m.EventType)); }); var serverUri = buildUri.Uri; Console.WriteLine("Using server uri: " + serverUri); var server = new HttpServer(serverUri, new ThreadPoolFiber(), input, new[] { new VersionConnectionHandler(), }); server.Start(); Console.WriteLine("Started: press a key to shutdown"); Console.ReadKey(); server.Stop(); Console.WriteLine("Stopping server"); Console.ReadKey(); }
public void Should_add_a_consumer_to_an_empty_adapter_chain() { var adapter = new ChannelAdapter<TestMessage>(new ShuntChannel<TestMessage>()); var future = new Future<TestMessage>(); var consumer = new ConsumerChannel<TestMessage>(_fiber, future.Complete); using (ChannelConnection scope = adapter.Connect(x => { x.AddChannel(consumer); })) { new TraceChannelVisitor().Visit(adapter); adapter.Send(new TestMessage()); } future.IsCompleted.ShouldBeTrue(); }
public void Start() { // file system watcher will fail if directory isn't there, ensure it is if (!Directory.Exists(_baseDirectory)) Directory.CreateDirectory(_baseDirectory); _scheduler = new TimerScheduler(new PoolFiber()); _channel = new ChannelAdapter(); _producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, new PoolFiber(), 10.Minutes()); _connection = _channel.Connect(x => { x.AddConsumerOf<FileSystemEvent>() .UsingConsumer(msg => ScheduleFolderChangeNotification(GetChangedDirectory(msg.Path))) .HandleOnFiber(_fiber); }); }
public void Configuring_event_listeners_for_nhibernate() { _auditChannel = new ChannelAdapter(); _preUpdate = new Future<PreUpdateEvent<TestInstance>>(); _postUpdate = new Future<PostUpdateEvent<TestInstance>>(); _auditChannel.Connect(x => { x.AddConsumerOf<PreUpdateEvent<TestInstance>>() .UsingConsumer(_preUpdate.Complete) .HandleOnCallingThread(); x.AddConsumerOf<PostUpdateEvent<TestInstance>>() .UsingConsumer(_postUpdate.Complete) .HandleOnCallingThread(); }); ExtraConfiguration = cfg => { cfg.AddAuditEventListeners(_auditChannel); }; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.CreateQuery("Delete TestInstance").ExecuteUpdate(); session.Save(new TestInstance(27)); transaction.Commit(); } using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { var instance = session.Get<TestInstance>(27); instance.UpdateValueChannel.Send(new UpdateValue(27, 123.45m)); transaction.Commit(); } }
public void Should_return_the_event_types_for_the_configuration() { var network = new ChannelAdapter(); network.Connect(x => { x.AddConsumerOf<PostUpdateEvent<TestInstance>>() .UsingConsumer(msg => { }); }); var configurator = new PostUpdateEventConfigurator(); var visitor = new AuditEventConsumerChannelVisitor(new EventListenerConfigurator[] { configurator, }); visitor.Configure(network); configurator.Types.Count().ShouldEqual(1); configurator.Types.First().ShouldEqual(typeof(TestInstance)); }
public void Should_add_a_consumer_that_is_assignable_to_the_type() { var firstFuture = new Future<TestMessage>(); var secondFuture = new Future<ITestMessage>(); var first = new ConsumerChannel<TestMessage>(_fiber, firstFuture.Complete); var subs = new BroadcastChannel<TestMessage>(new[] {first}); var adapter = new ChannelAdapter<TestMessage>(subs); var second = new ConsumerChannel<ITestMessage>(_fiber, secondFuture.Complete); using (var scope = adapter.Connect(x => x.AddChannel(second))) { new TraceChannelVisitor().Visit(adapter); adapter.Send(new TestMessage()); } firstFuture.IsCompleted.ShouldBeTrue(); secondFuture.IsCompleted.ShouldBeTrue(); }
public void Configuring_event_listeners_for_nhibernate() { using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.CreateQuery("Delete TestInstance").ExecuteUpdate(); session.CreateQuery("Delete TestInstanceAudit").ExecuteUpdate(); transaction.Commit(); } _channel = new ChannelAdapter(); _connection = _channel.Connect(x => { x.AddConsumersFor<TestInstanceAudit>() .BindUsing<TestInstanceAuditBinding, AuditKey>() .HandleOnCallingThread() .CreateNewInstanceBy(id => new TestInstanceAudit(id)) .PersistUsingNHibernate() .UseSessionProvider(() => SessionFactory.OpenSession()); }); ResetSessionFactory(); ExtraConfiguration = cfg => { cfg.AddAuditEventListeners(_channel); }; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.CreateQuery("Delete TestInstance").ExecuteUpdate(); var instance = new TestInstance(27, 123.45m); session.Save(instance); instance = new TestInstance(37, 123.45m); session.Save(instance); instance = new TestInstance(47, 123.45m); session.Save(instance); transaction.Commit(); } }
public void Should_add_a_provider_based_consumer() { var input = new ChannelAdapter(); var futureA = new Future<TestMessage>(); var futureB = new Future<TestMessage>(); var futureC = new Future<TestMessage>(); TestConsumer.Future = futureA; using (input.Connect(x => { x.AddConsumerOf<TestMessage>() .UsingInstance().Of<TestConsumer>() .HandleOnCallingThread() .ObtainedBy(() => new TestConsumer()) .OnChannel(y => y.InputChannel); x.AddConsumerOf<TestMessage>() .UsingConsumer(futureB.Complete) .HandleOnCallingThread(); x.AddConsumerOf<TestMessage>() .UsingSelectiveConsumer(message => futureC.Complete) .HandleOnCallingThread(); })) { Trace.WriteLine("Complete network:"); new TraceChannelVisitor().Visit(input); input.Send(new TestMessage()); } Trace.WriteLine("Empty network:"); new TraceChannelVisitor().Visit(input); futureA.IsCompleted.ShouldBeTrue(); futureB.IsCompleted.ShouldBeTrue(); futureC.IsCompleted.ShouldBeTrue(); }
public void Starting_a_socket_server() { _startingEventReceived = new Future<ServerStarting>(); _runningEventReceived = new Future<ServerRunning>(); _input = new ChannelAdapter(); _connection = _input.Connect(x => { x.AddConsumerOf<ServerStarting>() .UsingConsumer(_startingEventReceived.Complete) .HandleOnCallingThread(); x.AddConsumerOf<ServerRunning>() .UsingConsumer(_runningEventReceived.Complete) .HandleOnCallingThread(); }); _uri = new Uri("tcp://0.0.0.0:8008"); _server = new SocketServer(_uri, _input); _server.Start(); }