Esempio n. 1
0
        public void MessageProcessorTests_process()
        {
            MessageProcessingResult result = _processor.ProcessMessage(_message, null);

            Assert.IsTrue(result.WasSuccessful);
            Assert.AreEqual(1, _testHandler1Called);
            Assert.AreEqual(1, _testHandler2Called);
            Assert.AreEqual(0, _testHandler3Called);
        }
Esempio n. 2
0
        public void MessageProcessorTests_Unknown_message()
        {
            _typeMapping.Remove(typeof(TestMessage));
            MessageProcessingResult result = _processor.ProcessMessage(_message, null);

            Assert.IsFalse(result.WasSuccessful);
            Assert.AreEqual(0, _testHandler1Called);
            Assert.AreEqual(0, _testHandler2Called);
            Assert.AreEqual(0, _testHandler3Called);
        }
Esempio n. 3
0
        public void MessageProcessorTests_Exception_Thrown_in_Handler()
        {
            _typeMapping[typeof(TestMessage)].Add(typeof(TestHandler3));
            MessageProcessingResult result = _processor.ProcessMessage(_message, null);

            Assert.IsFalse(result.WasSuccessful);
            Assert.AreEqual(1, _testHandler1Called);
            Assert.AreEqual(1, _testHandler2Called);
            Assert.AreEqual(1, _testHandler3Called);
        }
Esempio n. 4
0
        protected override async Task <int> DoWork(bool isPrimaryReader, CancellationToken token)
        {
            int              cnt              = 0;
            SSSBMessage      msg              = null;
            SqlConnection    dbconnection     = null;
            TransactionScope transactionScope = null;

            var disposable = this.Coordinator.ReadThrottle(isPrimaryReader);

            try
            {
                TransactionOptions tranOptions = new TransactionOptions();
                tranOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                tranOptions.Timeout        = TimeSpan.FromMinutes(60);
                transactionScope           = new TransactionScope(TransactionScopeOption.RequiresNew, tranOptions, TransactionScopeAsyncFlowOption.Enabled);
            }
            catch
            {
                disposable.Dispose();
                throw;
            }

            using (transactionScope)
            {
                try
                {
                    dbconnection = await this.TryGetConnection(token);

                    msg = await this.ReadMessage(isPrimaryReader, this.taskId, token, dbconnection).ConfigureAwait(false);
                }
                finally
                {
                    disposable.Dispose();
                }

                cnt = msg == null ? 0 : 1;

                using (dbconnection)
                {
                    if (msg != null)
                    {
                        this.Coordinator.OnBeforeDoWork(this);
                        try
                        {
                            MessageProcessingResult res = await this.DispatchMessage(msg, this.taskId, token, dbconnection).ConfigureAwait(false);

                            if (res.isRollBack)
                            {
                                await this.OnRollback(msg, token);

                                return(cnt);
                            }
                        }
                        catch (Exception ex)
                        {
                            this.OnProcessMessageException(ex, msg);
                            throw;
                        }
                        finally
                        {
                            this.Coordinator.OnAfterDoWork(this);
                        }

                        transactionScope.Complete();
                    }
                }
            }

            return(cnt);
        }