Example #1
0
        public void TestConfigureRecoveryPolicyLoggerUsingDefaultLogger(string location, bool autoCreate)
        {
            string testuri = string.Format("activemq:tcp://${{activemqhost}}:61616" +
                                           "?nms.RecoveryPolicy.RecoveryLogger.Location={0}" +
                                           "&nms.RecoveryPolicy.RecoveryLogger.AutoCreateLocation={1}",
                                           location, autoCreate);

            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(testuri));

            using (INetTxConnection connection = factory.CreateNetTxConnection())
            {
                NetTxConnection netTxConnection = connection as NetTxConnection;

                Assert.IsNotNull(netTxConnection);
                NetTxRecoveryPolicy policy = netTxConnection.RecoveryPolicy;

                Assert.AreEqual("file", policy.RecoveryLoggerType);

                RecoveryFileLogger logger = policy.RecoveryLogger as RecoveryFileLogger;

                Assert.IsNotNull(logger);
                Assert.AreEqual(location, logger.Location);
                Assert.AreEqual(autoCreate, logger.AutoCreateLocation);
            }
        }
Example #2
0
        public void TestLogTransactionRecord()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            byte[] globalId     = new byte[32];
            byte[] branchQ      = new byte[32];
            byte[] recoveryData = new byte[256];

            Random gen = new Random();

            gen.NextBytes(globalId);
            gen.NextBytes(branchQ);
            gen.NextBytes(recoveryData);

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(rmId);

            XATransactionId xid = new XATransactionId();

            xid.GlobalTransactionId = globalId;
            xid.BranchQualifier     = branchQ;

            logger.LogRecoveryInfo(xid, recoveryData);

            Assert.IsTrue(File.Exists(Path.Combine(logger.Location, rmId + ".bin")),
                          "Recovery File was not created");
        }
Example #3
0
        public void TestPurgeTransactionRecord()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            byte[] globalId     = new byte[32];
            byte[] branchQ      = new byte[32];
            byte[] recoveryData = new byte[256];

            Random gen = new Random();

            gen.NextBytes(globalId);
            gen.NextBytes(branchQ);
            gen.NextBytes(recoveryData);

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(rmId.ToString());

            XATransactionId xid = new XATransactionId();

            xid.GlobalTransactionId = globalId;
            xid.BranchQualifier     = branchQ;

            logger.LogRecoveryInfo(xid, recoveryData);

            Assert.IsTrue(File.Exists(logger.Location + Path.DirectorySeparatorChar + rmId.ToString() + ".bin"),
                          "Recovery File was not created");

            logger.Purge();

            Assert.IsFalse(File.Exists(logger.Location + Path.DirectorySeparatorChar + rmId.ToString() + ".bin"),
                           "Recovery File was not created");
        }
Example #4
0
        public void TestInitWithNoLocationSet()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Initialize(rmId.ToString());

            Assert.AreEqual(Directory.GetCurrentDirectory(), logger.Location);
        }
Example #5
0
        public void TestInitWithNoLocationSet()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Initialize(this.resourceManagerId);

            Assert.AreEqual(Directory.GetCurrentDirectory(), logger.Location);
        }
Example #6
0
        public void TestNothingToRecover()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(rmId.ToString());

            Assert.IsTrue(logger.GetRecoverables().Length == 0);
        }
Example #7
0
        public void TestInitWithNonDefaultLocationSet()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(rmId.ToString());

            Assert.AreEqual(nonDefaultLogLocation, logger.Location);
        }
Example #8
0
        public void TestNothingToRecover()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(this.resourceManagerId);

            Assert.IsTrue(logger.GetRecoverables().Length == 0);
        }
Example #9
0
        public void TestInitWithNonDefaultLocationSet()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(this.resourceManagerId);

            Assert.AreEqual(nonDefaultLogLocation, logger.Location);
        }
Example #10
0
 private string GetFilename(RecoveryFileLogger logger, TransactionData transactionData)
 {
     return(string.Format(
                "{0}{1}{2}_{3}.bin",
                logger.Location,
                Path.DirectorySeparatorChar,
                this.resourceManagerId.ToString(),
                BitConverter.ToString(transactionData.Transaction.GlobalTransactionId).Replace("-", string.Empty)));
 }
