List:Commits« Previous MessageNext Message »
From:Magnus Svensson Date:July 22 2008 1:28pm
Subject:bzr commit into mysql-5.1-telco-6.4 branch (msvensson:2676)
View as plain text  
#At file:///data/msvensson/mysql/5.1-telco-6.4/

 2676 Magnus Svensson	2008-07-22 [merge]
      Merge
modified:
  storage/ndb/test/include/NDBT_Test.hpp
  storage/ndb/test/include/NdbMgmd.hpp
  storage/ndb/test/ndbapi/acrt/NdbRepStress.cpp
  storage/ndb/test/ndbapi/testBasic.cpp
  storage/ndb/test/ndbapi/testBasicAsynch.cpp
  storage/ndb/test/ndbapi/testMgm.cpp
  storage/ndb/test/ndbapi/testPartitioning.cpp
  storage/ndb/test/ndbapi/test_event.cpp
  storage/ndb/test/src/NDBT_Tables.cpp
  storage/ndb/test/src/NDBT_Test.cpp

=== modified file 'storage/ndb/test/include/NDBT_Test.hpp'
--- a/storage/ndb/test/include/NDBT_Test.hpp	2008-06-23 12:37:22 +0000
+++ b/storage/ndb/test/include/NDBT_Test.hpp	2008-07-22 13:25:43 +0000
@@ -122,13 +122,11 @@ typedef int (NDBT_TESTFUNC)(NDBT_Context
 
 class NDBT_Step {
 public:
-  NDBT_Step(NDBT_TestCase* ptest, 
-		const char* pname,
-		NDBT_TESTFUNC* pfunc);
+  NDBT_Step(NDBT_TestCase* ptest,
+            const char* pname,
+            NDBT_TESTFUNC* pfunc);
   virtual ~NDBT_Step() {}
   int execute(NDBT_Context*);
-  virtual int setUp(Ndb_cluster_connection&) = 0;
-  virtual void tearDown() = 0;
   void setContext(NDBT_Context*);
   NDBT_Context* getContext();
   void print();
@@ -141,23 +139,18 @@ protected:
   NDBT_TESTFUNC* func;
   NDBT_TestCase* testcase;
   int step_no;
-};
 
-class NDBT_NdbApiStep : public NDBT_Step {
+private:
+  int setUp(Ndb_cluster_connection&);
+  void tearDown();
+  Ndb* m_ndb;
+
 public:
-  NDBT_NdbApiStep(NDBT_TestCase* ptest,
-		  const char* pname,
-		  NDBT_TESTFUNC* pfunc);
-  virtual ~NDBT_NdbApiStep() {}
-  virtual int setUp(Ndb_cluster_connection&);
-  virtual void tearDown();
+  Ndb* getNdb() const;
 
-  Ndb* getNdb();
-protected:
-  Ndb* ndb;
 };
 
-class NDBT_ParallelStep : public NDBT_NdbApiStep {
+class NDBT_ParallelStep : public NDBT_Step {
 public:
   NDBT_ParallelStep(NDBT_TestCase* ptest,
 		    const char* pname,
@@ -165,7 +158,7 @@ public:
   virtual ~NDBT_ParallelStep() {}
 };
 
-class NDBT_Verifier : public NDBT_NdbApiStep {
+class NDBT_Verifier : public NDBT_Step {
 public:
   NDBT_Verifier(NDBT_TestCase* ptest,
 		const char* name,
@@ -173,7 +166,7 @@ public:
   virtual ~NDBT_Verifier() {}
 };
 
-class NDBT_Initializer  : public NDBT_NdbApiStep {
+class NDBT_Initializer  : public NDBT_Step {
 public:
   NDBT_Initializer(NDBT_TestCase* ptest,
 		   const char* name,
@@ -181,7 +174,7 @@ public:
   virtual ~NDBT_Initializer() {}
 };
 
-class NDBT_Finalizer  : public NDBT_NdbApiStep {
+class NDBT_Finalizer  : public NDBT_Step {
 public:
   NDBT_Finalizer(NDBT_TestCase* ptest,
 		 const char* name,
@@ -190,6 +183,12 @@ public:
 };
 
 
+enum NDBT_DriverType {
+  DummyDriver,
+  NdbApiDriver
+};
+
+
 class NDBT_TestCase {
 public:
   NDBT_TestCase(NDBT_TestSuite* psuite, 
@@ -211,10 +210,13 @@ public:
   virtual bool tableExists(NdbDictionary::Table* aTable) = 0;
   virtual bool isVerify(const NdbDictionary::Table* aTable) = 0;
 
-  virtual void saveTestResult(const NdbDictionary::Table* ptab, int result) = 0;
+  virtual void saveTestResult(const char*, int result) = 0;
   virtual void printTestResult() = 0;
   void initBeforeTest(){ timer.doReset();};
 
+  void setDriverType(NDBT_DriverType type) { m_driverType= type; }
+  NDBT_DriverType getDriverType() const { return m_driverType; }
+
   /**
    * Get no of steps running/completed
    */
@@ -243,6 +245,7 @@ protected:
   Properties props;
   NdbTimer timer;
   bool isVerifyTables;
+  NDBT_DriverType m_driverType;
 };
 
 static const int FAILED_TO_CREATE = 1000;
@@ -281,7 +284,7 @@ public:
   virtual ~NDBT_TestCaseImpl1();
   int addStep(NDBT_Step*);
   int addVerifier(NDBT_Verifier*);
-  int addInitializer(NDBT_Initializer*);
+  int addInitializer(NDBT_Initializer*, bool first= false);
   int addFinalizer(NDBT_Finalizer*);
   void addTable(const char*, bool);
   bool tableExists(NdbDictionary::Table*);
@@ -300,7 +303,7 @@ public:
 private:
   static const int  NORESULT = 999;
   
-  void saveTestResult(const NdbDictionary::Table* ptab, int result);
+  void saveTestResult(const char*, int result);
   void printTestResult();
 
   void startStepInThread(int stepNo, NDBT_Context* ctx);
@@ -371,14 +374,24 @@ public:
 
   void setTemporaryTables(bool val);
   bool getTemporaryTables() const;
+
+  void setLogging(bool val);
+  bool getLogging() const;
+
+  int createTables(Ndb_cluster_connection&) const;
+  int dropTables(Ndb_cluster_connection&) const;
+
+  void setDriverType(NDBT_DriverType type) { m_driverType= type; }
+  NDBT_DriverType getDriverType() const { return m_driverType; }
+
 private:
   int executeOne(Ndb_cluster_connection&,
 		 const char* _tabname, const char* testname = NULL);
   int executeAll(Ndb_cluster_connection&,
 		 const char* testname = NULL);
   void execute(Ndb_cluster_connection&,
-	       Ndb*, const NdbDictionary::Table*, const char* testname = NULL);
-  
+	       const NdbDictionary::Table*, const char* testname = NULL);
+
   int report(const char* _tcname = NULL);
   int reportAllTables(const char* );
   const char* name;
@@ -392,13 +405,14 @@ private:
   int loops;
   int timer;
   NdbTimer testSuiteTimer;
-  bool createTable;
+  bool m_createTable;
+  bool m_createAll;
   bool diskbased;
   bool runonce;
   const char* tsname;
-  bool createAllTables;
   bool temporaryTables;
-  bool nologging;
+  bool m_logging;
+  NDBT_DriverType m_driverType;
 };
 
 
@@ -413,10 +427,18 @@ C##suitname():NDBT_TestSuite(#suitname){
  NDBT_Initializer* pti; pti = NULL; \
  NDBT_Finalizer* ptf; ptf = NULL; 
 
+// The default driver type to use for all tests in suite
+#define DRIVER(type) \
+  setDriverType(type)
+
 #define TESTCASE(testname, comment) \
   pt = new NDBT_TestCaseImpl1(this, testname, comment); \
   addTest(pt);
 
+// The driver type to use for a particular testcase
+#define TESTCASE_DRIVER(type) \
+  pt->setDriverType(type);
+
 #define TC_PROPERTY(propname, propval) \
   pt->setProperty(propname, propval);
 
@@ -464,6 +486,6 @@ C##suitname():NDBT_TestSuite(#suitname){
  } } ; C##suitname suitname
 
 // Helper functions for retrieving variables from NDBT_Step
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
+#define GETNDB(ps) ((NDBT_Step*)ps)->getNdb()
 
 #endif

=== modified file 'storage/ndb/test/include/NdbMgmd.hpp'
--- a/storage/ndb/test/include/NdbMgmd.hpp	2008-06-23 12:37:22 +0000
+++ b/storage/ndb/test/include/NdbMgmd.hpp	2008-07-22 13:25:43 +0000
@@ -26,7 +26,7 @@ public:
     m_connect_str(getenv("NDB_CONNECTSTRING"))
     {
       if (!m_connect_str.length()){
-        fprintf(stderr, "Could not init NdbConnectCtring");
+        fprintf(stderr, "Could not init NdbConnectString");
         abort();
       }
     }

=== modified file 'storage/ndb/test/ndbapi/acrt/NdbRepStress.cpp'
--- a/storage/ndb/test/ndbapi/acrt/NdbRepStress.cpp	2008-03-03 15:10:42 +0000
+++ b/storage/ndb/test/ndbapi/acrt/NdbRepStress.cpp	2008-07-22 13:25:43 +0000
@@ -45,10 +45,6 @@ urandom(uint m)
   return r;
 }
 
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-/*
-*/
-
 bool
 syncSlaveWithMaster()
 {

=== modified file 'storage/ndb/test/ndbapi/testBasic.cpp'
--- a/storage/ndb/test/ndbapi/testBasic.cpp	2007-11-02 16:23:17 +0000
+++ b/storage/ndb/test/ndbapi/testBasic.cpp	2008-07-22 13:25:43 +0000
@@ -19,8 +19,6 @@
 #include <UtilTransactions.hpp>
 #include <NdbRestarter.hpp>
 
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
 
 /**
  * TODO 

=== modified file 'storage/ndb/test/ndbapi/testBasicAsynch.cpp'
--- a/storage/ndb/test/ndbapi/testBasicAsynch.cpp	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/test/ndbapi/testBasicAsynch.cpp	2008-07-22 13:25:43 +0000
@@ -19,8 +19,6 @@
 #include "HugoAsynchTransactions.hpp"
 #include "UtilTransactions.hpp"
 
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
 int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
 
   int records = ctx->getNumRecords();

=== modified file 'storage/ndb/test/ndbapi/testMgm.cpp'
--- a/storage/ndb/test/ndbapi/testMgm.cpp	2008-06-23 12:52:49 +0000
+++ b/storage/ndb/test/ndbapi/testMgm.cpp	2008-07-22 13:25:43 +0000
@@ -642,6 +642,7 @@ done:
 }
 
 NDBT_TESTSUITE(testMgm);
+DRIVER(DummyDriver); /* turn off use of NdbApi */
 TESTCASE("ApiSessionFailure",
 	 "Test failures in MGMAPI session"){
   INITIALIZER(runTestApiSession);
@@ -681,6 +682,8 @@ NDBT_TESTSUITE_END(testMgm);
 
 int main(int argc, const char** argv){
   ndb_init();
+  testMgm.setCreateTable(false);
+  testMgm.setRunAllTables(true);
   return testMgm.execute(argc, argv);
 }
 

=== modified file 'storage/ndb/test/ndbapi/testPartitioning.cpp'
--- a/storage/ndb/test/ndbapi/testPartitioning.cpp	2008-07-01 12:35:34 +0000
+++ b/storage/ndb/test/ndbapi/testPartitioning.cpp	2008-07-22 13:27:57 +0000
@@ -19,8 +19,6 @@
 #include <UtilTransactions.hpp>
 #include <NdbRestarter.hpp>
 
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
 static Uint32 max_dks = 0;
 
 static

=== modified file 'storage/ndb/test/ndbapi/test_event.cpp'
--- a/storage/ndb/test/ndbapi/test_event.cpp	2008-06-18 21:25:50 +0000
+++ b/storage/ndb/test/ndbapi/test_event.cpp	2008-07-22 13:27:57 +0000
@@ -23,8 +23,6 @@
 #include <NdbRestarts.hpp>
 #include <signaldata/DumpStateOrd.hpp>
 
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
 static int createEvent(Ndb *pNdb, 
                        const NdbDictionary::Table &tab,
                        NDBT_Context* ctx)

=== modified file 'storage/ndb/test/src/NDBT_Tables.cpp'
--- a/storage/ndb/test/src/NDBT_Tables.cpp	2008-07-01 12:35:34 +0000
+++ b/storage/ndb/test/src/NDBT_Tables.cpp	2008-07-22 13:27:57 +0000
@@ -1248,6 +1248,7 @@ loop:   
     if(r == -1){
       if(pNdb->getDictionary()->getNdbError().code == 755)
       {
+	ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;
 	if (create_default_tablespace(pNdb) == 0)
 	{
 	  goto loop;

=== modified file 'storage/ndb/test/src/NDBT_Test.cpp'
--- a/storage/ndb/test/src/NDBT_Test.cpp	2008-06-23 12:37:22 +0000
+++ b/storage/ndb/test/src/NDBT_Test.cpp	2008-07-22 13:25:43 +0000
@@ -25,7 +25,6 @@
 
 #include <time.h>
 
-// No verbose outxput
 
 NDBT_Context::NDBT_Context(Ndb_cluster_connection& con)
   : m_cluster_connection(con)
@@ -258,14 +257,58 @@ void NDBT_Context::setNumLoops(int _loop
   loops = _loops;
 }
 
-NDBT_Step::NDBT_Step(NDBT_TestCase* ptest, const char* pname, 
-		     NDBT_TESTFUNC* pfunc): name(pname){
-  assert(pfunc != NULL);
-  func = pfunc;
-  testcase = ptest;
-  step_no = -1;
+NDBT_Step::NDBT_Step(NDBT_TestCase* ptest, const char* pname,
+                     NDBT_TESTFUNC* pfunc) :
+  m_ctx(NULL), name(pname), func(pfunc),
+  testcase(ptest), step_no(-1), m_ndb(NULL)
+{
 }
 
+
+int
+NDBT_Step::setUp(Ndb_cluster_connection& con){
+
+  switch(testcase->getDriverType())
+  {
+  case DummyDriver:
+    break;
+
+  case NdbApiDriver:
+  {
+    m_ndb = new Ndb(&con, "TEST_DB" );
+    m_ndb->init(1024);
+
+    int result = m_ndb->waitUntilReady(300); // 5 minutes
+    if (result != 0){
+      g_err << "Ndb was not ready" << endl;
+      return NDBT_FAILED;
+    }
+    break;
+  }
+
+  default:
+    abort();
+    break;
+
+  }
+
+  return NDBT_OK;
+}
+
+
+void
+NDBT_Step::tearDown(){
+  delete m_ndb;
+  m_ndb = NULL;
+}
+
+
+Ndb* NDBT_Step::getNdb() const {
+  assert(m_ndb != NULL);
+  return m_ndb;
+}
+
+
 int NDBT_Step::execute(NDBT_Context* ctx) {
   assert(ctx != NULL);
 
@@ -305,58 +348,26 @@ NDBT_Context* NDBT_Step::getContext(){
   return m_ctx;
 }
 
-NDBT_NdbApiStep::NDBT_NdbApiStep(NDBT_TestCase* ptest, 
-			   const char* pname, 
-			   NDBT_TESTFUNC* pfunc)
-  : NDBT_Step(ptest, pname, pfunc),
-    ndb(NULL) {
-}
-
-
-int
-NDBT_NdbApiStep::setUp(Ndb_cluster_connection& con){
-  ndb = new Ndb(&con, "TEST_DB" );
-  ndb->init(1024);
-  
-  int result = ndb->waitUntilReady(300); // 5 minutes
-  if (result != 0){
-    g_err << name << ": Ndb was not ready" << endl;
-    return NDBT_FAILED;
-  }
-  return NDBT_OK;
-}
-
-void 
-NDBT_NdbApiStep::tearDown(){
-  delete ndb;
-  ndb = NULL;
-}
-
-Ndb* NDBT_NdbApiStep::getNdb(){ 
-  assert(ndb != NULL);
-  return ndb;
-}
-
 
 NDBT_ParallelStep::NDBT_ParallelStep(NDBT_TestCase* ptest, 
 				     const char* pname, 
 				     NDBT_TESTFUNC* pfunc)
-  : NDBT_NdbApiStep(ptest, pname, pfunc) {
+  : NDBT_Step(ptest, pname, pfunc) {
 }
 NDBT_Verifier::NDBT_Verifier(NDBT_TestCase* ptest, 
 			     const char* pname, 
 			     NDBT_TESTFUNC* pfunc)
-  : NDBT_NdbApiStep(ptest, pname, pfunc) {
+  : NDBT_Step(ptest, pname, pfunc) {
 }
 NDBT_Initializer::NDBT_Initializer(NDBT_TestCase* ptest, 
 				   const char* pname, 
 				   NDBT_TESTFUNC* pfunc)
-  : NDBT_NdbApiStep(ptest, pname, pfunc) {
+  : NDBT_Step(ptest, pname, pfunc) {
 }
 NDBT_Finalizer::NDBT_Finalizer(NDBT_TestCase* ptest, 
 			       const char* pname, 
 			       NDBT_TESTFUNC* pfunc)
-  : NDBT_NdbApiStep(ptest, pname, pfunc) {
+  : NDBT_Step(ptest, pname, pfunc) {
 }
 
 NDBT_TestCase::NDBT_TestCase(NDBT_TestSuite* psuite, 
@@ -386,6 +397,8 @@ NDBT_TestCaseImpl1::NDBT_TestCaseImpl1(N
   numStepsCompleted = 0;
   waitThreadsMutexPtr = NdbMutex_Create();
   waitThreadsCondPtr = NdbCondition_Create();
+
+  m_driverType= psuite->getDriverType();
 }
 
 NDBT_TestCaseImpl1::~NDBT_TestCaseImpl1(){
@@ -429,9 +442,13 @@ int NDBT_TestCaseImpl1::addVerifier(NDBT
   return 0;
 }
 
-int NDBT_TestCaseImpl1::addInitializer(NDBT_Initializer* pInitializer){
+int NDBT_TestCaseImpl1::addInitializer(NDBT_Initializer* pInitializer,
+                                       bool first){
   assert(pInitializer != NULL);
-  initializers.push_back(pInitializer);
+  if (first)
+    initializers.push(pInitializer, 0);
+  else
+    initializers.push_back(pInitializer);
   return 0;
 }
 
@@ -722,9 +739,9 @@ int NDBT_TestCaseImpl1::runFinal(NDBT_Co
 }
 
 
-void NDBT_TestCaseImpl1::saveTestResult(const NdbDictionary::Table* ptab, 
+void NDBT_TestCaseImpl1::saveTestResult(const char* test_name,
 					int result){
-  testResults.push_back(new NDBT_TestCaseResult(ptab->getName(), 
+  testResults.push_back(new NDBT_TestCaseResult(test_name,
 						result,
 						timer.elapsedTime()));
 }
@@ -754,18 +771,21 @@ void NDBT_TestCaseImpl1::printTestResult
 
 
 
-NDBT_TestSuite::NDBT_TestSuite(const char* pname):name(pname){
+NDBT_TestSuite::NDBT_TestSuite(const char* pname) :
+  name(pname),
+  m_createTable(true),
+  m_createAll(false),
+  m_logging(true),
+  m_driverType(NdbApiDriver)
+{
    numTestsOk = 0;
    numTestsFail = 0;
    numTestsExecuted = 0;
    records = 0;
    loops = 0;
-   createTable = true;
    diskbased = false;
    tsname = NULL;
-   createAllTables = false;
    temporaryTables = false;
-   nologging = false;
 }
 
 
@@ -777,14 +797,14 @@ NDBT_TestSuite::~NDBT_TestSuite(){
 }
 
 void NDBT_TestSuite::setCreateTable(bool _flag){
-  createTable = _flag;
+  m_createTable = _flag;
 }
 
 void NDBT_TestSuite::setRunAllTables(bool _flag){
   runonce = _flag;
 }
 void NDBT_TestSuite::setCreateAllTables(bool _flag){
-  createAllTables = _flag;
+  m_createAll = _flag;
 }
 
 void NDBT_TestSuite::setTemporaryTables(bool val){
@@ -795,6 +815,14 @@ bool NDBT_TestSuite::getTemporaryTables(
   return temporaryTables;
 }
 
+void NDBT_TestSuite::setLogging(bool val){
+  m_logging = val;
+}
+
+bool NDBT_TestSuite::getLogging() const {
+  return m_logging;
+}
+
 bool NDBT_TestSuite::timerIsOn(){
   return (timer != 0);
 }
@@ -819,91 +847,41 @@ int NDBT_TestSuite::executeAll(Ndb_clust
 
   if(tests.size() == 0)
     return NDBT_FAILED;
-  Ndb ndb(&con, "TEST_DB");
-  ndb.init(1024);
-
-  int result = ndb.waitUntilReady(500); // 5 minutes
-  if (result != 0){
-    g_err << name <<": Ndb was not ready" << endl;
-    return NDBT_FAILED;
-  }
 
   ndbout << name << " started [" << getDate() << "]" << endl;
 
-
   if(!runonce)
   {
     testSuiteTimer.doStart();
     for (int t=0; t < NDBT_Tables::getNumTables(); t++){
       const NdbDictionary::Table* ptab = NDBT_Tables::getTable(t);
       ndbout << "|- " << ptab->getName() << endl;
-      execute(con, &ndb, ptab, _testname);
+      execute(con, ptab, _testname);
     }
     testSuiteTimer.doStop();
   }
   else
   {
-    NdbDictionary::Dictionary* pDict= ndb.getDictionary();
     for (unsigned i = 0; i < tests.size(); i++){
       if (_testname != NULL && strcasecmp(tests[i]->getName(), _testname) != 0)
 	continue;
-      
-      
+
       tests[i]->initBeforeTest();
       ctx = new NDBT_Context(con);
 
-      Uint32 t;
-      for (t=0; t < (Uint32)NDBT_Tables::getNumTables(); t++)
-      {
-	const NdbDictionary::Table* pTab = NDBT_Tables::getTable(t);
-	const NdbDictionary::Table* pTab2 = pDict->getTable(pTab->getName());
-	
-	if(pTab2 != 0 && pDict->dropTable(pTab->getName()) != 0)
-	{
-	  numTestsFail++;
-	  numTestsExecuted++;
-	  g_err << "ERROR0: Failed to drop table " << pTab->getName() << endl;
-	  tests[i]->saveTestResult(pTab, FAILED_TO_CREATE);
-	  continue;
-	}
-      
-	if (NDBT_Tables::createTable(&ndb, pTab->getName(), 
-                                     nologging, false,
-				     g_create_hook, this) != 0) {
-	  numTestsFail++;
-	  numTestsExecuted++;
-	  g_err << "ERROR1: Failed to create table " << pTab->getName()
-		<< pDict->getNdbError() << endl;
-	  tests[i]->saveTestResult(pTab, FAILED_TO_CREATE);
-	  continue;
-	}
-	pTab2 = pDict->getTable(pTab->getName());
-
-	ctx->addTab(pTab2);
-      }
-	
       ctx->setNumRecords(records);
       ctx->setNumLoops(loops);
       ctx->setSuite(this);
-      
-      const NdbDictionary::Table** tables= ctx->getTables();
 
-      result = tests[i]->execute(ctx);
-      tests[i]->saveTestResult(tables[0], result);
+      int result = tests[i]->execute(ctx);
+
+      tests[i]->saveTestResult("", result);
       if (result != NDBT_OK)
 	numTestsFail++;
       else
 	numTestsOk++;
       numTestsExecuted++;
-      
-      if(result == NDBT_OK)
-      {
-	for(t = 0; tables[t] != 0; t++)
-	{ 
-	  pDict->dropTable(tables[t]->getName());
-	}
-      }
-      
+
       delete ctx;
     }
   }
@@ -913,17 +891,9 @@ int NDBT_TestSuite::executeAll(Ndb_clust
 int 
 NDBT_TestSuite::executeOne(Ndb_cluster_connection& con,
 			   const char* _tabname, const char* _testname){
-  
-  if(tests.size() == 0)
-    return NDBT_FAILED;
-  Ndb ndb(&con, "TEST_DB");
-  ndb.init(1024);
 
-  int result = ndb.waitUntilReady(300); // 5 minutes
-  if (result != 0){
-    g_err << name <<": Ndb was not ready" << endl;
+  if(tests.size() == 0)
     return NDBT_FAILED;
-  }
 
   ndbout << name << " started [" << getDate() << "]" << endl;
 
@@ -933,7 +903,7 @@ NDBT_TestSuite::executeOne(Ndb_cluster_c
 
   ndbout << "|- " << ptab->getName() << endl;
 
-  execute(con, &ndb, ptab, _testname);
+  execute(con, ptab, _testname);
 
   if (numTestsFail > 0){
     return NDBT_FAILED;
@@ -1026,7 +996,7 @@ NDBT_TestSuite::createHook(Ndb* ndb, Ndb
 }
 
 void NDBT_TestSuite::execute(Ndb_cluster_connection& con,
-			     Ndb* ndb, const NdbDictionary::Table* pTab, 
+			     const NdbDictionary::Table* pTab, 
 			     const char* _testname){
   int result; 
 
@@ -1047,50 +1017,20 @@ void NDBT_TestSuite::execute(Ndb_cluster
 
     tests[t]->initBeforeTest();
 
-    NdbDictionary::Dictionary* pDict = ndb->getDictionary();
-    const NdbDictionary::Table* pTab2 = pDict->getTable(pTab->getName());
-    if (createTable == true){
-
-      if(pTab2 != 0 && pDict->dropTable(pTab->getName()) != 0){
-	numTestsFail++;
-	numTestsExecuted++;
-	g_err << "ERROR0: Failed to drop table " << pTab->getName() << endl;
-	tests[t]->saveTestResult(pTab, FAILED_TO_CREATE);
-	continue;
-      }
-      
-      if (NDBT_Tables::createTable(ndb, pTab->getName(), nologging, false,
-                                   g_create_hook, this) != 0) {
-	numTestsFail++;
-	numTestsExecuted++;
-	g_err << "ERROR1: Failed to create table " << pTab->getName()
-              << pDict->getNdbError() << endl;
-	tests[t]->saveTestResult(pTab, FAILED_TO_CREATE);
-	continue;
-      }
-      pTab2 = pDict->getTable(pTab->getName());
-    } else if(!pTab2) {
-      pTab2 = pTab;
-    } 
-    
     ctx = new NDBT_Context(con);
-    ctx->setTab(pTab2);
     ctx->setNumRecords(records);
     ctx->setNumLoops(loops);
     ctx->setSuite(this);
-    
+    ctx->setTab(pTab);
+
     result = tests[t]->execute(ctx);
-    tests[t]->saveTestResult(pTab, result);
+    tests[t]->saveTestResult(pTab->getName(), result);
     if (result != NDBT_OK)
       numTestsFail++;
     else
       numTestsOk++;
     numTestsExecuted++;
 
-    if (result == NDBT_OK && createTable == true && createAllTables == false){
-      pDict->dropTable(pTab->getName());
-    }
-    
     tests[t]->m_has_run = true;
 
     delete ctx;
@@ -1099,6 +1039,133 @@ void NDBT_TestSuite::execute(Ndb_cluster
 
 
 
+int
+NDBT_TestSuite::createTables(Ndb_cluster_connection& con) const
+{
+  Ndb ndb(&con, "TEST_DB");
+  ndb.init(1);
+
+  NdbDictionary::Dictionary* pDict = ndb.getDictionary();
+  for(unsigned i = 0; i<m_tables_in_test.size(); i++)
+  {
+    const char *tab_name=  m_tables_in_test[i].c_str();
+    if (pDict->dropTable(tab_name) != 0)
+    {
+      g_err << "runCreateTables: Failed to drop table " << tab_name
+            << pDict->getNdbError() << endl;
+      return NDBT_FAILED;
+    }
+    if(NDBT_Tables::createTable(&ndb, tab_name, getLogging()) != 0)
+    {
+      g_err << "runCreateTables: Failed to create table " << tab_name
+            << pDict->getNdbError() << endl;
+      return NDBT_FAILED;
+    }
+
+    if (i == 0){
+      // Update ctx with a pointer to the first created table
+      const NdbDictionary::Table* pTab2 = pDict->getTable(tab_name);
+      ctx->setTab(pTab2);
+    }
+    g_info << "created " << tab_name << endl;
+  }
+
+  return NDBT_OK;
+}
+
+
+static int
+runCreateTables(NDBT_Context* ctx, NDBT_Step* step)
+{
+  NDBT_TestSuite* suite= ctx->getSuite();
+  return suite->createTables(ctx->m_cluster_connection);
+}
+
+
+static int
+runCreateTable(NDBT_Context* ctx, NDBT_Step* step)
+{
+  Ndb ndb(&ctx->m_cluster_connection, "TEST_DB");
+  ndb.init(1);
+
+  NdbDictionary::Dictionary* pDict = ndb.getDictionary();
+  const NdbDictionary::Table* pTab = ctx->getTab();
+  const char *tab_name=  pTab->getName();
+  if (pDict->dropTable(tab_name) > 0)
+  {
+    g_err << "runCreateTable: Failed to drop table " << tab_name
+          << pDict->getNdbError() << endl;
+    return NDBT_FAILED;
+  }
+
+  if(NDBT_Tables::createTable(&ndb, tab_name,
+                              ctx->getSuite()->getLogging()) != 0)
+  {
+    g_err << "runCreateTable: Failed to create table " << tab_name
+          << pDict->getNdbError() << endl;
+    return NDBT_FAILED;
+  }
+
+  // Update ctx with a pointer to the created table
+  const NdbDictionary::Table* pTab2 = pDict->getTable(tab_name);
+  ctx->setTab(pTab2);
+
+  return NDBT_OK;
+}
+
+
+int
+NDBT_TestSuite::dropTables(Ndb_cluster_connection& con) const
+{
+  Ndb ndb(&con, "TEST_DB");
+  ndb.init(1);
+
+  int res= NDBT_OK;
+  NdbDictionary::Dictionary* pDict = ndb.getDictionary();
+  for(unsigned i = 0; i<m_tables_in_test.size(); i++)
+  {
+    const char *tab_name=  m_tables_in_test[i].c_str();
+    if (pDict->dropTable(tab_name) != 0)
+    {
+      g_err << "runDropTables: Failed to drop table " << tab_name
+            << pDict->getNdbError() << endl;
+      res= NDBT_FAILED;
+      // Continue, try to drop all tables...
+    }
+
+    g_info << "dropped " << tab_name << endl;
+  }
+  return NDBT_OK;
+}
+
+
+static int
+runDropTables(NDBT_Context* ctx, NDBT_Step* step)
+{
+  NDBT_TestSuite* suite= ctx->getSuite();
+  return suite->dropTables(ctx->m_cluster_connection);
+}
+
+
+static int
+runDropTable(NDBT_Context* ctx, NDBT_Step* step)
+{
+  Ndb ndb(&ctx->m_cluster_connection, "TEST_DB");
+  ndb.init(1);
+
+  NdbDictionary::Dictionary* pDict = ndb.getDictionary();
+  const NdbDictionary::Table* pTab = ctx->getTab();
+  const char *tab_name=  pTab->getName();
+
+  if (pDict->dropTable(tab_name) != 0)
+  {
+    g_err << "runDropTables: Failed to drop table " << tab_name
+          << pDict->getNdbError() << endl;
+    return NDBT_FAILED;
+  }
+  return NDBT_OK;
+}
+
 
 int 
 NDBT_TestSuite::report(const char* _tcname){
@@ -1269,21 +1336,6 @@ int NDBT_TestSuite::execute(int argc, co
     return NDBT_ProgramExit(NDBT_WRONGARGS);
   }
 
-  if (opt_print == true){
-    printExecutionTree();
-    return 0;
-  }
-
-  if (opt_print_html == true){
-    printExecutionTreeHTML();
-    return 0;
-  }
-
-  if (opt_print_cases == true){
-    printCases();
-    return 0;
-  }
-
   if (opt_verbose)
     setOutputLevel(2); // Show g_info
   else 
@@ -1292,15 +1344,10 @@ int NDBT_TestSuite::execute(int argc, co
   records = opt_records;
   loops = opt_loops;
   timer = opt_timer;
-  nologging = opt_nologging;
+  if (opt_nologging)
+    setLogging(false);
   temporaryTables = opt_temporary;
 
-  Ndb_cluster_connection con;
-  if(con.connect(12, 5, 1))
-  {
-    return NDBT_ProgramExit(NDBT_FAILED);
-  }
-
   if (opt_seed == 0)
   {
     opt_seed = NdbTick_CurrentMillisecond();
@@ -1310,46 +1357,58 @@ int NDBT_TestSuite::execute(int argc, co
   srandom(opt_seed);
 
   global_flag_skip_invalidate_cache = 1;
-  
-  {
-    Ndb ndb(&con, "TEST_DB");
-    ndb.init(1024);
-    if (ndb.waitUntilReady(500)){
-      g_err << "Ndb was not ready" << endl;
-      return NDBT_ProgramExit(NDBT_FAILED);
-    }
-    NdbDictionary::Dictionary* pDict = ndb.getDictionary();
 
-    int num_tables= argc;
+  int num_tables= argc;
+  if (argc == 0)
+    num_tables = NDBT_Tables::getNumTables();
+
+  for(int i = 0; i<num_tables; i++)
+  {
     if (argc == 0)
-      num_tables = NDBT_Tables::getNumTables();
+      m_tables_in_test.push_back(NDBT_Tables::getTable(i)->getName());
+    else
+      m_tables_in_test.push_back(_argv[i]);
+  }
 
-    for(int i = 0; i<num_tables; i++)
+  if (m_createTable)
+  {
+    for (unsigned t = 0; t < tests.size(); t++)
     {
-      if (argc == 0)
-	m_tables_in_test.push_back(NDBT_Tables::getTable(i)->getName());
-      else
-	m_tables_in_test.push_back(_argv[i]);
-      if (createAllTables == true)
-      {
-	const char *tab_name=  m_tables_in_test[i].c_str();
-	const NdbDictionary::Table* pTab = pDict->getTable(tab_name);
-	if (pTab && pDict->dropTable(tab_name) != 0)
-	{
-	  g_err << "ERROR0: Failed to drop table " << tab_name
-		<< pDict->getNdbError() << endl;
-	  return NDBT_ProgramExit(NDBT_FAILED);
-	}
-	if(NDBT_Tables::createTable(&ndb, tab_name, nologging) != 0)
-	{
-	  g_err << "ERROR1: Failed to create table " << tab_name
-		<< pDict->getNdbError() << endl;
-	  return NDBT_ProgramExit(NDBT_FAILED);
-	}
-      }
+      NDBT_TestCaseImpl1* pt= (NDBT_TestCaseImpl1*)tests[t];
+      NDBT_Initializer* pti =
+        new NDBT_Initializer(pt,
+                             m_createAll ? "runCreateTables" : "runCreateTable",
+                             m_createAll ? runCreateTables : runCreateTable);
+      pt->addInitializer(pti, true);
+      NDBT_Finalizer* ptf =
+        new NDBT_Finalizer(pt,
+                           m_createAll ? "runDropTables" : "runDropTable",
+                           m_createAll ? runDropTables : runDropTable);
+      pt->addFinalizer(ptf);
     }
   }
 
+  if (opt_print == true){
+    printExecutionTree();
+    return 0;
+  }
+
+  if (opt_print_html == true){
+    printExecutionTreeHTML();
+    return 0;
+  }
+
+  if (opt_print_cases == true){
+    printCases();
+    return 0;
+  }
+
+  Ndb_cluster_connection con;
+  if(con.connect(12, 5, 1))
+  {
+    return NDBT_ProgramExit(NDBT_FAILED);
+  }
+
   if(argc == 0){
     // No table specified
     res = executeAll(con, opt_testname);
@@ -1362,24 +1421,8 @@ int NDBT_TestSuite::execute(int argc, co
     res = report(opt_testname);
   }
 
-  if (res == NDBT_OK && createAllTables == true)
-  {
-    Ndb ndb(&con, "TEST_DB");
-    ndb.init(1024);
-    if (ndb.waitUntilReady(500)){
-      g_err << "Ndb was not ready" << endl;
-      return NDBT_ProgramExit(NDBT_FAILED);
-    }
-    NdbDictionary::Dictionary* pDict = ndb.getDictionary();
-    for(unsigned i = 0; i<m_tables_in_test.size(); i++)
-    {
-      pDict->dropTable(m_tables_in_test[i].c_str());
-    }
-  }
-
   return NDBT_ProgramExit(res);
 }
- 
 
 
 void NDBT_TestSuite::printExecutionTree(){

Thread
bzr commit into mysql-5.1-telco-6.4 branch (msvensson:2676) Magnus Svensson22 Jul