// MagdaFileCatalog_t.cxx #include "dataset_magda/MagdaFileCatalog.h" #include #include #include #include "dataset_util/getcwd.h" #include "dataset_util/FileStatus.h" #include "dataset_file/FileManagementSystem.h" using std::string; using std::cout; using std::endl; using dset::Url; using dset::FileCatalog; using dset::FileManagementSystem; using dset::MagdaFileCatalog; // Display messsage. void msg(string txt) { cout << "--- " << txt << " ---" << endl; } int MagdaFileCatalog_t() { msg("Begin testing MagdaFileCatalog"); system("rm -f testdial.file"); msg("Testing static_type"); assert( MagdaFileCatalog::static_type() == "MagdaFileCatalog" ); MagdaFileCatalog& mfc = MagdaFileCatalog::instance(); msg("Testing type"); assert( mfc.type() == "MagdaFileCatalog" ); msg("Testing name"); assert( mfc.name() == "atlas" ); msg("Generic locator"); assert( FileCatalog::locate(mfc.type(), mfc.name()) != 0 ); assert( FileCatalog::locate(mfc.type(), mfc.name()) == &mfc ); Url lurl("lfn:testdial.file"); Url oldpurl("file:/home/wdeng/test/testTrans/testdial.file"); msg("Check has"); assert( mfc.has(lurl) ); msg("Get replicas"); msg("Looking for testdial.file: "); system("pwd"); system("ls -ls"); FileCatalog::UrlList urls = mfc.replicas(lurl); assert( urls.size() ); msg("Build FMS"); string dir = getcwd(); string file = dir + "/testdial.file"; string copyurl = "copy:" + dir; Url furl("file:" + dir + "/testdial.file"); Environment env; env["DIAL_FMS_CATALOG"] = "MagdaFileCatalog"; env["DIAL_FMS_PROTOCOLS"] = "file"; env["DIAL_FMS_PROTOCOL_ORDER"] = copyurl; env["DIAL_FMS_SE"] = ""; env["DIAL_FMS_VERBOSE"] = "true"; FileManagementSystem fms(env); cout << fms << endl; assert( fms.is_valid() ); msg("Get file with FMS"); unlink(file.c_str()); assert( ! FileStatus(file).exists() ); Url url = fms.get(lurl); if ( fms.error() ) { cout << fms.error_message() << endl; assert(false); } cout << url << endl; assert( url == furl ); assert( FileStatus(file).exists() ); msg("End testing MagdaFileCatalog"); return 0; } #ifdef CTEST_MAIN int main() { return MagdaFileCatalog_t(); } #endif