Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DbmValidate Class Reference

#include <DbmValidate.h>

List of all members.

Public Member Functions

 DbmValidate (DbmModule *module)
virtual ~DbmValidate ()
Bool_t RunAllTests ()
Bool_t TestExportImport ()
Bool_t TestGlobaliseSeqNo ()

Private Member Functions

Bool_t PrepareDb ()

Private Attributes

DbmFileLocater fFileLocater
DbmModulefModule
DbiStatementfStatement0
DbiStatementfStatement1


Constructor & Destructor Documentation

DbmValidate::DbmValidate DbmModule module  ) 
 

Definition at line 45 of file DbmValidate.cxx.

References DbiCascader::CreateStatement(), DbiTableProxyRegistry::GetCascader(), DbiTableProxyRegistry::Instance(), LEA_CTOR, and MSG.

00045                                           :
00046 fModule(module),
00047 fStatement0(0),
00048 fStatement1(0)
00049 {
00050 //
00051 //
00052 //  Purpose:  Constructor
00053 //
00054 //  Arguments:
00055 //     module     in  Module to be tested..  
00056 //
00057 //  Return:    n/a
00058 //
00059 //  Contact:   N. West
00060 //
00061 //  Specification:-
00062 //  =============
00063 //
00064 //  o  Create validation object and run tests..
00065 
00066 
00067 //  Program Notes:-
00068 //  =============
00069 
00070 //  None.
00071 
00072   LEA_CTOR    //Leak Checker
00073 
00074   MSG("Dbi", Msg::kVerbose) << "Creating DbmValidate" << endl;
00075 
00076   fStatement0  =   DbiTableProxyRegistry::Instance()  
00077                     .GetCascader()
00078                        .CreateStatement(0);
00079   fStatement1  =   DbiTableProxyRegistry::Instance()  
00080                     .GetCascader()
00081                        .CreateStatement(1);
00082 
00083   if ( ! fStatement0 || ! fStatement1 ) {
00084     MSG("Dbi", Msg::kInfo) 
00085       << "Cannot get DbiStatement for cascade entries 0,1 "
00086       << "unable to validate Dbm." << endl;
00087   }
00088   else {
00089     if ( ! PrepareDb() ) {
00090       MSG("Dbi", Msg::kInfo) << "Cannot run validation!" << endl;
00091     }
00092     else {
00093       if ( RunAllTests() ) {
00094         MSG("Dbi", Msg::kInfo) << "All tests passed" << endl;
00095       }
00096       else {
00097         MSG("Dbi", Msg::kInfo) << "Validation failed!" << endl;
00098       }
00099     }
00100   }   
00101 
00102 }  

DbmValidate::~DbmValidate  )  [virtual]
 

Definition at line 107 of file DbmValidate.cxx.

References fStatement0, LEA_DTOR, and MSG.

00107                           {
00108 //
00109 //
00110 //  Purpose: Destructor
00111 //
00112 //  Arguments: 
00113 //    None.
00114 //
00115 //  Return:    n/a
00116 //
00117 //  Contact:   N. West
00118 //
00119 //  Specification:-
00120 //  =============
00121 //
00122 //  o  Destroy validation object.
00123 
00124 
00125 //  Program Notes:-
00126 //  =============
00127 
00128 //  None.
00129 
00130   LEA_DTOR    //Leak Checker
00131 
00132   MSG("Dbi", Msg::kVerbose) << "Destroying DbmValidate" << endl;
00133 
00134   delete fStatement0;
00135   fStatement0 = 0;
00136   delete fStatement1;
00137   fStatement0 = 0;
00138 
00139 }


Member Function Documentation

Bool_t DbmValidate::PrepareDb  )  [private]
 

Definition at line 144 of file DbmValidate.cxx.

References DbiStatement::ExecuteUpdate(), fFileLocater, DbmFileLocater::Find(), fStatement0, fStatement1, MSG, and DbiStatement::PrintExceptions().

