Ejemplo n.º 1
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");
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 3
0
        public void TestInitWithNoLocationSet()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Initialize(rmId.ToString());

            Assert.AreEqual(Directory.GetCurrentDirectory(), logger.Location);
        }
Ejemplo n.º 4
0
        public void TestInitWithNoLocationSet()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            logger.Initialize(this.resourceManagerId);

            Assert.AreEqual(Directory.GetCurrentDirectory(), logger.Location);
        }
Ejemplo n.º 5
0
        public void TestInitWithNonDefaultLocationSet()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

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

            Assert.AreEqual(nonDefaultLogLocation, logger.Location);
        }
Ejemplo n.º 6
0
        public void TestNothingToRecover()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

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

            Assert.IsTrue(logger.GetRecoverables().Length == 0);
        }
Ejemplo n.º 7
0
        public void TestInitWithNonDefaultLocationSet()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

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

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

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

            Assert.IsTrue(logger.GetRecoverables().Length == 0);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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");
        }
Ejemplo n.º 11
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
            {
            }
        }
Ejemplo n.º 12
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.");
                }
            }
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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");
        }