public void TransportDeadThenAliveTest()
        {
            IMemcacheNode theNode   = null;
            FakeTransport transport = new FakeTransport();

            transport.Kill();

            // Memcache client config
            var config = new MemcacheClientConfiguration
            {
                DeadTimeout      = TimeSpan.FromSeconds(1),
                TransportFactory = transport.Factory,
                NodeFactory      = (e, c) => MemcacheClientConfiguration.DefaultNodeFactory(e, c),
                PoolSize         = 1,
            };

            theNode = config.NodeFactory(null, config);
            Assert.IsFalse(theNode.IsDead, "The node should be alive before any failure");

            Assert.IsFalse(theNode.TrySend(null, 1), "The TrySend should fail with a broken transport");
            Assert.IsTrue(theNode.IsDead, "The node should be dead after the first send failed");

            transport.Resurect();
            Assert.IsFalse(theNode.IsDead, "The node should be alive after the transport resurected");
            Assert.IsTrue(theNode.TrySend(null, 1), "The TrySend should be able to send a request after the transport is up again");

            transport.Kill();
            Assert.IsFalse(theNode.TrySend(null, 1), "The TrySend should fail with a killed transport");
            Assert.IsTrue(theNode.IsDead, "The node should be dead after the a send failed");
        }
示例#2
0
        public async Task EnvelopeReachesInnerTransport()
        {
            // Arrange
            using var cacheDirectory = new TempDirectory();
            var options = new SentryOptions
            {
                DiagnosticLogger   = _logger,
                CacheDirectoryPath = cacheDirectory.Path
            };

            using var innerTransport  = new FakeTransport();
            await using var transport = new CachingTransport(innerTransport, options);

            // Act
            using var envelope = Envelope.FromEvent(new SentryEvent());
            await transport.SendEnvelopeAsync(envelope);

            while (!innerTransport.GetSentEnvelopes().Any())
            {
                await Task.Delay(100);
            }

            // Assert
            var sentEnvelope = innerTransport.GetSentEnvelopes().Single();

            sentEnvelope.Should().BeEquivalentTo(envelope, o => o.Excluding(x => x.Items[0].Header));
        }
示例#3
0
    public async Task WorksInBackground()
    {
        // Arrange
        using var cacheDirectory = new TempDirectory();
        var options = new SentryOptions
        {
            Dsn = DsnSamples.ValidDsnWithoutSecret,
            DiagnosticLogger   = _logger,
            CacheDirectoryPath = cacheDirectory.Path
        };

        using var innerTransport  = new FakeTransport();
        await using var transport = new CachingTransport(innerTransport, options);

        // Act
        using var envelope = Envelope.FromEvent(new SentryEvent());
        await transport.SendEnvelopeAsync(envelope);

        // Wait until directory is empty
        while (Directory.EnumerateFiles(cacheDirectory.Path, "*", SearchOption.AllDirectories).Any())
        {
            await Task.Delay(100);
        }

        // Assert
        var sentEnvelope = innerTransport.GetSentEnvelopes().Single();

        sentEnvelope.Should().BeEquivalentTo(envelope, o => o.Excluding(x => x.Items[0].Header));
    }
        public async Task DoAsync_ConsumesRequests_WhenRequestsAvailable()
        {
            var transport  = new FakeTransport(100);
            var dispatcher = new FakeDispatcher();
            var cqrs       = new CqrsStrategy(new RequestTypeFinder(new[] { typeof(FakeCommand) }))
            {
                Dispatcher = dispatcher, Formatter = new JsonRequestContentFormatter()
            };
            var orchestrator = new EngineBuilder(options =>
            {
                options.Warps                      = 5;
                options.RequestsPerWarp            = 5;
                options.RunRequestsInWarpAllAtOnce = true;
                options.SlidingStep                = TimeSpan.FromMilliseconds(10);
            })
                               .ReceiveRequestsFrom(r => r.Add(transport))
                               .Finally(cqrs)
                               .BuildOrchestrator();

            await orchestrator.StartAsync();

            var completed = await transport.Complete();

            await orchestrator.StopAsync(TimeSpan.Zero);

            Assert.Equal(100, dispatcher.CallCounter);
            Assert.Equal(100, completed);
        }
