Пример #1
0
        public void should_call_initializer_methods_in_right_order()
        {
            var counter = new Counter();
            var bus = new TestBus();
            bus.Starting += () => counter.Increment();
            bus.Started += () => counter.Increment();
            bus.Stopping += () => counter.Increment();
            bus.Stopped += () => counter.Increment();
            var testHostInitializer = new TestHostInitializer(counter);
            var host = new Host();
            var container = host.ContainerFactory.Invoke();
            host.ContainerFactory = () =>
            {
                container.Configure(x =>
                {
                    x.ForSingletonOf<IBus>().Use(bus);
                    x.ForSingletonOf<HostInitializer>().Add(testHostInitializer);
                });
                return container;
            };

            host.Start();
            host.Stop();

            testHostInitializer.CapturedContainer.ShouldEqual(container);
            testHostInitializer.ConfigureContainerCounterValue.ShouldEqual(0);
            testHostInitializer.BeforeStartCounterValue.ShouldEqual(0);
            testHostInitializer.AfterStartCounterValue.ShouldEqual(2);
            testHostInitializer.BeforeStopCounterValue.ShouldEqual(2);
            testHostInitializer.AfterStopCounterValue.ShouldEqual(4);
        }
Пример #2
0
        public void Setup()
        {
            _transportMessageSerializer = new TransportMessageSerializer();
            _configurationMock          = new Mock <IPersistenceConfiguration>();
            _configurationMock.Setup(conf => conf.SafetyPhaseDuration).Returns(500.Milliseconds());
            _configurationMock.SetupGet(x => x.ReplayBatchSize).Returns(_replayBatchSize);
            _configurationMock.SetupGet(x => x.ReplayUnackedMessageCountThatReleasesNextBatch).Returns(200);

            _selfPeer    = new Peer(new PeerId("Abc.Testing.Self"), "tcp://abctest:888");
            _targetPeer  = new Peer(new PeerId("Abc.Testing.Target"), "tcp://abcother:123");
            _anotherPeer = new Peer(new PeerId("Abc.Testing.Another"), "tcp://abcanother:123");

            _bus                = new TestBus();
            _transport          = new TestTransport(_selfPeer, "test");
            _messageMatcherMock = new Mock <IInMemoryMessageMatcher>();

            _replayId = Guid.NewGuid();

            _insertedMessages = new List <byte[]>();
            var readerMock = new Mock <IMessageReader>();

            _storageMock = new Mock <IStorage>();
            _storageMock.Setup(x => x.CreateMessageReader(It.IsAny <PeerId>())).Returns(readerMock.Object);

            readerMock.Setup(x => x.GetUnackedMessages()).Returns(_insertedMessages);

            var speedReporter = new Mock <IReporter>();

            _replayer = new MessageReplayer(_configurationMock.Object, _storageMock.Object, _bus, _transport, _messageMatcherMock.Object, _targetPeer, _replayId, speedReporter.Object, new MessageSerializer());

            _messageMatcherMock.Setup(x => x.EnqueueWaitHandle(It.IsAny <EventWaitHandle>())).Callback <EventWaitHandle>(x => x.Set());
        }
        public void Setup()
        {
            _configurationMock = new Mock<IDirectoryConfiguration>();
            _bus = new TestBus();

            var peer = new Peer(new PeerId("Abc.Testing.0"), "tcp://abctest:12300");
            var peerDescriptor = peer.ToPeerDescriptor(true);
            _entry = new DeadPeerDetectorEntry(peerDescriptor, _configurationMock.Object, _bus, new CurrentThreadTaskScheduler());
        }
        public void SetUp()
        {
            _testBus = new TestBus();
            var configurationMock = new Mock <ICqlPersistenceConfiguration>();

            configurationMock.SetupGet(x => x.OldestMessagePerPeerCheckPeriod).Returns(30.Seconds());
            configurationMock.SetupGet(x => x.OldestMessagePerPeerGlobalCheckPeriod).Returns(30.Seconds());
            _cqlStorage           = new Mock <ICqlStorage>();
            _oldestMessageUpdater = new OldestNonAckedMessageUpdaterPeriodicAction(_testBus, configurationMock.Object, _cqlStorage.Object);
        }
        public void Setup()
        {
            _contextScope = MessageContext.SetCurrent(MessageContext.CreateTest());

            _configurationMock = new Mock<IDirectoryConfiguration>();
            _configurationMock.SetupGet(conf => conf.BlacklistedMachines).Returns(new[] { "ANOTHER_BLACKLISTEDMACHINE", "BLACKlistedMACHINE" });
            _repositoryMock = new Mock<IPeerRepository>();
            _bus = new TestBus();
            _handler = new DirectoryCommandsHandler(_bus, _repositoryMock.Object, _configurationMock.Object) { Context = MessageContext.CreateOverride(_sender.Id, _sender.EndPoint) };
        }