Example #11
0
        public void TestInitWithAutoCreateLocation()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            Assert.IsFalse(Directory.Exists(autoCreatePath));

            logger.AutoCreateLocation = true;
            logger.Location           = autoCreatePath;
            logger.Initialize(rmId.ToString());

            Assert.IsTrue(Directory.Exists(autoCreatePath));
            Assert.AreEqual(autoCreatePath, logger.Location);
        }
Example #12
0
        public void TestLogTransactionRecord()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(this.resourceManagerId);

            TransactionData transactionData = new TransactionData();

            logger.LogRecoveryInfo(transactionData.Transaction, transactionData.RecoveryData);

            Assert.IsTrue(File.Exists(this.GetFilename(logger, transactionData)),
                          "Recovery File was not created");
        }
Example #13
0
        public void TestInitWithLocationSetToBadPath()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Location = this.nonExistantPath;

            try
            {
                logger.Initialize(rmId.ToString());
                Assert.Fail("Should have detected an invalid dir and thrown an exception");
            }
            catch
            {
            }
        }
Example #14
0
        public void TestRecoverLoggedRecord()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Location = this.nonDefaultLogLocation;
            logger.Initialize(this.resourceManagerId);

            TransactionData transactionData01 = new TransactionData();

            logger.LogRecoveryInfo(transactionData01.Transaction, transactionData01.RecoveryData);
            TransactionData transactionData02 = new TransactionData();

            logger.LogRecoveryInfo(transactionData02.Transaction, transactionData02.RecoveryData);

            Assert.IsTrue(File.Exists(this.GetFilename(logger, transactionData01)), "Recovery File was not created");
            Assert.IsTrue(File.Exists(this.GetFilename(logger, transactionData02)), "Recovery File was not created");
            Assert.AreEqual(2, logger.GetRecoverables().Length, "Did not recover the logged record.");

            KeyValuePair <XATransactionId, byte[]>[] records = logger.GetRecoverables();
            Assert.AreEqual(2, records.Length);

            foreach (var keyValuePair in records)
            {
                if (BitConverter.ToString(keyValuePair.Key.GlobalTransactionId) == BitConverter.ToString(transactionData01.Transaction.GlobalTransactionId))
                {
                    Assert.AreEqual(transactionData01.GlobalId, keyValuePair.Key.GlobalTransactionId, "Incorrect Global TX Id returned");
                    Assert.AreEqual(transactionData01.BranchQ, keyValuePair.Key.BranchQualifier, "Incorrect Branch Qualifier returned");
                    Assert.AreEqual(transactionData01.RecoveryData, keyValuePair.Value, "Incorrect Recovery Information returned");
                }
                else if (BitConverter.ToString(keyValuePair.Key.GlobalTransactionId) == BitConverter.ToString(transactionData02.Transaction.GlobalTransactionId))
                {
                    Assert.AreEqual(transactionData02.GlobalId, keyValuePair.Key.GlobalTransactionId, "Incorrect Global TX Id returned");
                    Assert.AreEqual(transactionData02.BranchQ, keyValuePair.Key.BranchQualifier, "Incorrect Branch Qualifier returned");
                    Assert.AreEqual(transactionData02.RecoveryData, keyValuePair.Value, "Incorrect Recovery Information returned");
                }
                else
                {
                    Assert.Fail("Transaction not found.");
                }
            }
        }
Example #15
0
        public void TestConfigureRecoveryPolicyLoggerType(
            [Values("tcp://${activemqhost}:61616?nms.RecoveryPolicy.RecoveryLoggerType=file")]
            string baseConnectionURI)
        {
            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));

            using (INetTxConnection connection = factory.CreateNetTxConnection())
            {
                NetTxConnection netTxConnection = connection as NetTxConnection;

                Assert.IsNotNull(netTxConnection);
                NetTxRecoveryPolicy policy = netTxConnection.RecoveryPolicy;

                Assert.AreEqual("file", policy.RecoveryLoggerType);

                RecoveryFileLogger logger = policy.RecoveryLogger as RecoveryFileLogger;

                Assert.IsNotNull(logger);
                Assert.AreEqual(Directory.GetCurrentDirectory(), logger.Location);
            }
        }