示例#5
0
 public EndpointThatThrowsOnInfrastructureStop()
 {
     EndpointSetup <DefaultServer>(builder =>
     {
         var fakeTransport = new FakeTransport();
         fakeTransport.RaiseExceptionOnTransportDispose(new InvalidOperationException("ExceptionInInfrastructureStop"));
         builder.UseTransport(fakeTransport);
     });
 }
 public Endpoint()
 {
     EndpointSetup <DefaultServer, Context>((endpointConfig, context) =>
     {
         var fakeTransport       = new FakeTransport();
         context.StartUpSequence = fakeTransport.StartupSequence;
         endpointConfig.UseTransport(fakeTransport);
     });
 }
 public EndpointThatThrowsOnPumpStop()
 {
     EndpointSetup <DefaultServer>(builder =>
     {
         var fakeTransport = new FakeTransport();
         fakeTransport.RaiseExceptionOnReceiverStop(new InvalidOperationException("ExceptionInPumpStop"));
         builder.UseTransport(fakeTransport);
     });
 }
        public void ItShouldBeAbleToSendMessagesOfArbitraryLength(char ch, int count)
        {
            var config = new StatsDConfiguration
            {
                Host = "127.0.0.1"
            };

            var fakeTransport = new FakeTransport();
            var publisher     = new BufferBasedStatsDPublisher(config, fakeTransport);

            publisher.Increment(new string(ch, count));
            fakeTransport.TimesCalled.ShouldBe(1);
        }
        public void SetUp()
        {
            Transport   = new FakeTransport();
            FuncBuilder = new FuncBuilder();
            Configure.GetEndpointNameAction = () => "TestEndpoint";
            const string localAddress = "endpointA";

            MasterNodeAddress = new Address(localAddress, "MasterNode");

            try
            {
                Address.InitializeLocalAddress(localAddress);
            }
            catch // intentional
            {
            }

            MessageSerializer = new XmlMessageSerializer(MessageMapper);
            ExtensionMethods.GetStaticOutgoingHeadersAction = () => MessageHeaderManager.staticHeaders;
            gatewayAddress = MasterNodeAddress.SubScope("gateway");

            messageSender = MockRepository.GenerateStub <ISendMessages>();

            subscriptionStorage = new FakeSubscriptionStorage();
            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => headerManager);
            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => new SentTimeMutator());
            FuncBuilder.Register <DefaultDispatcherFactory>(() => new DefaultDispatcherFactory());
            FuncBuilder.Register <EstimatedTimeToSLABreachCalculator>(() => SLABreachCalculator);

            unicastBus = new UnicastBus
            {
                MasterNodeAddress     = MasterNodeAddress,
                TimeoutManagerAddress = MasterNodeAddress.SubScope("Timeouts"),
                MessageSerializer     = MessageSerializer,
                Builder             = FuncBuilder,
                MessageSender       = messageSender,
                Transport           = Transport,
                SubscriptionStorage = subscriptionStorage,
                AutoSubscribe       = true,
                MessageMapper       = MessageMapper,
                FailureManager      = MockRepository.GenerateStub <IManageMessageFailures>()
            };
            bus = unicastBus;

            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => new RelatedToMessageMutator {
                Bus = bus
            });
            FuncBuilder.Register <IBus>(() => bus);

            ExtensionMethods.SetHeaderAction = headerManager.SetHeader;
        }
示例#10
0
        public async Task DisposesInjectedStuffWhenTheActivatorIsDisposed()
        {
            var fakeTransport = new FakeTransport();
            var fakeSubscriptionStorage = new FakeSubscriptionStorage();

            using (var activator = new BuiltinHandlerActivator())
            {
                Configure.With(activator)
                    .Transport(x => x.Register(c => fakeTransport))
                    .Subscriptions(x => x.Register(c => fakeSubscriptionStorage))
                    .Start();

                await Task.Delay(1000);
            }

            Assert.That(fakeTransport.WasDisposed, Is.True, "The fake transport was not disposed!");
            Assert.That(fakeSubscriptionStorage.WasDisposed, Is.True, "The fake subscription storage was not disposed!");
        }
