// ConnectionResolver_t.cxx #include "dataset_catalog/ConnectionResolver.h" #include "dataset_util/Text.h" #include "dataset_util/pthread_sleep.h" #include #include using std::cout; using std::endl; using std::string; using dset::ConnectionResolver; namespace { void msg(const char* msg) { cout << "----- "; cout << msg; cout << " -----" << endl; } } // end of unnamed namespace int ConnectionResolver_t() { msg("Begin testing ConnectionResolver"); msg("Invalid catalog"); system("rm -f nosuchfile"); ConnectionResolver::set_configuration_file("nosuchfile"); ConnectionResolver badres; assert( ! badres.is_valid() ); assert( badres.resolve("DatasetRepository", "MYSQL") == "" ); msg("Write configuration file"); Text txt; txt.append("DatasetRepository"); txt.append("SQLRESULT"); txt.append("SQLRESULT@WS:myserver"); txt.append("AMI:ADA:dataset_repository:catalogs:atlas:"); txt.append("MYSQL:dbds:db1.usatlas.bnl.gov:selection:dbds:badpasswd"); txt.append(""); txt.append("TaskRepository"); txt.append("SQLRESULT"); txt.append("AMI:ADA:task_repository:catalogs:atlas:"); txt.append("MYSQL:dbds:db1.usatlas.bnl.gov:selection:dbds:"); txt.append(""); txt.append("JobRepository"); txt.append("SQLRESULT"); txt.append("AMI:ADA:job_repository:catalogs:atlas:"); txt.append("MYSQL:dbds:db1.usatlas.bnl.gov:selection:dbds:"); txt.append(""); txt.append("DatasetSelectionCatalog"); txt.append("SQLRESULT"); txt.append("MYSQL:dbds:db1.usatlas.bnl.gov:selection:dbds:"); txt.append(""); txt.append("TaskSelectionCatalog"); txt.append("SQLRESULT"); txt.append("MYSQL:dbds:db1.usatlas.bnl.gov:selection:dbds:"); txt.append(""); txt.append("JobSelectionCatalog"); txt.append("SQLRESULT"); txt.append("MYSQL:dbds:db1.usatlas.bnl.gov:selection:dbds:"); txt.append(""); txt.append("ApplicationSelectionCatalog"); txt.append("SQLRESULT"); txt.append("MYSQL:dbds:db1.usatlas.bnl.gov:selection:dbds:"); system("rm -rf table_params"); txt.write("table_params"); msg("Set configuration file"); string cname = "table_params"; //cname = "http://www.usatlas.bnl.gov/~dial/atlascfg/atlas_ws_catalog.cfg"; ConnectionResolver::set_configuration_file(cname); cout << "Name: " << ConnectionResolver::get_configuration_file() << endl; assert( ConnectionResolver::get_configuration_file() == cname ); msg("Resolve"); ConnectionResolver rs; assert( rs.is_valid() ); string str = rs.resolve("DatasetRepository", "MYSQL"); cout << str << endl; if ( str.empty() ) { cout << "No match found" << endl; assert(false); } msg("Resolve"); string in = "SQLRESULT@WS"; cout << in << endl; string out = rs.resolve("DatasetRepository", in); cout << out << endl; assert( out == "SQLRESULT@WS:myserver" ); msg("All tests passed."); return 0; } #ifdef CTEST_MAIN int main() { return ConnectionResolver_t(); } #endif