Example #1
0
        public void TestNothingToRecover()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

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

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

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

            Assert.IsTrue(logger.GetRecoverables().Length == 0);
        }
Example #3
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 #4
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");
        }