Exemplo n.º 1
0
            public void DefaultValueIsEmptyString()
            {
                var bus = new DurableMessageBus(new RetryPolicy());

                Assert.That(bus.MessageVersion, Is.Not.Null);
                Assert.That(bus.MessageVersion, Is.Empty);
            }
Exemplo n.º 2
0
            public async Task SetUp()
            {
                await ClearAllDataFiles();

                var retryPolicy = new RetryPolicy(1, DateTimeUtility.PositiveOneHourTimeSpan);

                _bus = new DurableMessageBus(retryPolicy);

                _commands = new CommandSubscribers();
                _events   = new EventSubscribers();
                _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle);
                _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle);
            }
Exemplo n.º 3
0
            public async Task SetUp()
            {
                await ClearAllDataFiles();

                var retryPolicy = new RetryPolicy();

                Assume.That(retryPolicy.Retries, Is.EqualTo(0));

                _bus = new DurableMessageBus(retryPolicy);

                _commands = new CommandSubscribers();
                _events   = new EventSubscribers();
                _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle);
                _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle);
            }
Exemplo n.º 4
0
            public async Task CanRepublishDurableCommandsOnNextStart()
            {
                await SendUnacknowledgedCommandAndEventTwiceThenDisposeDurableBus();

                //recreate the bus from scratch
                _bus = new DurableMessageBus(_retryPolicy);

                //re-register the command subscriber
                _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle);

                //calling start should re-hydrate the list of pending (unacknowledged) commands
                // and then process them using the re-registered subscriber
                await _bus.Start();

                //we should now have one more payload element received
                Assert.That(_commands.ProcessedMessagePayload, Is.EqualTo(_tripleValue), "Command not properly re-hydrated.");
            }
Exemplo n.º 5
0
            public async Task DurableEventsWithoutMatchingVersionAreDiscardedOnBusStart()
            {
                await SendUnacknowledgedCommandAndEventTwiceThenDisposeDurableBus();

                //recreate the bus from scratch, set the version to be something *other* than the default empty string
                _bus = new DurableMessageBus(_retryPolicy)
                {
                    MessageVersionProvider = () => "not-the-default"
                };

                //re-register the event subscriber
                _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle);

                //calling start should re-hydrate the list of pending (unacknowledged) events
                // and then process them using the re-registered subscriber
                await _bus.Start();

                //because the version of the command doesn't match, we should still only have original two payload elements received
                Assert.That(_events.ProcessedMessagePayload, Is.EqualTo(_doubleValue), "Event with wrong version not properly ignored.");
            }
Exemplo n.º 6
0
            public void VersionIsCachedAfterInitialCalculationAndNotRecalculated()
            {
                const string expected    = "1";
                const string notExpected = "2";

                var versionProvider = new VersionProvider {
                    Version = expected
                };

                var bus = new DurableMessageBus(new RetryPolicy())
                {
                    MessageVersionProvider = () => versionProvider.Version
                };

                Assume.That(bus.MessageVersion, Is.EqualTo(expected), "MessageVersionProvider delegate not wired up properly.");

                //this changes the value that would be returned by the delegate, should it improperly be invoked a second time
                versionProvider.Version = notExpected;

                //since the delegate should NOT be invoked a second time, we expect the original value to be retained
                Assert.That(bus.MessageVersion, Is.EqualTo(expected));
            }
Exemplo n.º 7
0
            public async Task MessageIsNotSendToSubscriberOnStart()
            {
                const string singleValue = "0";

                //we need a retry policy with at least one retry
                //  so that we'd expect the call to Start() to attempt a retry
                var retryPolicy = new RetryPolicy(1, DateTimeUtility.PositiveOneHourTimeSpan);

                var bus      = new DurableMessageBus(retryPolicy);
                var commands = new CommandSubscribers();

                bus.RegisterSubscriptionFor <TestDurableCommand>(commands.Handle);

                await bus.SendDurable(new TestDurableCommand(singleValue));

                Assume.That(commands.ProcessedMessagePayload, Is.EqualTo(singleValue), "Command Subscriber didn't receive the expected message.");

                bus.UnRegisterAllSubscriptionsFor <TestDurableCommand>();

                await bus.Start();

                Assert.That(commands.ProcessedMessagePayload, Is.EqualTo(singleValue), "Bus did not properly ignore queued command.");
            }
Exemplo n.º 8
0
            private async Task SendUnacknowledgedCommandAndEventTwiceThenDisposeDurableBus()
            {
                _doubleValue = string.Format("{0}{0}", SingleValue);
                _tripleValue = string.Format("{0}{0}{0}", SingleValue);

                _retryPolicy = new RetryPolicy(10, DateTimeUtility.PositiveOneHourTimeSpan);
                _bus         = new DurableMessageBus(_retryPolicy);

                _commands = new DurableCommandSubscribers();
                _events   = new DurableEventSubscribers();

                _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle);
                _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle);

                await _bus.SendDurable(new TestDurableCommand(SingleValue));

                await _bus.PublishDurable(new TestDurableEvent(SingleValue));

                Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue),
                            "Command Subscriber not registered for command as expected.");
                Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue),
                            "Event Subscriber not registered for event as expected.");

                await _bus.Start();

                Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(_doubleValue),
                            "Command Subscriber not registered for command as expected.");
                Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(_doubleValue),
                            "Event Subscriber not registered for event as expected.");

                await _bus.Stop();

                _bus = null;

                Assume.That(_bus, Is.Null);
            }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            RunningLog = new ObservableCollection <string>();

            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
            Bus = new DurableMessageBus()
            {
                Logger = text =>
                {
                    Debug.WriteLine(text);
                    RunningLog.Add(text);
                }
            };

            ViewModels = new ViewModelManager();

            var registrar = new SubscriberRegistrar(Bus, ViewModels);

            registrar.RegisterMessageBusSubscribers();


            this.InitializeComponent();
            this.Suspending += OnSuspending;
        }
Exemplo n.º 10
0
 public async Task AcknowledgeLastMessage(DurableMessageBus bus)
 {
     await bus.Acknowledge(Messages.Last());
 }
 public SubscriberRegistrar(DurableMessageBus messageBus, IManageViewModels modelManager)
 {
     _messageBus   = messageBus;
     _modelManager = modelManager;
 }
 public IncrementCounterCommandHandler(DurableMessageBus bus)
 {
     _bus = bus;
 }
 public CounterIncrementedViewModelEventHandler(DurableMessageBus bus, IManageViewModels modelManager)
 {
     _bus          = bus;
     _modelManager = modelManager;
 }