public void simple_scenario_when_there_are_already_events_queued_up()
        {
            theChannel.Write(q => q.Write(e1, e2, e3));

            theWriter.ConnectedTest = () => !theWriter.Events.Contains(e3);

            var task = theChannelWriter.Write(theTopic);

            task.Wait(150).ShouldBeTrue();

            theWriter.Events.ShouldHaveTheSameElementsAs(e1, e2, e3);
        }
示例#2
0
文件: Program.cs 项目: Erhannis/Jibu
        public override void Run()
        {
            try
            {
                // we use a Choice to listen
                // on the Channel.
                Choice choice = new Choice(customers);

                switch (choice.TryFairSelect())
                {
                case 0:
                    // We got a seat => sit down
                    customers.Write(this);
                    break;

                case -1:
                    // no seats => leave shop
                    LeaveShop();
                    break;
                }
            }
            catch (PoisonException)
            {
                // if the channel has been
                // poisoned the shop must be closed
                Console.WriteLine(name + ": Too late! Shop is closed.");
            }
        }
示例#3
0
 public override void Run()
 {
     while (true)
     {
         Timer.SleepFor(rand.Next(1000 + rand.Next(2000)));
         infoChannel.Write(new Tuple <int, int, string>(rand.Next(100), rand.Next(100), "customer "
                                                        + customerCounter));
         customerCounter++;
     }
 }
示例#4
0
文件: Taxi.cs 项目: Erhannis/Jibu
        public override void Run()
        {
            Tuple <int, int, string> fare;

            while (true)
            {
                fare = customerInfoChannel.Read();
                DriveToDestination();
                Console.WriteLine("Delivered " + fare.Third);
                ackChannel.Write(fare.Third);
            }
        }
        protected override void WriteBody(XmlWriter writer)
        {
            // Any fixtures based on this template should be cloned instances with
            // no data, so there shouldn't be any data persisted when this is done.
            ChannelWriter channelWriter = new ChannelWriter();

            writer.WriteStartElement("Channels");
            foreach (Channel channel in Channels)
            {
                channelWriter.Channel = channel;
                channelWriter.Write(writer);
            }
            writer.WriteEndElement();             // Channels
        }
        public void sends_initialization_events_then_events_following_last_initial_event_id()
        {
            theChannel.Write(q => q.Write(e1, e2, e3, e4, e5));
            theInitializer = new TestChannelInitializer(ie1, ie2, ie3);

            theChannelWriter = new ChannelWriter <FakeTopic>(theWriter, theWriter, theCache, theInitializer);

            theWriter.ConnectedTest = () => !theWriter.Events.Contains(e5);

            var task = theChannelWriter.Write(theTopic);

            task.Wait(150).ShouldBeTrue();

            theWriter.Events.ShouldHaveTheSameElementsAs(ie1, ie2, ie3, e4, e5);
        }
        public void parent_task_is_faulted_when_channel_initializer_fails()
        {
            theInitializer   = new FailingTestChannelInitializer();
            theChannelWriter = new ChannelWriter <FakeTopic>(theWriter, theWriter, theCache, theInitializer);

            var testTask = new Task(() => theChannelWriter.Write(theTopic));

            testTask.RunSynchronously();
            testTask.IsFaulted.ShouldBeTrue();

            var exceptions = testTask.Exception.Flatten().InnerExceptions;

            exceptions.Count.ShouldBe(1);
            exceptions[0].Message.ShouldBe(FailingTestChannelInitializer.ExceptionMessage);
        }
        public void failure_to_acquire_channel_terminates_without_errors()
        {
            theWriter = new RecordingServerEventWriter();

            var cache = MockRepository.GenerateMock <ITopicChannelCache>();
            ITopicChannel <FakeTopic> channel = new TopicChannel <FakeTopic>(new EventQueue <FakeTopic>());

            theChannel = channel.Channel;
            theTopic   = new FakeTopic();

            cache.Stub(x => x.TryGetChannelFor(theTopic, out channel)).Return(false);

            theChannelWriter = new ChannelWriter <FakeTopic>(theWriter, theWriter, cache, theInitializer);
            var task = theChannelWriter.Write(theTopic);

            task.Wait(150).ShouldBeTrue();
        }