예제 #1
0
        public async Task ShouldNotCacheContext()
        {
            var stringWriter = new StringWriter();

            var pipelineModifications = new PipelineModifications();

            pipelineModifications.Additions.Add(new Behavior1.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Stage1.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Behavior2.Registration(stringWriter));
            pipelineModifications.Additions.Add(new StageFork.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Stage2.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Terminator.Registration(stringWriter));

            var pipeline = new Pipeline <ITransportReceiveContext>(new FakeBuilder(), new SettingsHolder(), pipelineModifications);

            stringWriter.WriteLine("Run 1");

            var context = new TestableTransportReceiveContext();

            context.Extensions.Set <IPipelineCache>(new FakePipelineCache());
            context.Extensions.Set(ExtendableExtensions.RunSpecificKey, 1);

            await pipeline.Invoke(context);

            stringWriter.WriteLine("Run 2");

            context = new TestableTransportReceiveContext();
            context.Extensions.Set <IPipelineCache>(new FakePipelineCache());
            context.Extensions.Set(ExtendableExtensions.RunSpecificKey, 2);

            await pipeline.Invoke(context);

            Approvals.Verify(stringWriter.ToString());
        }
예제 #2
0
        public async Task ShouldExecutePipeline()
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                Assert.Ignore("ApprovalTests only works on Windows");
            }

            var stringWriter = new StringWriter();

            var pipelineModifications = new PipelineModifications();

            pipelineModifications.Additions.Add(new Behavior1.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Stage1.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Behavior2.Registration(stringWriter));
            pipelineModifications.Additions.Add(new StageFork.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Stage2.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Terminator.Registration(stringWriter));

            var pipeline = new Pipeline <ITransportReceiveContext>(new FakeBuilder(), pipelineModifications);

            var context = new TestableTransportReceiveContext();

            context.Extensions.Set <IPipelineCache>(new FakePipelineCache());

            await pipeline.Invoke(context);

            TestApprover.Verify(stringWriter.ToString());
        }
예제 #3
0
        public async Task ShouldCacheExecutionFunc()
        {
            var stringWriter = new StringWriter();

            var pipelineModifications = new PipelineModifications();

            pipelineModifications.Additions.Add(new Behavior1.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Stage1.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Behavior2.Registration(stringWriter));
            pipelineModifications.Additions.Add(new StageFork.Registration(stringWriter));

            var pipeline = new Pipeline <ITransportReceiveContext>(new FakeBuilder(), new SettingsHolder(), pipelineModifications);

            var context = new TestableTransportReceiveContext();

            context.Extensions.Set <IPipelineCache>(new FakePipelineCache());

            var stopwatch = Stopwatch.StartNew();
            await pipeline.Invoke(context);

            stopwatch.Stop();

            var firstRunTicks = stopwatch.ElapsedTicks;

            var runs = new List <long>();

            for (var i = 0; i < 100; i++)
            {
                stopwatch = Stopwatch.StartNew();
                await pipeline.Invoke(context);

                stopwatch.Stop();
                runs.Add(stopwatch.ElapsedTicks);
            }

            var average = runs.Average();

            Assert.That(average, Is.LessThan(firstRunTicks / 5));
        }
예제 #4
0
        public async Task ShouldExecutePipeline()
        {
            var stringWriter = new StringWriter();

            var pipelineModifications = new PipelineModifications();

            pipelineModifications.Additions.Add(new Behavior1.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Stage1.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Behavior2.Registration(stringWriter));
            pipelineModifications.Additions.Add(new StageFork.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Stage2.Registration(stringWriter));
            pipelineModifications.Additions.Add(new Terminator.Registration(stringWriter));

            var pipeline = new Pipeline <ITransportReceiveContext>(new ServiceCollection().BuildServiceProvider(), pipelineModifications);

            var context = new TestableTransportReceiveContext();

            context.Extensions.Set <IPipelineCache>(new FakePipelineCache());

            await pipeline.Invoke(context);

            Approver.Verify(stringWriter.ToString());
        }