Пример #6
0
        public void Setup()
        {
            _configurationMock = new Mock <IDirectoryConfiguration>();
            _bus = new TestBus();

            var peer           = new Peer(new PeerId("Abc.Testing.0"), "tcp://abctest:12300");
            var peerDescriptor = peer.ToPeerDescriptor(true);

            _entry = new DeadPeerDetectorEntry(peerDescriptor, _configurationMock.Object, _bus, new CurrentThreadTaskScheduler());
        }
Пример #7
0
        public void should_notify_explicit_handlers()
        {
            var bus = new TestBus();

            bool received = false;

            bus.Subscribe <FakeEvent>(e => received = true);

            bus.Publish(new FakeEvent(1));

            Assert.That(received);
        }
Пример #8
0
        public void Setup()
        {
            _configurationMock = new Mock <IBusConfiguration>();
            _configurationMock.SetupGet(x => x.DirectoryServiceEndPoints).Returns(new[] { "tcp://main-directory:777", "tcp://backup-directory:777" });
            _configurationMock.SetupGet(x => x.RegistrationTimeout).Returns(500.Milliseconds());
            _configurationMock.SetupGet(x => x.IsDirectoryPickedRandomly).Returns(false);

            _directory = new PeerDirectoryClient(_configurationMock.Object);
            _bus       = new TestBus();

            _self      = new Peer(new PeerId("Abc.Testing.0"), "tcp://abctest:123");
            _otherPeer = new Peer(new PeerId("Abc.Testing.1"), "tcp://abctest:789");
        }
Пример #9
0
        public void Setup()
        {
            _configurationMock = new Mock<IBusConfiguration>();
            _configurationMock.SetupGet(x => x.DirectoryServiceEndPoints).Returns(new[] { "tcp://main-directory:777", "tcp://backup-directory:777" });
            _configurationMock.SetupGet(x => x.RegistrationTimeout).Returns(100.Milliseconds());
            _configurationMock.SetupGet(x => x.IsDirectoryPickedRandomly).Returns(false);

            _directory = new PeerDirectoryClient(_configurationMock.Object);
            _bus = new TestBus();

            _self = new Peer(new PeerId("Abc.Testing.0"), "tcp://abctest:123");
            _otherPeer = new Peer(new PeerId("Abc.Testing.1"), "tcp://abctest:789");
        }
Пример #10
0
        public void should_not_generate_snapshot_if_snapshot_generator_returns_null()
        {
            // Arrange
            var testBus           = new TestBus();
            var snapshotGenerator = new TestSnapshotGenerator(testBus, null);

            // Act
            var peerId = new PeerId("testPeerId");

            snapshotGenerator.Handle(new SubscriptionsUpdated(new SubscriptionsForType(new MessageTypeId(typeof(TestEvent))), peerId));

            // Assert
            testBus.ExpectNothing();
        }
