Ejemplo n.º 1
0
        public async Task Invoke_when_timeout_not_in_storage_should_process_successfully()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister  = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var behavior          = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);

            await behavior.Invoke(CreateContext(Guid.NewGuid().ToString()));

            Assert.AreEqual(0, messageDispatcher.OutgoingTransportOperations.UnicastTransportOperations.Count());
        }
        public async Task Invoke_when_timeout_not_in_storage_should_process_successfully()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);

            await behavior.Invoke(CreateContext(Guid.NewGuid().ToString()));

            Assert.AreEqual(0, messageDispatcher.OutgoingTransportOperations.UnicastTransportOperations.Count());
        }
        public async Task Invoke_when_using_dtc_should_enlist_dispatch_in_transaction()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);
            var timeoutData = CreateTimeout();
            await timeoutPersister.Add(timeoutData, null);

            await behavior.Invoke(CreateContext(timeoutData.Id));

            var transportOperation = messageDispatcher.OutgoingTransportOperations.UnicastTransportOperations.Single();
            Assert.AreEqual(DispatchConsistency.Default, transportOperation.RequiredDispatchConsistency);
        }
        public void Invoke_when_removing_timeout_fails_should_throw_exception()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister = new FakeTimeoutStorage
            {
                OnPeek = (id, bag) => CreateTimeout(),
                OnTryRemove = (id, bag) => false // simulates a concurrent delete
            };

            var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);

            Assert.That(async () => await behavior.Invoke(CreateContext(Guid.NewGuid().ToString())), Throws.InstanceOf<Exception>());
        }
        public async Task Invoke_when_dispatching_message_fails_should_keep_timeout_in_storage()
        {
            var messageDispatcher = new FailingMessageDispatcher();
            var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);
            var timeoutData = CreateTimeout();
            await timeoutPersister.Add(timeoutData, null);

            Assert.That(async () => await behavior.Invoke(CreateContext(timeoutData.Id)), Throws.InstanceOf<Exception>());

            var result = await timeoutPersister.Peek(timeoutData.Id, null);
            Assert.NotNull(result);
        }
        public async Task Invoke_when_message_dispatched_should_remove_timeout_from_timeout_storage()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);
            var timeoutData = CreateTimeout();
            await timeoutPersister.Add(timeoutData, null);

            await behavior.Invoke(CreateContext(timeoutData.Id));

            var result = await timeoutPersister.Peek(timeoutData.Id, null);
            Assert.Null(result);
        }
Ejemplo n.º 7
0
        public void Invoke_when_removing_timeout_fails_should_throw_exception()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister  = new FakeTimeoutStorage
            {
                OnPeek      = (id, bag) => CreateTimeout(),
                OnTryRemove = (id, bag) => false // simulates a concurrent delete
            };

            var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);

            Assert.That(async() => await behavior.Invoke(CreateContext(Guid.NewGuid().ToString())), Throws.InstanceOf <Exception>());
        }
Ejemplo n.º 8
0
        public async Task Invoke_should_pass_transport_transaction_from_message_context()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister  = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var timeoutData       = CreateTimeout();
            await timeoutPersister.Add(timeoutData, null);

            var context = CreateContext(timeoutData.Id);

            var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);
            await behavior.Invoke(context);

            Assert.AreSame(context.TransportTransaction, messageDispatcher.TransportTransactionUsed, "Wrong transport transaction passed to the dispatcher");
        }
Ejemplo n.º 9
0
        public async Task Invoke_when_using_dtc_should_enlist_dispatch_in_transaction()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister  = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var behavior          = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);
            var timeoutData       = CreateTimeout();
            await timeoutPersister.Add(timeoutData, null);

            await behavior.Invoke(CreateContext(timeoutData.Id));

            var transportOperation = messageDispatcher.OutgoingTransportOperations.UnicastTransportOperations.Single();

            Assert.AreEqual(DispatchConsistency.Default, transportOperation.RequiredDispatchConsistency);
        }
Ejemplo n.º 10
0
        public async Task Invoke_when_dispatching_message_fails_should_keep_timeout_in_storage()
        {
            var messageDispatcher = new FailingMessageDispatcher();
            var timeoutPersister  = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var behavior          = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);
            var timeoutData       = CreateTimeout();
            await timeoutPersister.Add(timeoutData, null);

            Assert.That(async() => await behavior.Invoke(CreateContext(timeoutData.Id)), Throws.InstanceOf <Exception>());

            var result = await timeoutPersister.Peek(timeoutData.Id, null);

            Assert.NotNull(result);
        }
Ejemplo n.º 11
0
        public async Task Invoke_when_message_dispatched_should_remove_timeout_from_timeout_storage()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister  = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var behavior          = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);
            var timeoutData       = CreateTimeout();
            await timeoutPersister.Add(timeoutData, null);

            await behavior.Invoke(CreateContext(timeoutData.Id));

            var result = await timeoutPersister.Peek(timeoutData.Id, null);

            Assert.Null(result);
        }
Ejemplo n.º 12
0
        static string SetupDispatcherSatellite(FeatureConfigurationContext context, TransportTransactionMode requiredTransactionSupport)
        {
            var satelliteLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("TimeoutsDispatcher");
            var satelliteAddress        = context.Settings.GetTransportAddress(satelliteLogicalAddress);

            context.AddSatelliteReceiver("Timeout Dispatcher Processor", satelliteAddress, requiredTransactionSupport, PushRuntimeSettings.Default, RecoverabilityPolicy,
                                         (builder, pushContext) =>
            {
                var dispatchBehavior = new DispatchTimeoutBehavior(
                    builder.Build <IDispatchMessages>(),
                    builder.Build <IPersistTimeouts>(),
                    requiredTransactionSupport);

                return(dispatchBehavior.Invoke(pushContext));
            });

            return(satelliteAddress);
        }
Ejemplo n.º 13
0
        static string SetupDispatcherSatellite(FeatureConfigurationContext context, TransportTransactionMode requiredTransactionSupport, PushRuntimeSettings pushRuntimeSettings)
        {
            var satelliteLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("TimeoutsDispatcher");
            var satelliteAddress = context.Settings.GetTransportAddress(satelliteLogicalAddress);

            context.AddSatelliteReceiver("Timeout Dispatcher Processor", satelliteAddress, requiredTransactionSupport, pushRuntimeSettings, RecoverabilityPolicy,
                (builder, pushContext) =>
                {
                    var dispatchBehavior = new DispatchTimeoutBehavior(
                        builder.Build<IDispatchMessages>(),
                        builder.Build<IPersistTimeouts>(),
                        requiredTransactionSupport);

                    return dispatchBehavior.Invoke(pushContext);
                });

            return satelliteAddress;
        }
        public async Task Invoke_should_pass_transport_transaction_from_message_context()
        {
            var messageDispatcher = new FakeMessageDispatcher();
            var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow);
            var timeoutData = CreateTimeout();
            await timeoutPersister.Add(timeoutData, null);
            var context = CreateContext(timeoutData.Id);

            var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope);
            await behavior.Invoke(context);

            Assert.AreSame(context.TransportTransaction, messageDispatcher.TransportTransactionUsed, "Wrong transport transaction passed to the dispatcher");
        }