00144                               {
00145 //
00146 //
00147 //  Purpose:  Prepare database for validation tests.
00148 //
00149 //  Arguments: None
00150 //
00151 //  Return:    
00152 //
00153 //  Contact:   N. West
00154 //
00155 //  Specification:-
00156 //  =============
00157 //
00158 //  o Prepare database for validation tests.
00159 
00160 
00161 //  Program Notes:-
00162 //  =============
00163 
00164 //  None.
00165 
00166   Bool_t ok = kTRUE;
00167 
00168   if ( ! fStatement0 || ! fStatement1 ) {
00169     MSG("Dbm",Msg::kInfo) 
00170        << "Cannot prepare  for tests (no database access)" << endl;
00171     return kFALSE;
00172   }
00173 
00174   string prepareDBFileName 
00175      = fFileLocater.Find("DatabaseMaintenance/test/PrepareDB.mysql");
00176   ifstream prepareDBFile(prepareDBFileName.c_str());
00177 
00178   if ( ! prepareDBFile.is_open() ) {
00179     MSG("Dbm",Msg::kInfo)
00180        << "Cannot prepare  for tests (no validation data file)" << endl;
00181     return kFALSE;
00182   }
00183 
00184   // Loop processing SQL commands.
00185 
00186   while ( ! prepareDBFile.eof() ) {
00187     string sql;
00188     string line;
00189     while ( ! prepareDBFile.eof() ) {
00190       getline(prepareDBFile,line);
00191       // Remove trailing spaces.
00192       int last = line.size()-1;
00193       while ( last >= 0 && line[last] == ' ') line.erase(last--);
00194       // Ignore blank and comment lines
00195       if ( last < 0 || line[0] == '#' ) continue;
00196       // Append and look for terminating ";".
00197       sql += line;
00198       if ( line[last] == ';' ) {
00199         MSG("Dbm",Msg::kDebug) << "SQL " << sql << endl;
00200         fStatement0->ExecuteUpdate(sql.c_str());
00201         if ( fStatement0->PrintExceptions() ) ok = kFALSE;
00202         fStatement1->ExecuteUpdate(sql.c_str());
00203         if ( fStatement1->PrintExceptions() ) ok = kFALSE;
00204         sql = "";
00205         break;
00206       }
00207     }
00208     if ( sql != "" 
00209        ) MSG("Dbm",Msg::kInfo)
00210                 << "File ends with incomplete SQL "<< sql << endl;
00211   }
00212   
00213   return ok;
00214   
00215 }

Bool_t DbmValidate::RunAllTests  ) 
 

Definition at line 219 of file DbmValidate.cxx.

References TestExportImport(), and TestGlobaliseSeqNo().

00219                                 {
00220 //
00221 //
00222 //  Purpose: Run suite of validation tests. 
00223 //
00224 //  Arguments: None.
00225 //
00226 //  Return:    
00227 //
00228 //  Contact:   N. West
00229 //
00230 //  Specification:-
00231 //  =============
00232 //
00233 //  o Run suite of validation tests. 
00234 
00235 //  Program Notes:-
00236 //  =============
00237 
00238 //  None.
00239 
00240   Bool_t ok = kTRUE;
00241 
00242   if ( ! TestGlobaliseSeqNo() ) ok = kFALSE;
00243   if ( ! TestExportImport()   ) ok = kFALSE;
00244 
00245   return ok;
00246 
00247 }

Bool_t DbmValidate::TestExportImport  ) 
 

Definition at line 250 of file DbmValidate.cxx.

References DbmModule::ClearCache(), fModule, DbmModule::fValRecSet, DbmModule::HandleCommand(), and MSG.

Referenced by RunAllTests().

00250                                      {
00251 //
00252 //
00253 //  Purpose: Test Export and Import.
00254 //
00255 //  Arguments: None.
00256 //
00257 //  Return:    
00258 //
00259 //  Contact:   N. West
00260 //
00261 //  Specification:-
00262 //  =============
00263 //
00264 //  o Export data from database 0  and import into database 1.
00265 
00266 //  Program Notes:-
00267 //  =============
00268 
00269 //  None.
00270 
00271   MSG("Dbm",Msg::kInfo) << "Testing Export/Import       ..." << endl;
00272 
00273   Bool_t ok = kTRUE;
00274 
00275 
00276   if ( ! ok ) {
00277     MSG("Dbm",Msg::kError) << "  Cannot prepare test" << endl;
00278     return kFALSE;
00279   }
00280 
00281 
00282   //  Export data
00283   JobCommand jcExport("/Export --Table DBMVALIDATEDATA1 --File DbmValidateData1.dat");
00284   fModule->HandleCommand(&jcExport);
00285 
00286   //  Force Dbm to load DbiValidityRecs from cascade number 1.
00287   fModule->ClearCache();
00288   fModule->fValRecSet = new DbiValRecSet("DBMVALIDATEDATA1",1);
00289 
00290   //  Import data
00291   JobCommand jcImport("/Import --DatabaseNumber 1 --File DbmValidateData1.dat");
00292   fModule->HandleCommand(&jcImport);
00293 
00294   return ok;
00295 
00296 }

