Ejemplo n.º 1
0
        /// <exception cref="System.Exception"></exception>
        protected override void Invoke()
        {
            AbstractDb4oTestCase toTest = Subject();
            MethodInfo           method = GetMethod();

            InvokeConcurrencyMethod(toTest, method);
        }
 /// <exception cref="System.Exception"></exception>
 public void Run()
 {
     AbstractDb4oTestCase.Fixture().Close();
     AbstractDb4oTestCase.Fixture().Clean();
     AbstractDb4oTestCase.Fixture().Config().ReadOnly(true);
     AbstractDb4oTestCase.Fixture().Open(this._enclosing);
 }
Ejemplo n.º 3
0
 internal RunnableTestMethod(ConcurrencyTestMethod _enclosing, AbstractDb4oTestCase
                             toTest, MethodInfo method, int seq, bool showSeq)
 {
     this._enclosing = _enclosing;
     this.toTest     = toTest;
     this.method     = method;
     this.seq        = seq;
     this.showSeq    = showSeq;
 }
Ejemplo n.º 4
0
        /// <exception cref="System.Exception"></exception>
        private void InvokeConcurrencyMethod(AbstractDb4oTestCase toTest, MethodInfo method
                                             )
        {
            Type[] parameters           = Sharpen.Runtime.GetParameterTypes(method);
            bool   hasSequenceParameter = false;

            if (parameters.Length == 2)
            {
                // ExtObjectContainer, seq
                hasSequenceParameter = true;
            }
            int threadCount = toTest.ThreadCount();

            threads  = new Thread[threadCount];
            failures = new Exception[threadCount];
            for (int i = 0; i < threadCount; ++i)
            {
                threads[i] = new Thread(new ConcurrencyTestMethod.RunnableTestMethod(this, toTest
                                                                                     , method, i, hasSequenceParameter), "ConcurrencyTestMethod.invokeConcurrencyMethod Thread["
                                        + i + "]");
            }
            // start threads simultaneously
            for (int i = 0; i < threadCount; ++i)
            {
                threads[i].Start();
            }
            // wait for the threads to end
            for (int i = 0; i < threadCount; ++i)
            {
                threads[i].Join();
            }
            // check if any of the threads ended abnormally
            for (int i = 0; i < threadCount; ++i)
            {
                if (failures[i] != null)
                {
                    // TODO: show all failures by throwing another kind of exception.
                    throw failures[i];
                }
            }
            // check test result
            CheckConcurrencyMethod(toTest, method.Name);
        }
Ejemplo n.º 5
0
 /// <exception cref="System.Exception"></exception>
 private void InvokeConcurrencyMethod(AbstractDb4oTestCase toTest, MethodInfo method
     )
 {
     var parameters = Runtime.GetParameterTypes(method);
     var hasSequenceParameter = false;
     if (parameters.Length == 2)
     {
         // ExtObjectContainer, seq
         hasSequenceParameter = true;
     }
     var threadCount = toTest.ThreadCount();
     threads = new Thread[threadCount];
     failures = new Exception[threadCount];
     for (var i = 0; i < threadCount; ++i)
     {
         threads[i] = new Thread(new RunnableTestMethod(this, toTest
             , method, i, hasSequenceParameter), "ConcurrencyTestMethod.invokeConcurrencyMethod Thread["
                                                 + i + "]");
     }
     // start threads simultaneously
     for (var i = 0; i < threadCount; ++i)
     {
         threads[i].Start();
     }
     // wait for the threads to end
     for (var i = 0; i < threadCount; ++i)
     {
         threads[i].Join();
     }
     // check if any of the threads ended abnormally
     for (var i = 0; i < threadCount; ++i)
     {
         if (failures[i] != null)
         {
             // TODO: show all failures by throwing another kind of exception.
             throw failures[i];
         }
     }
     // check test result
     CheckConcurrencyMethod(toTest, method.Name);
 }
Ejemplo n.º 6
0
        /// <exception cref="System.Exception"></exception>
        private void CheckConcurrencyMethod(AbstractDb4oTestCase toTest, string testMethodName
                                            )
        {
            MethodInfo checkMethod = CheckMethodFor(toTest.GetType(), testMethodName);

            if (null == checkMethod)
            {
                return;
            }
            // pass ExtObjectContainer as a param to check method
            IExtObjectContainer oc = Fixture().Db();

            try
            {
                checkMethod.Invoke(toTest, new object[] { oc });
            }
            finally
            {
                oc.Close();
            }
        }
Ejemplo n.º 7
0
 internal virtual IMultiSessionFixture Fixture()
 {
     return((IMultiSessionFixture)AbstractDb4oTestCase.Fixture());
 }
Ejemplo n.º 8
0
 /// <exception cref="System.Exception"></exception>
 private void CheckConcurrencyMethod(AbstractDb4oTestCase toTest, string testMethodName
     )
 {
     var checkMethod = CheckMethodFor(toTest.GetType(), testMethodName);
     if (null == checkMethod)
     {
         return;
     }
     // pass ExtObjectContainer as a param to check method
     var oc = Fixture().Db();
     try
     {
         checkMethod.Invoke(toTest, new object[] {oc});
     }
     finally
     {
         oc.Close();
     }
 }
Ejemplo n.º 9
0
 internal RunnableTestMethod(ConcurrencyTestMethod _enclosing, AbstractDb4oTestCase
     toTest, MethodInfo method, int seq, bool showSeq)
 {
     this._enclosing = _enclosing;
     this.toTest = toTest;
     this.method = method;
     this.seq = seq;
     this.showSeq = showSeq;
 }