示例#11
0
        public async Task DisposesInjectedStuffWhenTheActivatorIsDisposed()
        {
            var fakeTransport           = new FakeTransport();
            var fakeSubscriptionStorage = new FakeSubscriptionStorage();

            using (var activator = new BuiltinHandlerActivator())
            {
                Configure.With(activator)
                .Transport(x => x.Register(c => fakeTransport))
                .Subscriptions(x => x.Register(c => fakeSubscriptionStorage))
                .Start();

                await Task.Delay(1000);
            }

            Assert.That(fakeTransport.WasDisposed, Is.True, "The fake transport was not disposed!");
            Assert.That(fakeSubscriptionStorage.WasDisposed, Is.True, "The fake subscription storage was not disposed!");
        }
        public async Task Should_work()
        {
            var context = await Scenario.Define <ScenarioContext>()
                          .WithEndpoint <ScopeEndpoint>(b => b.CustomConfig(c =>
            {
                var transport = new FakeTransport
                {
                    TransportTransactionMode = TransportTransactionMode.ReceiveOnly
                };
                c.UseTransport(transport);
                c.UnitOfWork()
                .WrapHandlersInATransactionScope();
            }))
                          .Done(c => c.EndpointsStarted)
                          .Run();

            Assert.True(context.EndpointsStarted);
        }
            public EndpointWithLocalCallback()
            {
                EndpointSetup <DefaultServer>(builder =>
                {
                    var fakeTransport = new FakeTransport();
                    fakeTransport.RaiseCriticalErrorOnReceiverStart(new AggregateException("Startup task failed to complete.", new InvalidOperationException("ExceptionInBusStarts")));
                    builder.UseTransport(fakeTransport);

                    builder.DefineCriticalErrorAction((errorContext, _) =>
                    {
                        var aggregateException    = (AggregateException)errorContext.Exception;
                        var context               = builder.GetSettings().Get <Context>();
                        context.Exception         = aggregateException.InnerExceptions.First();
                        context.Message           = errorContext.Error;
                        context.ExceptionReceived = true;
                        return(Task.FromResult(0));
                    });
                });
            }
示例#14
0
        public async Task AwareOfExistingFiles()
        {
            // Arrange
            using var cacheDirectory = new TempDirectory();
            var options = new SentryOptions
            {
                Dsn = DsnSamples.ValidDsnWithoutSecret,
                DiagnosticLogger   = _logger,
                CacheDirectoryPath = cacheDirectory.Path
            };

            // Send some envelopes with a failing transport to make sure they all stay in cache
            {
                using var initialInnerTransport  = new FakeTransport();
                await using var initialTransport = new CachingTransport(initialInnerTransport, options);

                // Shutdown the worker immediately so nothing gets processed
                await initialTransport.StopWorkerAsync();

                for (var i = 0; i < 3; i++)
                {
                    using var envelope = Envelope.FromEvent(new SentryEvent());
                    await initialTransport.SendEnvelopeAsync(envelope);
                }
            }

            using var innerTransport  = new FakeTransport();
            await using var transport = new CachingTransport(innerTransport, options);

            // Act

            // Wait until directory is empty
            while (
                Directory.Exists(cacheDirectory.Path) &&
                Directory.EnumerateFiles(cacheDirectory.Path, "*", SearchOption.AllDirectories).Any())
            {
                await Task.Delay(100);
            }

            // Assert
            innerTransport.GetSentEnvelopes().Should().HaveCount(3);
        }
        public void Should_blow_up()
        {
            var exception = Assert.ThrowsAsync <Exception>(async() =>
            {
                await Scenario.Define <ScenarioContext>()
                .WithEndpoint <ScopeEndpoint>(b => b.CustomConfig(c =>
                {
                    var fakeTransport = new FakeTransport
                    {
                        TransportTransactionMode = TransportTransactionMode.TransactionScope
                    };
                    c.UseTransport(fakeTransport);
                    c.UnitOfWork()
                    .WrapHandlersInATransactionScope();
                }))
                .Run();
            });

            Assert.True(exception.Message.Contains("A Transaction scope unit of work can't be used when the transport already uses a scope"));
        }
示例#16
0
            public Endpoint()
            {
                EndpointSetup <DefaultServer, Context>((c, t) =>
                {
                    var fakeTransport = new FakeTransport
                    {
                        OnTransportInitialize = queues =>
                        {
                            t.SendingAddresses    = queues.sendingAddresses;
                            t.ReceivingAddresses  = queues.receivingAddresses;
                            t.SetupInfrastructure = queues.setupInfrastructure;
                        }
                    };
                    c.UseTransport(fakeTransport);

                    if (!t.EnableInstallers)
                    {
                        // DefaultServer always calls EnableInstaller. We need to reverse it.
                        c.GetSettings().Set("Installers.Enable", false);
                    }
                });
            }