Example #16
0
        public void TestNoRecoverAfterFailOnTransactionWhenLogDeleted()
        {
            // Test initialize - Fills in DB with data to send.
            PrepareDatabase();

            INetTxConnectionFactory factory      = new NetTxConnectionFactory(ReplaceEnvVar(connectionURI));
            NetTxConnectionFactory  netTxFactory = factory as NetTxConnectionFactory;
            RecoveryFileLogger      logger       = netTxFactory.RecoveryPolicy.RecoveryLogger as RecoveryFileLogger;
            string logDirectory = logger.Location;

            using (INetTxConnection connection = factory.CreateNetTxConnection())
            {
                connection.ExceptionListener += this.OnException;
                connection.Start();

                ITransport         transport = (connection as Connection).ITransport;
                TcpFaultyTransport tcpFaulty = transport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport;
                Assert.IsNotNull(tcpFaulty);
                tcpFaulty.OnewayCommandPreProcessor += this.FailOnCommitTransportHook;

                ReadFromDbAndProduceToQueueWithCommit(connection);

                Thread.Sleep(2000);
            }

            // transaction should not have been commited
            VerifyNoMessagesInQueueNoRecovery();

            // delete all recovery files
            foreach (string file in Directory.GetFiles(logDirectory, "*.bin"))
            {
                File.Delete(file);
            }

            // verify sql server has commited the transaction
            VerifyDatabaseTableIsEmpty();

            // check messages are NOT present in the queue bacause recovery file has been deleted
            VerifyNoMessagesInQueue();
        }
Example #17
0
        public void TestPurgeTransactionRecord()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(this.resourceManagerId.ToString());

            TransactionData transactionData01 = new TransactionData();

            logger.LogRecoveryInfo(transactionData01.Transaction, transactionData01.RecoveryData);
            TransactionData transactionData02 = new TransactionData();

            logger.LogRecoveryInfo(transactionData02.Transaction, transactionData02.RecoveryData);

            Assert.IsTrue(File.Exists(this.GetFilename(logger, transactionData01)), "Recovery File was not created");
            Assert.IsTrue(File.Exists(this.GetFilename(logger, transactionData02)), "Recovery File was not created");

            logger.Purge();

            this.AssertFileIsDeleted(this.GetFilename(logger, transactionData01), 1000);
            this.AssertFileIsDeleted(this.GetFilename(logger, transactionData02), 1000);
        }
Example #18
0
        public void TestRecoverLoggedRecord()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            byte[] globalId     = new byte[32];
            byte[] branchQ      = new byte[32];
            byte[] recoveryData = new byte[256];

            Random gen = new Random();

            gen.NextBytes(globalId);
            gen.NextBytes(branchQ);
            gen.NextBytes(recoveryData);

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(rmId.ToString());

            XATransactionId xid = new XATransactionId();

            xid.GlobalTransactionId = globalId;
            xid.BranchQualifier     = branchQ;

            logger.LogRecoveryInfo(xid, recoveryData);

            Assert.IsTrue(File.Exists(logger.Location + Path.DirectorySeparatorChar + rmId.ToString() + ".bin"),
                          "Recovery File was not created");
            Assert.IsTrue(logger.GetRecoverables().Length == 1,
                          "Did not recover the logged record.");

            KeyValuePair <XATransactionId, byte[]>[] records = logger.GetRecoverables();
            Assert.AreEqual(1, records.Length);

            Assert.AreEqual(globalId, records[0].Key.GlobalTransactionId, "Incorrect Global TX Id returned");
            Assert.AreEqual(branchQ, records[0].Key.BranchQualifier, "Incorrect Branch Qualifier returned");
            Assert.AreEqual(recoveryData, records[0].Value, "Incorrect Recovery Information returned");
        }