public virtual void TestNullTPCs()
        {
            int numObjects = Random.Next(4) + 3; // between [3, 6]

            ITwoPhaseCommit[] tpcs = new ITwoPhaseCommit[numObjects];
            bool setNull           = false;

            for (int i = 0; i < tpcs.Length; i++)
            {
                bool isNull = Random.NextDouble() < 0.3;
                if (isNull)
                {
                    setNull = true;
                    tpcs[i] = null;
                }
                else
                {
                    tpcs[i] = new TwoPhaseCommitImpl(false, false, false);
                }
            }

            if (!setNull)
            {
                // none of the TPCs were picked to be null, pick one at random
                int idx = Random.Next(numObjects);
                tpcs[idx] = null;
            }

            // following call would fail if TPCTool won't handle null TPCs properly
            TwoPhaseCommitTool.Execute(tpcs);
        }
        public virtual void TestRollback()
        {
            // tests that rollback is called if failure occurs at any stage
            int numObjects = Random().Next(8) + 3; // between [3, 10]

            TwoPhaseCommitImpl[] objects = new TwoPhaseCommitImpl[numObjects];
            for (int i = 0; i < objects.Length; i++)
            {
                bool failOnPrepare = Random().NextBoolean();
                // we should not hit failures on commit usually
                bool failOnCommit   = Random().NextDouble() < 0.05;
                bool railOnRollback = Random().NextBoolean();
                objects[i] = new TwoPhaseCommitImpl(failOnPrepare, failOnCommit, railOnRollback);
            }

            bool anyFailure = false;

            try
            {
                TwoPhaseCommitTool.Execute(objects);
            }
            catch (Exception t)
            {
                anyFailure = true;
            }

            if (anyFailure)
            {
                // if any failure happened, ensure that rollback was called on all.
                foreach (TwoPhaseCommitImpl tpc in objects)
                {
                    Assert.IsTrue(tpc.RollbackCalled, "rollback was not called while a failure occurred during the 2-phase commit");
                }
            }
        }
        public virtual void TestPrepareThenCommit()
        {
            // tests that prepareCommit() is called on all objects before commit()
            TwoPhaseCommitImpl[] objects = new TwoPhaseCommitImpl[2];
            for (int i = 0; i < objects.Length; i++)
            {
                objects[i] = new TwoPhaseCommitImpl(false, false, false);
            }

            // following call will fail if commit() is called before all prepare() were
            TwoPhaseCommitTool.Execute(objects);
        }