Bool_t DbmValidate::TestGlobaliseSeqNo  ) 
 

Definition at line 298 of file DbmValidate.cxx.

References DbiStatement::ExecuteQuery(), fModule, fStatement0, DbmModule::HandleCommand(), jc, MSG, and DbiStatement::PrintExceptions().

Referenced by RunAllTests().

00298                                        {
00299 //
00300 //
00301 //  Purpose: Test Globalisation of SeqNos.
00302 //
00303 //  Arguments: None.
00304 //
00305 //  Return:    
00306 //
00307 //  Contact:   N. West
00308 //
00309 //  Specification:-
00310 //  =============
00311 //
00312 //  o Count no.of local SeqNos, convert and count again.
00313 
00314 //  Program Notes:-
00315 //  =============
00316 
00317 //  None.
00318 
00319   MSG("Dbm",Msg::kInfo) << "Testing SeqNo globalisation ..." << endl;
00320 
00321   string sqlLocalMain =
00322   "select SeqNo from DBMVALIDATEDATA1 where SeqNo < 100000000;";
00323   string sqlLocalVal =
00324   "select SeqNo from DBMVALIDATEDATA1VLD where SeqNo < 100000000;";
00325 
00326   TSQLStatement* stmt = 0;
00327 
00328   //  Count number before
00329   Int_t numBefore = 0;
00330   stmt = fStatement0->ExecuteQuery(sqlLocalMain.c_str());
00331   fStatement0->PrintExceptions();
00332   if ( stmt ) while ( stmt->NextResultRow() ) ++numBefore;
00333   delete stmt;
00334   stmt = fStatement0->ExecuteQuery(sqlLocalVal.c_str());
00335   fStatement0->PrintExceptions();
00336   if ( stmt ) while ( stmt->NextResultRow() ) ++numBefore;
00337   delete stmt;
00338 
00339   //  Globalise
00340   JobCommand jc("/GlobaliseSeqNo DBMVALIDATEDATA1");
00341   fModule->HandleCommand(&jc);
00342 
00343   //  Count number after
00344   Int_t numAfter = 0;
00345   stmt = fStatement0->ExecuteQuery(sqlLocalMain.c_str());
00346   fStatement0->PrintExceptions();
00347   if ( stmt ) while ( stmt->NextResultRow() ) ++numAfter;
00348   delete stmt;
00349   stmt = fStatement0->ExecuteQuery(sqlLocalVal.c_str());
00350   fStatement0->PrintExceptions();
00351   if ( stmt ) while ( stmt->NextResultRow() ) ++numAfter;
00352   delete stmt;
00353 
00354   Bool_t ok = numBefore == 9 &&  numAfter == 0;
00355   MSG("Dbm",Msg::kInfo) 
00356     << "    Before there should be 9 local Seqno, found " 
00357     << numBefore << endl  
00358     << "    After there should be 0 local Seqno, found " 
00359     << numAfter << endl
00360     << "Test has " << (ok ? "passed" : "failed!!") << endl;
00361 
00362   return ok;
00363 
00364 }


Member Data Documentation

DbmFileLocater DbmValidate::fFileLocater [private]
 

Definition at line 47 of file DbmValidate.h.

Referenced by PrepareDb().

DbmModule* DbmValidate::fModule [private]
 

Definition at line 48 of file DbmValidate.h.

Referenced by TestExportImport(), and TestGlobaliseSeqNo().

DbiStatement* DbmValidate::fStatement0 [private]
 

Definition at line 49 of file DbmValidate.h.

Referenced by PrepareDb(), TestGlobaliseSeqNo(), and ~DbmValidate().

DbiStatement* DbmValidate::fStatement1 [private]
 

Definition at line 50 of file DbmValidate.h.

Referenced by PrepareDb().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:09:05 2010 for loon by  doxygen 1.3.9.1