Пример #11
0
        public void should_generate_snapshot_and_publish_it_to_the_specified_peer()
        {
            // Arrange
            var testBus           = new TestBus();
            var snapshotGenerator = new TestSnapshotGenerator(testBus, new TestSnapshot());

            // Act
            var peerId = new PeerId("testPeerId");

            snapshotGenerator.Handle(new SubscriptionsUpdated(new SubscriptionsForType(new MessageTypeId(typeof(TestEvent))), peerId));

            // Assert
            testBus.ExpectExactly(peerId, new TestSnapshot());
        }
        public void Setup()
        {
            _contextScope = MessageContext.SetCurrent(MessageContext.CreateTest());

            _configurationMock = new Mock <IDirectoryConfiguration>();
            _configurationMock.SetupGet(conf => conf.BlacklistedMachines).Returns(new[] { "ANOTHER_BLACKLISTEDMACHINE", "BLACKlistedMACHINE" });
            _repositoryMock = new Mock <IPeerRepository>();
            _bus            = new TestBus();
            _speedReporter  = new Mock <IDirectorySpeedReporter>();
            _handler        = new DirectoryCommandsHandler(_bus, _repositoryMock.Object, _configurationMock.Object, _speedReporter.Object)
            {
                Context = MessageContext.CreateOverride(_sender.Id, _sender.EndPoint)
            };
        }
        public void Setup()
        {
            _repositoryMock = new Mock<IPeerRepository>();
            var configurationMock = new Mock<IDirectoryConfiguration>();
            configurationMock.SetupGet(conf => conf.DisableDynamicSubscriptionsForDirectoryOutgoingMessages).Returns(() => _disableDynamicSubscriptionsForDirectoryOutgoingMessages);
            _peerDirectory = new PeerDirectoryServer(configurationMock.Object, _repositoryMock.Object);

            _updatedPeer = null;
            _peerDirectory.PeerUpdated += (id, action) => _updatedPeer = new UpdatedPeer(id, action);

            _bus = new TestBus();

            _self = new Peer(new PeerId("Abc.DirectoryService.0"), "tcp://abc:42");
            _otherPeer = new Peer(new PeerId("Abc.Testing.0"), "tcp://abc:123");
        }
Пример #14
0
        public void Setup()
        {
            _repositoryMock = new Mock <IPeerRepository>();
            var configurationMock = new Mock <IDirectoryConfiguration>();

            configurationMock.SetupGet(conf => conf.DisableDynamicSubscriptionsForDirectoryOutgoingMessages).Returns(() => _disableDynamicSubscriptionsForDirectoryOutgoingMessages);
            _peerDirectory = new PeerDirectoryServer(configurationMock.Object, _repositoryMock.Object);

            _updatedPeer = null;
            _peerDirectory.PeerUpdated += (id, action) => _updatedPeer = new UpdatedPeer(id, action);

            _bus = new TestBus();

            _self      = new Peer(new PeerId("Abc.DirectoryService.0"), "tcp://abc:42");
            _otherPeer = new Peer(new PeerId("Abc.Testing.0"), "tcp://abc:123");
        }
Пример #15
0
        public async Task should_handle_exception_with_async_executor()
        {
            // Arrange
            var bus = new TestBus {
                HandlerExecutor = new TestBus.AsyncHandlerExecutor()
            };
            var exception = new Exception("Expected");

            bus.AddHandlerThatThrows <FakeCommand>(exception);

            // Act
            var result = await bus.Send(new FakeCommand(123));

            // Assert
            Assert.That(result.IsSuccess, Is.False);
            Assert.That(result.ResponseMessage, Is.EqualTo(exception.Message));
        }
        public void Setup()
        {
            _batchSize = 1;
            _delay     = null;

            _configurationMock = new Mock <IPersistenceConfiguration>();
            _configurationMock.SetupGet(conf => conf.PersisterBatchSize).Returns(() => _batchSize);
            _configurationMock.SetupGet(conf => conf.PersisterDelay).Returns(() => _delay);

            _storageMock = new Mock <IStorage>();

            _bus     = new TestBus();
            _matcher = new InMemoryMessageMatcher(_configurationMock.Object, _storageMock.Object, _bus);

            _storeBatchFunc = x => { };
            _storageMock.Setup(x => x.Write(It.IsAny <IList <MatcherEntry> >()))
            .Returns <IList <MatcherEntry> >(items => Task.Run(() => _storeBatchFunc.Invoke(items)));
        }
Пример #17
0
        public virtual void Setup()
        {
            CurrentMessageContext = CreateMessageContext();
            _contextScope         = MessageContext.SetCurrent(CurrentMessageContext);


            MockContainer = new MockContainer();
            Bus           = new TestBus();
            MockContainer.Configure(x =>
            {
                x.For <IBus>().Use(Bus);
                x.For <MessageContext>().Use(CurrentMessageContext);
            });


            BeforeBuildingHandler();
            CreateHandler();
        }
