コード例 #1
0
        public void TestResourceHolder()
        {
            var h1 = new RabbitResourceHolder();
            var h2 = new RabbitResourceHolder();
            var connectionFactory = new Mock <IConnectionFactory>();

            TransactionSynchronizationManager.SetActualTransactionActive(true);
            ConnectionFactoryUtils.BindResourceToTransaction(h1, connectionFactory.Object, true);
            Assert.Same(h1, ConnectionFactoryUtils.BindResourceToTransaction(h2, connectionFactory.Object, true));
            TransactionSynchronizationManager.Clear();
        }
コード例 #2
0
        public void TestReceiveBlockingGlobalTx()
        {
            template.ConvertAndSend(ROUTE, "blockGTXNoTO");
            var resourceHolder = ConnectionFactoryUtils
                                 .GetTransactionalResourceHolder(template.ConnectionFactory, true);

            TransactionSynchronizationManager.SetActualTransactionActive(true);
            ConnectionFactoryUtils.BindResourceToTransaction(resourceHolder, template.ConnectionFactory, true);
            template.ReceiveTimeout      = -1;
            template.IsChannelTransacted = true;
            var o = template.ReceiveAndConvert <string>(ROUTE);

            resourceHolder.CommitAll();
            resourceHolder.CloseAll();
            Assert.Same(resourceHolder, TransactionSynchronizationManager.UnbindResource(template.ConnectionFactory));
            Assert.NotNull(o);
            Assert.Equal("blockGTXNoTO", o);
            template.ReceiveTimeout = 0;
            Assert.Null(template.Receive(ROUTE));
        }