예제 #5
0
        public void SetUp()
        {
            LicenseManager.InitializeLicense();
            transportDefinition = new MsmqTransport();

            settings = new SettingsHolder();

            settings.SetDefault("EndpointName", "TestEndpoint");
            settings.SetDefault("Endpoint.SendOnly", false);
            settings.SetDefault("MasterNode.Address", MasterNodeAddress);
            pipelineModifications = new PipelineModifications();
            settings.Set <PipelineModifications>(pipelineModifications);

            ApplyPipelineModifications();

            Transport   = new FakeTransport();
            FuncBuilder = new FuncBuilder();

            FuncBuilder.Register <ReadOnlySettings>(() => settings);

            router = new StaticMessageRouter(KnownMessageTypes());
            var conventions = new Conventions();

            handlerRegistry         = new MessageHandlerRegistry(conventions);
            MessageMetadataRegistry = new MessageMetadataRegistry(false, conventions);
            MessageSerializer       = new XmlMessageSerializer(MessageMapper, conventions);

            messageSender       = MockRepository.GenerateStub <ISendMessages>();
            subscriptionStorage = new FakeSubscriptionStorage();
            configure           = new Configure(settings, FuncBuilder, new List <Action <IConfigureComponents> >(), new PipelineSettings(null))
            {
                localAddress = Address.Parse("TestEndpoint")
            };

            subscriptionManager = new SubscriptionManager
            {
                MessageSender       = messageSender,
                SubscriptionStorage = subscriptionStorage,
                Configure           = configure
            };

            pipelineFactory = new PipelineExecutor(settings, FuncBuilder);

            FuncBuilder.Register <IMessageSerializer>(() => MessageSerializer);
            FuncBuilder.Register <ISendMessages>(() => messageSender);

            FuncBuilder.Register <LogicalMessageFactory>(() => new LogicalMessageFactory(MessageMetadataRegistry, MessageMapper, pipelineFactory));

            FuncBuilder.Register <IManageSubscriptions>(() => subscriptionManager);
            FuncBuilder.Register <EstimatedTimeToSLABreachCalculator>(() => SLABreachCalculator);
            FuncBuilder.Register <MessageMetadataRegistry>(() => MessageMetadataRegistry);

            FuncBuilder.Register <IMessageHandlerRegistry>(() => handlerRegistry);
            FuncBuilder.Register <IMessageMapper>(() => MessageMapper);

            FuncBuilder.Register <DeserializeLogicalMessagesBehavior>(() => new DeserializeLogicalMessagesBehavior
            {
                MessageSerializer       = MessageSerializer,
                MessageMetadataRegistry = MessageMetadataRegistry,
            });

            FuncBuilder.Register <CreatePhysicalMessageBehavior>(() => new CreatePhysicalMessageBehavior());
            FuncBuilder.Register <PipelineExecutor>(() => pipelineFactory);
            FuncBuilder.Register <TransportDefinition>(() => transportDefinition);

            var messagePublisher = new StorageDrivenPublisher
            {
                MessageSender       = messageSender,
                SubscriptionStorage = subscriptionStorage
            };

            var deferrer = new TimeoutManagerDeferrer
            {
                MessageSender         = messageSender,
                TimeoutManagerAddress = MasterNodeAddress.SubScope("Timeouts"),
                Configure             = configure,
            };

            FuncBuilder.Register <IDeferMessages>(() => deferrer);
            FuncBuilder.Register <IPublishMessages>(() => messagePublisher);

            bus = new UnicastBus
            {
                Builder             = FuncBuilder,
                MessageSender       = messageSender,
                Transport           = Transport,
                MessageMapper       = MessageMapper,
                SubscriptionManager = subscriptionManager,
                MessageRouter       = router,
                Settings            = settings,
                Configure           = configure,
                HostInformation     = new HostInformation(Guid.NewGuid(), "HelloWorld")
            };

            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => new CausationMutator {
                Bus = bus
            });
            FuncBuilder.Register <IBus>(() => bus);
            FuncBuilder.Register <UnicastBus>(() => bus);
            FuncBuilder.Register <Conventions>(() => conventions);
            FuncBuilder.Register <Configure>(() => configure);
        }