示例#17
0
        public void SetUp()
        {
            HandlerInvocationCache.Clear();

            SettingsHolder.Reset();
            SettingsHolder.SetDefault("Endpoint.SendOnly", false);

            Transport   = new FakeTransport();
            FuncBuilder = new FuncBuilder();
            Configure.GetEndpointNameAction = () => "TestEndpoint";
            const string localAddress = "endpointA";

            MasterNodeAddress = new Address(localAddress, "MasterNode");
            subscriptionPredicatesEvaluator = new SubscriptionPredicatesEvaluator();
            router                  = new StaticMessageRouter(KnownMessageTypes());
            handlerRegistry         = new MessageHandlerRegistry();
            MessageMetadataRegistry = new MessageMetadataRegistry
            {
                DefaultToNonPersistentMessages = false
            };

            try
            {
                Address.InitializeLocalAddress(localAddress);
            }
            catch // intentional
            {
            }

            MessageSerializer = new XmlMessageSerializer(MessageMapper);
            ExtensionMethods.GetStaticOutgoingHeadersAction = () => MessageHeaderManager.staticHeaders;
            gatewayAddress = MasterNodeAddress.SubScope("gateway");

            messageSender       = MockRepository.GenerateStub <ISendMessages>();
            subscriptionStorage = new FakeSubscriptionStorage();

            subscriptionManager = new MessageDrivenSubscriptionManager
            {
                Builder             = FuncBuilder,
                MessageSender       = messageSender,
                SubscriptionStorage = subscriptionStorage
            };

            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => headerManager);
            FuncBuilder.Register <IMutateIncomingMessages>(() => new FilteringMutator
            {
                SubscriptionPredicatesEvaluator = subscriptionPredicatesEvaluator
            });
            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => new SentTimeMutator());
            FuncBuilder.Register <IMutateIncomingTransportMessages>(() => subscriptionManager);
            FuncBuilder.Register <DefaultDispatcherFactory>(() => new DefaultDispatcherFactory());
            FuncBuilder.Register <EstimatedTimeToSLABreachCalculator>(() => SLABreachCalculator);
            FuncBuilder.Register <ExtractIncomingPrincipal>(() => new WindowsImpersonator());

            unicastBus = new UnicastBus
            {
                MasterNodeAddress = MasterNodeAddress,
                MessageSerializer = MessageSerializer,
                Builder           = FuncBuilder,
                MessageSender     = messageSender,
                Transport         = Transport,
                MessageMapper     = MessageMapper,
                MessagePublisher  = new StorageDrivenPublisher
                {
                    MessageSender       = messageSender,
                    SubscriptionStorage = subscriptionStorage
                },
                MessageDeferrer = new TimeoutManagerDeferrer
                {
                    MessageSender         = messageSender,
                    TimeoutManagerAddress = MasterNodeAddress.SubScope("Timeouts")
                },
                SubscriptionManager             = subscriptionManager,
                MessageMetadataRegistry         = MessageMetadataRegistry,
                SubscriptionPredicatesEvaluator = subscriptionPredicatesEvaluator,
                HandlerRegistry = handlerRegistry,
                MessageRouter   = router
            };
            bus = unicastBus;

            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => new CausationMutator {
                Bus = bus
            });
            FuncBuilder.Register <IBus>(() => bus);

            ExtensionMethods.SetHeaderAction = headerManager.SetHeader;
        }
