// dataset_merge_events_t.cxx #include #include #include "dataset_util/getcwd.h" #include "dataset_util/FileName.h" #include "dataset_util/FileStatus.h" #include "dataset_util/mkdir.h" #include "dataset_util/DtdRegistry.h" #include "dataset_id/SimpleUniqueIdGenerator.h" #include "dataset_credential/CredentialSelectionCatalog.h" #include "dataset_credential/GssCredentialManager.h" #include "dataset_base/DatasetCreator.h" #include "dataset_base/DatasetRepository.h" #include "dataset_base/EventMergeDataset.h" #include "dataset_base/Dataset_t.h" #include "dataset_xml/XmlParser.h" using std::string; using std::cout; using std::endl; using dset::CredentialSelectionCatalog; using dset::GssCredentialManager; using dset::ContentBlock; using dset::Content; using dset::Dataset; using dset::DatasetCreator; using dset::DatasetRepository; using dset::EventMergeDataset; namespace { void msg(string txt) { cout << "*** "; cout << txt; cout << endl; } int ssystem(string com) { return system(com.c_str()); } } int dataset_merge_events_t() { msg("Testing datset_merge_events"); system("rm -rf resolver.dat dr.dat UniqueId dataste.dtd"); system("rm -f id2.dat ids.dat mdst1.xml mdst2.xml mdst3.xml"); msg("Write DTD"); DtdRegistry::instance("dataset").write(); SimpleUniqueIdGenerator::create_collection("Dataset", 123, 1001); SimpleUniqueIdGenerator::set_as_default(); msg("Create default repository"); DatasetRepository::create_default_instance(); DatasetRepository& rep = DatasetRepository::default_instance(); assert( rep.is_valid() ); msg("Fetch default instance of CSC."); assert( CredentialSelectionCatalog::create_default_instance() == 0 ); CredentialSelectionCatalog& sc = CredentialSelectionCatalog::default_instance(); cout << sc << endl; assert( sc.is_valid() ); string owner = "me"; assert( GssCredentialManager::set_default() == 0 ); assert( GssCredentialManager::set_owner("me") == 0 ); msg("Display help message"); int stat = system("dataset_merge_events -h"); assert( stat == 0 ); msg("Create content description"); ContentId cid1(101); assert( cid1.is_valid() ); ContentId cid2(102); assert( cid2.is_valid() ); ContentIdList cids; cids.insert(cid1); cids.insert(cid2); assert( cids.size() == 2 ); msg("Create dataset 1"); DatasetId did1; EventIdList eids1; eids1.insert(EventIdRange(101, 1, 10)); Content con1; ContentBlock cb1("EventDataset", "Test", cids, eids1); con1.push_back(cb1); TestDataset tdst1(con1); tdst1.lock(); assert( tdst1.is_valid() ); did1 = tdst1.id(); cout << tdst1 << endl; assert( rep.insert(&tdst1).is_valid() ); assert( rep.extract(tdst1.id(), true) != 0 ); msg("Create dataset 2"); DatasetId did2; EventIdList eids2; eids2.insert(EventIdRange(101, 11, 25)); Content con2; ContentBlock cb2("EventDataset", "Test", cids, eids2); con2.push_back(cb2); TestDataset tdst2(con2); tdst2.lock(); cout << tdst2 << endl; did2 = tdst2.id(); assert( rep.insert(&tdst2).is_valid() ); assert( rep.extract(tdst2.id(), true) != 0 ); msg("Create merged dataset with explicit ID"); DatasetId did3(201,3); string com0 = "export DIAL_CATALOG_CONF=resolver.dat; "; string com = com0 + "dataset_merge_events -i 201-3 -w -f mdst1.xml "; com += did1.to_string() + " " + did2.to_string(); assert( rep.extract(did3, true) == 0 ); cout << com << endl; stat = system(com.c_str()); assert( stat == 0 ); assert( rep.extract(did3, true) != 0 ); msg("Create merged dataset from list"); Text tids("ids.dat"); tids.append(did1.to_string()); tids.append(did2.to_string()); tids.write(); DatasetId did4(201,4); com = com0 + "dataset_merge_events -i 201-4 -w -f mdst3.xml -l ids.dat"; assert( rep.extract(did4, true) == 0 ); cout << com << endl; stat = system(com.c_str()); assert( stat == 0 ); assert( rep.extract(did4, true) != 0 ); msg("Create merged dataset with generated ID"); Dataset::reset_id_generator(); com = com0; com += "dataset_merge_events"; com += " -u SimpleUniqueIdGenerator:UniqueId::"; com += " -f mdst2.xml -w "; com += did1.to_string() + " " + did2.to_string(); com += " > id2.dat"; cout << com << endl; stat = system(com.c_str()); assert( stat == 0 ); msg("...Fetch ID"); Text tid2("id2.dat"); unsigned int iline = 0; if ( tid2.line(0) == "***** Initializing POOL ******" ) { cout << "Warning: Found POOL initialization message" << endl; ++iline; } assert( tid2.size() == iline+1 ); string sid2 = tid2.line(iline); cout << sid2 << endl; assert( sid2.size() > 2 ); DatasetId did5(sid2); cout << did5 << endl; assert( did5.is_valid() ); msg("...extract dataset"); assert( rep.extract(did5, true) != 0 ); cout << *rep.extract(did5, true) << endl; msg("Read merged dataset"); XmlParser parser; const XmlElement* pxdst = parser.parse("mdst2.xml"); assert( pxdst != 0 ); const Dataset* pdst = DatasetCreator::create(*pxdst); assert( pdst != 0 ); assert( pdst->is() ); const EventMergeDataset& edst = pdst->cast(); cout << edst << endl; assert( rep.has(did1) ); assert( edst.constituents().size() == 2 ); assert( edst.constituents().front() != 0 ); assert( edst.constituents().front()->id() == did1 ); assert( edst.constituents().back() != 0 ); assert( edst.constituents().back()->id() == did2 ); return 0; } #ifdef CTEST_MAIN int main() { return dataset_merge_events_t(); } #endif