private void PerformTestCase() { if (_totalLoopCount <= 0) { for (long totalIndex = 0; ; totalIndex++) { ProcessGetInsertIteration(); if (totalIndex >= _reportingInterval) { try { string query = string.Format("Select count(*) from {0}", _collectionName); var count = _collection.ExecuteScalar(query); _adapter.WriteObject(DateTime.Now.ToString() + ": Docouments count: " + count); totalIndex = 1; } catch (Exception e) { ++errorCount; } } } } else { for (long totalIndex = 0; totalIndex < _totalLoopCount; totalIndex++) { ProcessGetInsertIteration(); if (totalIndex >= _reportingInterval) { try { string query = string.Format("Select count(*) from {0}", _collectionName); long count = (long)_collection.ExecuteScalar(query); //_parent.WriteObject(DateTime.Now.ToString() + ": Docouments count: "+count ); _adapter.WriteObject(DateTime.Now.ToString() + ": Docouments count: " + count); totalIndex = 1; } catch (Exception e) { ++errorCount; } } } } }
/// <summary> /// Main test starting point. This method instantiate multiple threads and keeps track of /// all of them. /// </summary> public void Test() { try { threads = new Thread[_threadCount]; string pid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); for (int threadIndex = 0; threadIndex < _threadCount; threadIndex++) { int docCount = _maxDocuments / _threadCount; if (threadIndex == 0) { docCount += _maxDocuments % _threadCount; } try { string query = string.Format("Select count(*) from {0}", _collectionName); Double x = (Double)parent.Database.GetCollection(_collectionName).ExecuteScalar(query); Order._serialKey = (int)x; } catch (Exception e) { adapter.WriteObject(e.ToString()); } ThreadContainer tc = new ThreadContainer(_collectionName, _totalLoopCount, _testCaseIterations, _testCaseIterationDelay, _getsPerIteration, _updatesPerIteration, _instertsPerIteration, _deletesPerIteration, _reportingInterval, threadIndex, parent, adapter, this); ThreadStart threadDelegate = new ThreadStart(tc.DoTest); threads[threadIndex] = new Thread(threadDelegate); threads[threadIndex].Name = "ThreadIndex: " + threadIndex; threads[threadIndex].Start(); } adapter.Listen(); //--- wait on threads to complete there work before finishing //for (int threadIndex = 0; threadIndex < threads.Length; threadIndex++) //{ // threads[threadIndex].Join(); //} } catch (Exception e) { Console.Error.WriteLine("Error: " + e.Message); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); } }