示例#18
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);
        }
        public void SetUp()
        {
            transportDefinition = new Msmq();
            HandlerInvocationCache.Clear();

            SettingsHolder.Reset();
            SettingsHolder.SetDefault("Endpoint.SendOnly", false);

            Transport   = new FakeTransport();
            FuncBuilder = new FuncBuilder();
            Configure.GetEndpointNameAction = () => "TestEndpoint";
            subscriptionPredicatesEvaluator = new SubscriptionPredicatesEvaluator();
            router                  = new StaticMessageRouter(KnownMessageTypes());
            handlerRegistry         = new MessageHandlerRegistry();
            MessageMetadataRegistry = new MessageMetadataRegistry
            {
                DefaultToNonPersistentMessages = false
            };


            MessageSerializer = new XmlMessageSerializer(MessageMapper);
            //ExtensionMethods.GetStaticOutgoingHeadersAction = () => MessageHeaderManager.staticHeaders;
            gatewayAddress = MasterNodeAddress.SubScope("gateway");

            messageSender       = MockRepository.GenerateStub <ISendMessages>();
            subscriptionStorage = new FakeSubscriptionStorage();
            subscriptionManager = new MessageDrivenSubscriptionManager
            {
                Builder             = FuncBuilder,
                MessageSender       = messageSender,
                SubscriptionStorage = subscriptionStorage
            };

            var pipelineBuilder = new PipelineBuilder(FuncBuilder);

            pipelineFactory = new PipelineExecutor(FuncBuilder, pipelineBuilder);

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

            FuncBuilder.Register <MessageAuditer>(() => new MessageAuditer());

            FuncBuilder.Register <LogicalMessageFactory>(() => new LogicalMessageFactory());

            FuncBuilder.Register <IMutateIncomingMessages>(() => new FilteringMutator
            {
                SubscriptionPredicatesEvaluator = subscriptionPredicatesEvaluator
            });
            FuncBuilder.Register <IMutateIncomingTransportMessages>(() => subscriptionManager);
            FuncBuilder.Register <EstimatedTimeToSLABreachCalculator>(() => SLABreachCalculator);
            FuncBuilder.Register <MessageMetadataRegistry>(() => MessageMetadataRegistry);

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

            FuncBuilder.Register <ExtractLogicalMessagesBehavior>(() => new ExtractLogicalMessagesBehavior
            {
                MessageSerializer       = MessageSerializer,
                MessageMetadataRegistry = MessageMetadataRegistry,
            });
            FuncBuilder.Register <ImpersonateSenderBehavior>(() => new ImpersonateSenderBehavior
            {
                ExtractIncomingPrincipal = MockRepository.GenerateStub <ExtractIncomingPrincipal>()
            });

            FuncBuilder.Register <CreatePhysicalMessageBehavior>(() => new CreatePhysicalMessageBehavior());
            FuncBuilder.Register <PipelineBuilder>(() => pipelineBuilder);
            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")
            };

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

            unicastBus = new UnicastBus
            {
                MasterNodeAddress               = MasterNodeAddress,
                Builder                         = FuncBuilder,
                MessageSender                   = messageSender,
                Transport                       = Transport,
                MessageMapper                   = MessageMapper,
                SubscriptionManager             = subscriptionManager,
                SubscriptionPredicatesEvaluator = subscriptionPredicatesEvaluator,
                MessageRouter                   = router
            };
            bus = unicastBus;

            FuncBuilder.Register <IMutateOutgoingTransportMessages>(() => new CausationMutator {
                Bus = bus
            });
            FuncBuilder.Register <IBus>(() => bus);
            FuncBuilder.Register <UnicastBus>(() => unicastBus);
            new HeaderBootstrapper
            {
                Builder = FuncBuilder
            }.SetupHeaderActions();
        }
示例#20
0
 public ITransport CreateTransport(TransportParams parameters)
 {
     LastCreatedTransport = new FakeTransport(parameters);
     InitialiseFakeTransport(LastCreatedTransport);
     return(LastCreatedTransport);
 }
示例#21
0
        public void TransportDeadThenAliveTest()
        {
            IMemcacheNode theNode = null;
            FakeTransport transport = new FakeTransport();
            transport.Kill();

            // Memcache client config
            var config = new MemcacheClientConfiguration
            {
                DeadTimeout = TimeSpan.FromSeconds(1),
                TransportFactory = transport.Factory,
                NodeFactory = (e, c) =>  MemcacheClientConfiguration.DefaultNodeFactory(e, c),
                PoolSize = 1,
            };

            theNode = config.NodeFactory(null, config);
            Assert.IsFalse(theNode.IsDead, "The node should be alive before any failure");

            Assert.IsFalse(theNode.TrySend(null, 1), "The TrySend should fail with a broken transport");
            Assert.IsTrue(theNode.IsDead, "The node should be dead after the first send failed");

            transport.Resurect();
            Assert.IsFalse(theNode.IsDead, "The node should be alive after the transport resurected");
            Assert.IsTrue(theNode.TrySend(null, 1), "The TrySend should be able to send a request after the transport is up again");

            transport.Kill();
            Assert.IsFalse(theNode.TrySend(null, 1), "The TrySend should fail with a killed transport");
            Assert.IsTrue(theNode.IsDead, "The node should be dead after the a send failed");
        }