Пример #18
0
        public void Setup()
        {
            _transientAlivePeer0         = CreatePeerDescriptor("Abc.TransientAlive.0", isUp: true, isPersistent: false, hasDebuggerAttached: false);
            _transientAlivePeer1         = CreatePeerDescriptor("Abc.TransientAlive.1", isUp: true, isPersistent: false, hasDebuggerAttached: false);
            _transientDeadPeer           = CreatePeerDescriptor("Abc.TransientDead.0", isUp: false, isPersistent: false, hasDebuggerAttached: false);
            _persistentAlivePeer         = CreatePeerDescriptor("Abc.PersistentAlive.0", isUp: true, isPersistent: true, hasDebuggerAttached: false);
            _persistentDeadPeer          = CreatePeerDescriptor("Abc.PersistentDead.0", isUp: false, isPersistent: true, hasDebuggerAttached: false);
            _debugPersistentAlivePeer    = CreatePeerDescriptor("Abc.DebugPersistentAlive.0", isUp: true, isPersistent: true, hasDebuggerAttached: true);
            _debugTransientAlivePeer     = CreatePeerDescriptor("Abc.DebugTransientAlive.0", isUp: true, isPersistent: false, hasDebuggerAttached: true);
            _persistencePeer             = CreatePeerDescriptor("Abc.Zebus.PersistenceService.0", isUp: true, isPersistent: false, hasDebuggerAttached: false);
            _directoryPeer               = CreatePeerDescriptor("NonStandardDirectoryName", isUp: true, isPersistent: false, hasDebuggerAttached: false);
            _directoryPeer.Subscriptions = new[] { new Subscription(new MessageTypeId(typeof(RegisterPeerCommand))) };
            _peersNotToDecommission      = new string[0];

            _peerRepositoryMock = new Mock <IPeerRepository>();
            var peerDescriptors = new List <PeerDescriptor>
            {
                _transientAlivePeer0,
                _transientAlivePeer1,
                _transientDeadPeer,
                _persistentAlivePeer,
                _persistentDeadPeer,
                _debugPersistentAlivePeer,
                _debugTransientAlivePeer,
                _persistencePeer
            };

            _peerRepositoryMock.Setup(repo => repo.GetPeers(It.IsAny <bool>())).Returns(peerDescriptors);
            _peerRepositoryMock.Setup(repo => repo.Get(It.IsAny <PeerId>())).Returns <PeerId>(peerId => peerDescriptors.FirstOrDefault(x => x.Peer.Id == peerId));

            _bus = new TestBus();

            _configurationMock = new Mock <IDirectoryConfiguration>();
            _configurationMock.As <IDirectoryConfiguration>().SetupGet(conf => conf.TransientPeerPingTimeout).Returns(_transientPeerTimeout.Seconds());
            _configurationMock.As <IDirectoryConfiguration>().SetupGet(conf => conf.PersistentPeerPingTimeout).Returns(_persistentPeerTimeout.Seconds());
            _configurationMock.As <IDirectoryConfiguration>().SetupGet(conf => conf.DebugPeerPingTimeout).Returns(_debugPeerTimeout.Seconds());
            _configurationMock.As <IDirectoryConfiguration>().SetupGet(conf => conf.PeerPingInterval).Returns(_pingInterval);
            _configurationMock.As <IDirectoryConfiguration>().SetupGet(conf => conf.WildcardsForPeersNotToDecommissionOnTimeout).Returns(() => _peersNotToDecommission);

            _detector = new DeadPeerDetector(_bus, _peerRepositoryMock.Object, _configurationMock.Object);
            _detector.TaskScheduler = new CurrentThreadTaskScheduler();

            _bus.HandlerExecutor = new HangOnThrowHandlerExecutor();
        }
        public void SetUp()
        {
            _bus = new TestBus();

            _periodicInitializer = new XPeriodicActionHostInitializer(_bus, 20.Milliseconds());
        }
 public void SetUp()
 {
     _storage = new Mock <IStorage>();
     _bus     = new TestBus();
     _handler = new PublishNonAckMessagesCountCommandHandler(_storage.Object, _bus);
 }
Пример #21
0
 public void SetUp()
 {
     _peerStateRepo        = new FakePeerStateRepository();
     _testBus              = new TestBus();
     _oldestMessageUpdater = new OldestNonAckedMessageUpdaterPeriodicAction(_testBus, _peerStateRepo, DataContext, new Mock <ICqlPersistenceConfiguration>().Object);
 }