Back to index

nordugrid-arc-nox  1.1.0~rc6
JobDescriptionTest.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <string>
00003 #include <fstream>
00004 
00005 #include <cppunit/extensions/HelperMacros.h>
00006 
00007 #include <arc/Logger.h>
00008 #include <arc/StringConv.h>
00009 #include <arc/XMLNode.h>
00010 #include <arc/client/JobDescription.h>
00011 
00012 #define ARC_ASSERT(X) CPPUNIT_ASSERT_MESSAGE("ARCJSDL parsing issue", X);
00013 #define XRSL_ASSERT(X) CPPUNIT_ASSERT_MESSAGE("XRSL parsing issue", X);
00014 #define JDL_ASSERT(X) CPPUNIT_ASSERT_MESSAGE("JDL parsing issue", X);
00015 
00016 #define PARSE_ASSERT(X, JOB, ARC, XRSL, JDL) \
00017   ARC_ASSERT(ARC.X == JOB.X); \
00018   XRSL_ASSERT(XRSL.X == JOB.X); \
00019   JDL_ASSERT(JDL.X == JOB.X);
00020 
00021 #define ARC_ASSERT_EQUAL(X, Y) CPPUNIT_ASSERT_EQUAL_MESSAGE("ARCJSDL parsing issue", X, Y);
00022 #define XRSL_ASSERT_EQUAL(X, Y) CPPUNIT_ASSERT_EQUAL_MESSAGE("XRSL parsing issue", X, Y);
00023 #define JDL_ASSERT_EQUAL(X, Y) CPPUNIT_ASSERT_EQUAL_MESSAGE("JDL parsing issue", X, Y);
00024 
00025 #define PARSE_ASSERT_EQUAL(X, JOB, ARC, XRSL, JDL) \
00026   ARC_ASSERT_EQUAL(JOB.X, ARC.X); \
00027   XRSL_ASSERT_EQUAL(JOB.X, XRSL.X); \
00028   JDL_ASSERT_EQUAL(JOB.X, JDL.X);
00029 
00030 #define DATATYPE_ASSERT() \
00031 
00032 
00033 class JobDescriptionTest
00034   : public CppUnit::TestFixture {
00035 
00036   CPPUNIT_TEST_SUITE(JobDescriptionTest);
00037   CPPUNIT_TEST(TestExecutable);
00038   CPPUNIT_TEST(TestInputOutputError);
00039   CPPUNIT_TEST(TestDataStagingCreateDelete);
00040   CPPUNIT_TEST(TestDataStagingDownloadDelete);
00041   CPPUNIT_TEST(TestDataStagingUploadDelete);
00042   CPPUNIT_TEST(TestDataStagingCreateDownload);
00043   CPPUNIT_TEST(TestDataStagingDownloadDownload);
00044   CPPUNIT_TEST(TestDataStagingUploadDownload);
00045   CPPUNIT_TEST(TestDataStagingCreateUpload);
00046   CPPUNIT_TEST(TestDataStagingDownloadUpload);
00047   CPPUNIT_TEST(TestDataStagingUploadUpload);
00048   CPPUNIT_TEST(TestPOSIXCompliance);
00049   CPPUNIT_TEST(TestHPCCompliance);
00050   CPPUNIT_TEST_SUITE_END();
00051 
00052 public:
00053   JobDescriptionTest()
00054     : logger(Arc::Logger::getRootLogger(), "JobDescriptionTest"),
00055       logcerr(std::cout)
00056     {}
00057   void setUp();
00058   void tearDown();
00059   void TestExecutable();
00060   void TestInputOutputError();
00061   void TestDataStagingCreateDelete();
00062   void TestDataStagingDownloadDelete();
00063   void TestDataStagingUploadDelete();
00064   void TestDataStagingCreateDownload();
00065   void TestDataStagingDownloadDownload();
00066   void TestDataStagingUploadDownload();
00067   void TestDataStagingCreateUpload();
00068   void TestDataStagingDownloadUpload();
00069   void TestDataStagingUploadUpload();
00070   void TestPOSIXCompliance();
00071   void TestHPCCompliance();
00072 
00073 private:
00074   Arc::JobDescription job;
00075   Arc::JobDescription arcJob;
00076   Arc::JobDescription xrslJob;
00077   Arc::JobDescription jdlJob;
00078 
00079   Arc::LogStream logcerr;
00080   Arc::Logger logger;
00081 };
00082 
00083 void JobDescriptionTest::setUp() {
00084   job.Application.Executable.Name = "executable";
00085   job.Application.Executable.Argument.push_back("arg1");
00086   job.Application.Executable.Argument.push_back("arg2");
00087   job.Application.Executable.Argument.push_back("arg3");
00088 
00089   // Needed by the XRSLParser.
00090   std::ofstream f("executable", std::ifstream::trunc);
00091   f << "executable";
00092   f.close();
00093 
00094   Arc::Logger::getRootLogger().addDestination(logcerr);
00095   Arc::Logger::getRootLogger().setThreshold(Arc::WARNING);
00096 }
00097 
00098 void JobDescriptionTest::tearDown() {
00099 }
00100 
00101 void JobDescriptionTest::TestExecutable() {
00102   arcJob.Parse(job.UnParse("ARCJSDL"));
00103   xrslJob.Parse(job.UnParse("XRSL"));
00104   jdlJob.Parse(job.UnParse("JDL"));
00105 
00106   PARSE_ASSERT(Application.Executable.Name, job, arcJob, xrslJob, jdlJob);
00107   PARSE_ASSERT(Application.Executable.Argument, job, arcJob, xrslJob, jdlJob);
00108 }
00109 
00110 void JobDescriptionTest::TestInputOutputError() {
00111   job.Application.Input = "input-file";
00112   // Needed by the XRSLParser.
00113   std::ofstream f("input-file", std::ifstream::trunc);
00114   f << "input-file";
00115   f.close();
00116 
00117   job.Application.Output = "output-file";
00118   job.Application.Error = "error-file";
00119 
00120   arcJob.Parse(job.UnParse("ARCJSDL"));
00121   xrslJob.Parse(job.UnParse("XRSL"));
00122   jdlJob.Parse(job.UnParse("JDL"));
00123 
00124   PARSE_ASSERT(Application.Input, job, arcJob, xrslJob, jdlJob);
00125   PARSE_ASSERT(Application.Output, job, arcJob, xrslJob, jdlJob);
00126   PARSE_ASSERT(Application.Error, job, arcJob, xrslJob, jdlJob);
00127 }
00128 
00132 void JobDescriptionTest::TestDataStagingCreateDelete() {
00133       job.DataStaging.File.clear();
00134 
00135   Arc::FileType file;
00136   file.Name = "1-Create-Delete";
00137   file.KeepData = false;
00138   file.IsExecutable = false;
00139   file.DownloadToCache = false;
00140   job.DataStaging.File.push_back(file);
00141 
00142   arcJob.Parse(job.UnParse("ARCJSDL"));
00143   ARC_ASSERT(arcJob);
00144   ARC_ASSERT(job.DataStaging.File.size() == 1 && arcJob.DataStaging.File.size() == 1);
00145   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00146 
00147   ARC_ASSERT(job.DataStaging.File.front().IsExecutable == arcJob.DataStaging.File.front().IsExecutable);
00148   job.DataStaging.File.pop_back(); file.IsExecutable = true; job.DataStaging.File.push_back(file); arcJob.Parse(job.UnParse("ARCJSDL"));
00149   ARC_ASSERT(job.DataStaging.File.front().IsExecutable == arcJob.DataStaging.File.front().IsExecutable);
00150 }
00151 
00153 void JobDescriptionTest::TestDataStagingDownloadDelete() {
00154   job.DataStaging.File.clear();
00155 
00156   Arc::FileType file;
00157   file.Name = "2-Download-Delete";
00158   Arc::DataSourceType source;
00159   source.URI = "http://example.com/" + file.Name;
00160   CPPUNIT_ASSERT(source.URI);
00161   source.Threads = -1;
00162   file.Source.push_back(source);
00163   file.KeepData = false;
00164   file.IsExecutable = false;
00165   file.DownloadToCache = false;
00166   job.DataStaging.File.push_back(file);
00167 
00168   CPPUNIT_ASSERT(job.DataStaging.File.size() == 1);
00169   CPPUNIT_ASSERT(job.DataStaging.File.front().Source.size() == 1 && job.DataStaging.File.front().Source.front().URI);
00170 
00171   arcJob.Parse(job.UnParse("ARCJSDL"));
00172   ARC_ASSERT(arcJob);
00173   ARC_ASSERT(arcJob.DataStaging.File.size() == 1);
00174   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00175   ARC_ASSERT(arcJob.DataStaging.File.front().Source.size() == 1 && arcJob.DataStaging.File.front().Source.front().URI);
00176   ARC_ASSERT(job.DataStaging.File.front().Source.front().URI == arcJob.DataStaging.File.front().Source.front().URI);
00177 
00178   xrslJob.Parse(job.UnParse("XRSL"));
00179   XRSL_ASSERT(xrslJob);
00180   XRSL_ASSERT(!xrslJob.DataStaging.File.empty());
00181   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.front().Name);
00182   XRSL_ASSERT(xrslJob.DataStaging.File.front().Source.size() == 1 && xrslJob.DataStaging.File.front().Source.front().URI);
00183   XRSL_ASSERT(job.DataStaging.File.front().Source.front().URI == xrslJob.DataStaging.File.front().Source.front().URI);
00184 
00185   jdlJob.Parse(job.UnParse("JDL"));
00186   JDL_ASSERT(jdlJob);
00187   JDL_ASSERT(!jdlJob.DataStaging.File.empty());
00188   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.front().Name);
00189   JDL_ASSERT(jdlJob.DataStaging.File.front().Source.size() == 1 && jdlJob.DataStaging.File.front().Source.front().URI);
00190   JDL_ASSERT(job.DataStaging.File.front().Source.front().URI == jdlJob.DataStaging.File.front().Source.front().URI);
00191 }
00192 
00194 void JobDescriptionTest::TestDataStagingUploadDelete() {
00195   job.DataStaging.File.clear();
00196 
00197   Arc::FileType file;
00198   file.Name = "3-Upload-Delete";
00199   Arc::DataSourceType source;
00200   source.URI = file.Name;
00201   source.Threads = -1;
00202   file.Source.push_back(source);
00203   file.KeepData = false;
00204   job.DataStaging.File.push_back(file);
00205 
00206   // Needed by the XRSLParser.
00207   std::ofstream f("3-Upload-Delete", std::ifstream::trunc);
00208   f << "3-Upload-Delete";
00209   f.close();
00210 
00211   arcJob.Parse(job.UnParse("ARCJSDL"));
00212   ARC_ASSERT(arcJob);
00213   ARC_ASSERT(arcJob.DataStaging.File.size() == 1);
00214   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00215   ARC_ASSERT(arcJob.DataStaging.File.front().Source.size() == 1 && arcJob.DataStaging.File.front().Source.front().URI);
00216   ARC_ASSERT(job.DataStaging.File.front().Source.front().URI == arcJob.DataStaging.File.front().Source.front().URI);
00217 
00218   xrslJob.Parse(job.UnParse("XRSL"));
00219   XRSL_ASSERT(xrslJob);
00220   XRSL_ASSERT(!xrslJob.DataStaging.File.empty());
00221   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.front().Name);
00222   XRSL_ASSERT(xrslJob.DataStaging.File.front().Source.size() == 1 && xrslJob.DataStaging.File.front().Source.front().URI);
00223   XRSL_ASSERT(job.DataStaging.File.front().Source.front().URI == xrslJob.DataStaging.File.front().Source.front().URI);
00224 
00225   jdlJob.Parse(job.UnParse("JDL"));
00226   JDL_ASSERT(jdlJob);
00227   JDL_ASSERT(!jdlJob.DataStaging.File.empty());
00228   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.front().Name);
00229   JDL_ASSERT(jdlJob.DataStaging.File.front().Source.size() == 1 && jdlJob.DataStaging.File.front().Source.front().URI);
00230   JDL_ASSERT(job.DataStaging.File.front().Source.front().URI == jdlJob.DataStaging.File.front().Source.front().URI);
00231 }
00232 
00234 void JobDescriptionTest::TestDataStagingCreateDownload() {
00235   job.DataStaging.File.clear();
00236 
00237   Arc::FileType file;
00238   file.Name = "4-Create-Download";
00239   file.KeepData = true;
00240   job.DataStaging.File.push_back(file);
00241 
00242   arcJob.Parse(job.UnParse("ARCJSDL"));
00243   ARC_ASSERT(arcJob);
00244   ARC_ASSERT(arcJob.DataStaging.File.size() == 1);
00245   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00246   ARC_ASSERT(arcJob.DataStaging.File.front().KeepData);
00247 
00248   xrslJob.Parse(job.UnParse("XRSL"));
00249   XRSL_ASSERT(xrslJob);
00250   XRSL_ASSERT(!xrslJob.DataStaging.File.empty());
00251   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.back().Name);
00252   XRSL_ASSERT(xrslJob.DataStaging.File.back().KeepData);
00253 
00254   jdlJob.Parse(job.UnParse("JDL"));
00255   JDL_ASSERT(jdlJob);
00256   JDL_ASSERT(!jdlJob.DataStaging.File.empty());
00257   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.back().Name);
00258   JDL_ASSERT(jdlJob.DataStaging.File.back().KeepData);
00259 }
00260 
00262 void JobDescriptionTest::TestDataStagingDownloadDownload() {
00263   job.DataStaging.File.clear();
00264 
00265   Arc::FileType file;
00266   file.Name = "5-Download-Download";
00267   Arc::DataSourceType source;
00268   source.URI = "http://example.com/" + file.Name;
00269   source.Threads = -1;
00270   file.Source.push_back(source);
00271   file.KeepData = true;
00272   job.DataStaging.File.push_back(file);
00273 
00274   arcJob.Parse(job.UnParse("ARCJSDL"));
00275   ARC_ASSERT(arcJob);
00276   ARC_ASSERT(arcJob.DataStaging.File.size() == 1);
00277   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00278   ARC_ASSERT(arcJob.DataStaging.File.front().Source.size() == 1 && arcJob.DataStaging.File.front().Source.front().URI);
00279   ARC_ASSERT(job.DataStaging.File.front().Source.front().URI == arcJob.DataStaging.File.front().Source.front().URI);
00280   ARC_ASSERT(arcJob.DataStaging.File.front().KeepData);
00281 
00282   xrslJob.Parse(job.UnParse("XRSL"));
00283   XRSL_ASSERT(xrslJob);
00284   XRSL_ASSERT(!xrslJob.DataStaging.File.empty());
00285   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.front().Name);
00286   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.back().Name);
00287   XRSL_ASSERT(xrslJob.DataStaging.File.front().Source.size() == 1 && xrslJob.DataStaging.File.front().Source.front().URI);
00288   XRSL_ASSERT(job.DataStaging.File.front().Source.front().URI == xrslJob.DataStaging.File.front().Source.front().URI);
00289   XRSL_ASSERT(!xrslJob.DataStaging.File.front().KeepData);
00290   XRSL_ASSERT(xrslJob.DataStaging.File.back().KeepData);
00291 
00292   jdlJob.Parse(job.UnParse("JDL"));
00293   JDL_ASSERT(jdlJob);
00294   JDL_ASSERT(!jdlJob.DataStaging.File.empty());
00295   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.front().Name);
00296   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.back().Name);
00297   JDL_ASSERT(jdlJob.DataStaging.File.front().Source.size() == 1 && jdlJob.DataStaging.File.front().Source.front().URI);
00298   JDL_ASSERT(job.DataStaging.File.front().Source.front().URI == jdlJob.DataStaging.File.front().Source.front().URI);
00299   JDL_ASSERT(!jdlJob.DataStaging.File.front().KeepData);
00300   JDL_ASSERT(jdlJob.DataStaging.File.back().KeepData);
00301 }
00302 
00304 void JobDescriptionTest::TestDataStagingUploadDownload() {
00305   job.DataStaging.File.clear();
00306 
00307   Arc::FileType file;
00308   file.Name = "6-Upload-Download";
00309   Arc::DataSourceType source;
00310   source.URI = file.Name;
00311   source.Threads = -1;
00312   file.Source.push_back(source);
00313   file.KeepData = true;
00314   job.DataStaging.File.push_back(file);
00315 
00316   // Needed by the XRSLParser.
00317   std::ofstream f(file.Name.c_str(), std::ifstream::trunc);
00318   f << "6-Upload-Download";
00319   f.close();
00320 
00321   arcJob.Parse(job.UnParse("ARCJSDL"));
00322   ARC_ASSERT(arcJob);
00323   ARC_ASSERT(arcJob.DataStaging.File.size() == 1);
00324   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00325   ARC_ASSERT(arcJob.DataStaging.File.front().Source.size() == 1 && arcJob.DataStaging.File.front().Source.front().URI);
00326   ARC_ASSERT(job.DataStaging.File.front().Source.front().URI == arcJob.DataStaging.File.front().Source.front().URI);
00327   ARC_ASSERT(arcJob.DataStaging.File.front().KeepData);
00328 
00329   xrslJob.Parse(job.UnParse("XRSL"));
00330   XRSL_ASSERT(xrslJob);
00331   XRSL_ASSERT(!xrslJob.DataStaging.File.empty());
00332   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.front().Name);
00333   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.back().Name);
00334   XRSL_ASSERT(xrslJob.DataStaging.File.front().Source.size() == 1 && xrslJob.DataStaging.File.front().Source.front().URI);
00335   XRSL_ASSERT(job.DataStaging.File.front().Source.front().URI == xrslJob.DataStaging.File.front().Source.front().URI);
00336   XRSL_ASSERT(!xrslJob.DataStaging.File.front().KeepData);
00337   XRSL_ASSERT(xrslJob.DataStaging.File.back().KeepData);
00338 
00339   jdlJob.Parse(job.UnParse("JDL"));
00340   JDL_ASSERT(jdlJob);
00341   JDL_ASSERT(!jdlJob.DataStaging.File.empty());
00342   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.front().Name);
00343   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.back().Name);
00344   JDL_ASSERT(jdlJob.DataStaging.File.front().Source.size() == 1 && jdlJob.DataStaging.File.front().Source.front().URI);
00345   JDL_ASSERT(job.DataStaging.File.front().Source.front().URI == jdlJob.DataStaging.File.front().Source.front().URI);
00346   JDL_ASSERT(!jdlJob.DataStaging.File.front().KeepData);
00347   JDL_ASSERT(jdlJob.DataStaging.File.back().KeepData);
00348 }
00349 
00351 void JobDescriptionTest::TestDataStagingCreateUpload() {
00352   job.DataStaging.File.clear();
00353 
00354   Arc::FileType file;
00355   file.Name = "7-Create-Upload";
00356   Arc::DataTargetType target;
00357   target.URI = "http://example.com/" + file.Name;
00358   target.Threads = -1;
00359   file.Target.push_back(target);
00360   file.KeepData = false;
00361   job.DataStaging.File.push_back(file);
00362 
00363   arcJob.Parse(job.UnParse("ARCJSDL"));
00364   ARC_ASSERT(arcJob);
00365   ARC_ASSERT(arcJob.DataStaging.File.size() == 1);
00366   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00367   ARC_ASSERT(arcJob.DataStaging.File.front().Target.size() == 1 && arcJob.DataStaging.File.front().Target.front().URI);
00368   ARC_ASSERT(job.DataStaging.File.front().Target.front().URI == arcJob.DataStaging.File.front().Target.front().URI);
00369   ARC_ASSERT(!arcJob.DataStaging.File.front().KeepData);
00370 
00371   xrslJob.Parse(job.UnParse("XRSL"));
00372   XRSL_ASSERT(xrslJob);
00373   XRSL_ASSERT(!xrslJob.DataStaging.File.empty());
00374   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.back().Name);
00375   XRSL_ASSERT(xrslJob.DataStaging.File.back().Target.size() == 1 && xrslJob.DataStaging.File.back().Target.front().URI);
00376   XRSL_ASSERT(job.DataStaging.File.front().Target.front().URI == xrslJob.DataStaging.File.back().Target.front().URI);
00377   XRSL_ASSERT(!xrslJob.DataStaging.File.back().KeepData);
00378 
00379   jdlJob.Parse(job.UnParse("JDL"));
00380   JDL_ASSERT(jdlJob);
00381   JDL_ASSERT(!jdlJob.DataStaging.File.empty());
00382   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.back().Name);
00383   JDL_ASSERT(jdlJob.DataStaging.File.back().Target.size() == 1 && jdlJob.DataStaging.File.back().Target.front().URI);
00384   JDL_ASSERT(job.DataStaging.File.front().Target.front().URI == jdlJob.DataStaging.File.back().Target.front().URI);
00385   JDL_ASSERT(!jdlJob.DataStaging.File.back().KeepData);
00386 }
00387 
00389 void JobDescriptionTest::TestDataStagingDownloadUpload() {
00390   job.DataStaging.File.clear();
00391 
00392   Arc::FileType file;
00393   file.Name = "8-Download-Upload";
00394   Arc::DataSourceType source;
00395   source.URI = "http://example.com/" + file.Name;
00396   source.Threads = -1;
00397   file.Source.push_back(source);
00398   Arc::DataTargetType target;
00399   target.URI = "http://example.com/" + file.Name;
00400   target.Threads = -1;
00401   file.Target.push_back(target);
00402   file.KeepData = false;
00403   job.DataStaging.File.push_back(file);
00404 
00405   arcJob.Parse(job.UnParse("ARCJSDL"));
00406   ARC_ASSERT(arcJob);
00407   ARC_ASSERT(arcJob.DataStaging.File.size() == 1);
00408   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00409   ARC_ASSERT(arcJob.DataStaging.File.front().Source.size() == 1 && arcJob.DataStaging.File.front().Source.front().URI);
00410   ARC_ASSERT(job.DataStaging.File.front().Source.front().URI == arcJob.DataStaging.File.front().Source.front().URI);
00411   ARC_ASSERT(arcJob.DataStaging.File.front().Target.size() == 1 && arcJob.DataStaging.File.front().Target.front().URI);
00412   ARC_ASSERT(job.DataStaging.File.front().Target.front().URI == arcJob.DataStaging.File.front().Target.front().URI);
00413   ARC_ASSERT(!arcJob.DataStaging.File.front().KeepData);
00414 
00415   xrslJob.Parse(job.UnParse("XRSL"));
00416   XRSL_ASSERT(xrslJob);
00417   XRSL_ASSERT(!xrslJob.DataStaging.File.empty());
00418   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.front().Name);
00419   XRSL_ASSERT(xrslJob.DataStaging.File.front().Source.size() == 1 && xrslJob.DataStaging.File.front().Source.front().URI);
00420   XRSL_ASSERT(job.DataStaging.File.front().Source.front().URI == xrslJob.DataStaging.File.front().Source.front().URI);
00421   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.back().Name);
00422   XRSL_ASSERT(xrslJob.DataStaging.File.back().Target.size() == 1 && xrslJob.DataStaging.File.back().Target.front().URI);
00423   XRSL_ASSERT(job.DataStaging.File.back().Target.front().URI == xrslJob.DataStaging.File.back().Target.front().URI);
00424   XRSL_ASSERT(!xrslJob.DataStaging.File.front().KeepData);
00425   XRSL_ASSERT(!xrslJob.DataStaging.File.back().KeepData);
00426 
00427   jdlJob.Parse(job.UnParse("JDL"));
00428   JDL_ASSERT(jdlJob);
00429   JDL_ASSERT(!jdlJob.DataStaging.File.empty());
00430   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.front().Name);
00431   JDL_ASSERT(jdlJob.DataStaging.File.front().Source.size() == 1 && jdlJob.DataStaging.File.front().Source.front().URI);
00432   JDL_ASSERT(job.DataStaging.File.front().Source.front().URI == jdlJob.DataStaging.File.front().Source.front().URI);
00433   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.back().Name);
00434   JDL_ASSERT(jdlJob.DataStaging.File.back().Target.size() == 1 && jdlJob.DataStaging.File.back().Target.front().URI);
00435   JDL_ASSERT(job.DataStaging.File.front().Target.front().URI == jdlJob.DataStaging.File.back().Target.front().URI);
00436   JDL_ASSERT(!jdlJob.DataStaging.File.front().KeepData);
00437   JDL_ASSERT(!jdlJob.DataStaging.File.back().KeepData);
00438 }
00439 
00441 void JobDescriptionTest::TestDataStagingUploadUpload() {
00442   job.DataStaging.File.clear();
00443 
00444   Arc::FileType file;
00445   file.Name = "9-Upload-Upload";
00446    Arc::DataSourceType source;
00447   source.URI = file.Name;
00448   source.Threads = -1;
00449   file.Source.push_back(source);
00450   Arc::DataTargetType target;
00451   target.URI = "http://example.com/" + file.Name;
00452   target.Threads = -1;
00453   file.Target.push_back(target);
00454   file.KeepData = false;
00455   job.DataStaging.File.push_back(file);
00456 
00457   // Needed by the XRSLParser.
00458   std::ofstream f(file.Name.c_str(), std::ifstream::trunc);
00459   f << "9-Upload-Upload";
00460   f.close();
00461 
00462   arcJob.Parse(job.UnParse("ARCJSDL"));
00463   ARC_ASSERT(arcJob);
00464   ARC_ASSERT(arcJob.DataStaging.File.size() == 1);
00465   ARC_ASSERT_EQUAL(job.DataStaging.File.front().Name, arcJob.DataStaging.File.front().Name);
00466   ARC_ASSERT(arcJob.DataStaging.File.front().Source.size() == 1 && arcJob.DataStaging.File.front().Source.front().URI);
00467   ARC_ASSERT(job.DataStaging.File.front().Source.front().URI == arcJob.DataStaging.File.front().Source.front().URI);
00468   ARC_ASSERT(arcJob.DataStaging.File.front().Target.size() == 1 && arcJob.DataStaging.File.front().Target.front().URI);
00469   ARC_ASSERT(job.DataStaging.File.front().Target.front().URI == arcJob.DataStaging.File.front().Target.front().URI);
00470   ARC_ASSERT(!arcJob.DataStaging.File.front().KeepData);
00471 
00472   xrslJob.Parse(job.UnParse("XRSL"));
00473   XRSL_ASSERT(xrslJob);
00474   XRSL_ASSERT(!xrslJob.DataStaging.File.empty());
00475   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.front().Name);
00476   XRSL_ASSERT(xrslJob.DataStaging.File.front().Source.size() == 1 && xrslJob.DataStaging.File.front().Source.front().URI);
00477   XRSL_ASSERT(job.DataStaging.File.front().Source.front().URI == xrslJob.DataStaging.File.front().Source.front().URI);
00478   XRSL_ASSERT_EQUAL(job.DataStaging.File.front().Name, xrslJob.DataStaging.File.back().Name);
00479   XRSL_ASSERT(xrslJob.DataStaging.File.back().Target.size() == 1 && xrslJob.DataStaging.File.back().Target.front().URI);
00480   XRSL_ASSERT(job.DataStaging.File.back().Target.front().URI == xrslJob.DataStaging.File.back().Target.front().URI);
00481   XRSL_ASSERT(!xrslJob.DataStaging.File.front().KeepData);
00482   XRSL_ASSERT(!xrslJob.DataStaging.File.back().KeepData);
00483 
00484   jdlJob.Parse(job.UnParse("JDL"));
00485   JDL_ASSERT(jdlJob);
00486   JDL_ASSERT(!jdlJob.DataStaging.File.empty());
00487   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.front().Name);
00488   JDL_ASSERT(jdlJob.DataStaging.File.front().Source.size() == 1 && jdlJob.DataStaging.File.front().Source.front().URI);
00489   JDL_ASSERT(job.DataStaging.File.front().Source.front().URI == jdlJob.DataStaging.File.front().Source.front().URI);
00490   JDL_ASSERT_EQUAL(job.DataStaging.File.front().Name, jdlJob.DataStaging.File.back().Name);
00491   JDL_ASSERT(jdlJob.DataStaging.File.back().Target.size() == 1 && jdlJob.DataStaging.File.back().Target.front().URI);
00492   JDL_ASSERT(job.DataStaging.File.front().Target.front().URI == jdlJob.DataStaging.File.back().Target.front().URI);
00493   JDL_ASSERT(!jdlJob.DataStaging.File.front().KeepData);
00494   JDL_ASSERT(!jdlJob.DataStaging.File.back().KeepData);
00495 }
00496 
00497 void JobDescriptionTest::TestPOSIXCompliance() {
00500   const std::string posixJSDLStr = "<?xml version=\"1.0\"?>"
00501 "<JobDefinition>"
00502 "<JobDescription>"
00503 "<Application>"
00504 "<posix-jsdl:POSIXApplication>"
00505 "<posix-jsdl:Executable>executable</posix-jsdl:Executable>"
00506 "<posix-jsdl:Argument>arg1</posix-jsdl:Argument>"
00507 "<posix-jsdl:Argument>arg2</posix-jsdl:Argument>"
00508 "<posix-jsdl:Argument>arg3</posix-jsdl:Argument>"
00509 "<posix-jsdl:Input>input</posix-jsdl:Input>"
00510 "<posix-jsdl:Output>output</posix-jsdl:Output>"
00511 "<posix-jsdl:Error>error</posix-jsdl:Error>"
00512 "<posix-jsdl:Environment name=\"var1\">value1</posix-jsdl:Environment>"
00513 "<posix-jsdl:Environment name=\"var2\">value2</posix-jsdl:Environment>"
00514 "<posix-jsdl:Environment name=\"var3\">value3</posix-jsdl:Environment>"
00515 "<posix-jsdl:WallTimeLimit>50</posix-jsdl:WallTimeLimit>"
00516 "<posix-jsdl:MemoryLimit>100</posix-jsdl:MemoryLimit>"
00517 "<posix-jsdl:CPUTimeLimit>110</posix-jsdl:CPUTimeLimit>"
00518 "<posix-jsdl:ProcessCountLimit>2</posix-jsdl:ProcessCountLimit>"
00519 "<posix-jsdl:VirtualMemoryLimit>500</posix-jsdl:VirtualMemoryLimit>"
00520 "<posix-jsdl:ThreadCountLimit>7</posix-jsdl:ThreadCountLimit>"
00521 "</posix-jsdl:POSIXApplication>"
00522 "</Application>"
00523 "</JobDescription>"
00524 "</JobDefinition>";
00525 
00526   job.Application.Input = "input";
00527   job.Application.Output = "output";
00528   job.Application.Error = "error";
00529 
00530   job.Application.Environment.push_back(std::make_pair("var1", "value1"));
00531   job.Application.Environment.push_back(std::make_pair("var2", "value2"));
00532   job.Application.Environment.push_back(std::make_pair("var3", "value3"));
00533 
00534   job.Resources.TotalWallTime = 50;
00535   job.Resources.IndividualPhysicalMemory = 100;
00536   job.Resources.TotalCPUTime = 110;
00537   job.Resources.SlotRequirement.NumberOfSlots = 2;
00538   job.Resources.IndividualVirtualMemory = 500;
00539   job.Resources.SlotRequirement.ThreadsPerProcesses = 7;
00540 
00541   arcJob.Parse(posixJSDLStr);
00542 
00543   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Application.Executable.Name, arcJob.Application.Executable.Name);
00544   CPPUNIT_ASSERT_MESSAGE("POSIX compliance failure", job.Application.Executable.Argument == arcJob.Application.Executable.Argument);
00545   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Application.Input, arcJob.Application.Input);
00546   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Application.Output, arcJob.Application.Output);
00547   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Application.Error, arcJob.Application.Error);
00548   CPPUNIT_ASSERT_MESSAGE("POSIX compliance failure", job.Application.Environment == arcJob.Application.Environment);
00549 
00550   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.TotalWallTime.range.max, arcJob.Resources.TotalWallTime.range.max);
00551   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.IndividualPhysicalMemory.max, arcJob.Resources.IndividualPhysicalMemory.max);
00552   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.TotalCPUTime.range.max, arcJob.Resources.TotalCPUTime.range.max);
00553   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.SlotRequirement.NumberOfSlots.max, arcJob.Resources.SlotRequirement.NumberOfSlots.max);
00554   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.IndividualVirtualMemory.max, arcJob.Resources.IndividualVirtualMemory.max);
00555   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.SlotRequirement.ThreadsPerProcesses.max, arcJob.Resources.SlotRequirement.ThreadsPerProcesses.max);
00556 
00557   Arc::XMLNode xmlArcJSDL(arcJob.UnParse("ARCJSDL"));
00558   Arc::XMLNode pApp = xmlArcJSDL["JobDescription"]["Application"]["POSIXApplication"];
00559 
00560   CPPUNIT_ASSERT_MESSAGE("POSIX compliance failure", pApp);
00561   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Application.Executable.Name, (std::string)pApp["Executable"]);
00562   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"arg1", (std::string)pApp["Argument"][0]);
00563   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"arg2", (std::string)pApp["Argument"][1]);
00564   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"arg3", (std::string)pApp["Argument"][2]);
00565   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Application.Input, (std::string)pApp["Input"]);
00566   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Application.Output, (std::string)pApp["Output"]);
00567   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Application.Error, (std::string)pApp["Error"]);
00568 
00569   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"var1",   (std::string)pApp["Environment"][0].Attribute("name"));
00570   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"value1", (std::string)pApp["Environment"][0]);
00571   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"var2",   (std::string)pApp["Environment"][1].Attribute("name"));
00572   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"value2", (std::string)pApp["Environment"][1]);
00573   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"var3",   (std::string)pApp["Environment"][2].Attribute("name"));
00574   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", (std::string)"value3", (std::string)pApp["Environment"][2]);
00575 
00576   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.TotalWallTime.range.max, Arc::stringto<int>(pApp["WallTimeLimit"]));
00577   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.IndividualPhysicalMemory.max, Arc::stringto<int64_t>(pApp["MemoryLimit"]));
00578   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.TotalCPUTime.range.max, Arc::stringto<int>(pApp["CPUTimeLimit"]));
00579   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.SlotRequirement.NumberOfSlots.max, Arc::stringto<int>(pApp["ProcessCountLimit"]));
00580   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.IndividualVirtualMemory.max, Arc::stringto<int64_t>(pApp["VirtualMemoryLimit"]));
00581   CPPUNIT_ASSERT_EQUAL_MESSAGE("POSIX compliance failure", job.Resources.SlotRequirement.ThreadsPerProcesses.max, Arc::stringto<int>(pApp["ThreadCountLimit"]));
00582 }
00583 
00584 void JobDescriptionTest::TestHPCCompliance() {
00587   const std::string hpcJSDLStr = "<?xml version=\"1.0\"?>"
00588 "<JobDefinition>"
00589 "<JobDescription>"
00590 "<Application>"
00591 "<HPC-jsdl:HPCProfileApplication>"
00592 "<HPC-jsdl:Executable>executable</HPC-jsdl:Executable>"
00593 "<HPC-jsdl:Argument>arg1</HPC-jsdl:Argument>"
00594 "<HPC-jsdl:Argument>arg2</HPC-jsdl:Argument>"
00595 "<HPC-jsdl:Argument>arg3</HPC-jsdl:Argument>"
00596 "<HPC-jsdl:Input>input</HPC-jsdl:Input>"
00597 "<HPC-jsdl:Output>output</HPC-jsdl:Output>"
00598 "<HPC-jsdl:Error>error</HPC-jsdl:Error>"
00599 "<HPC-jsdl:Environment name=\"var1\">value1</HPC-jsdl:Environment>"
00600 "<HPC-jsdl:Environment name=\"var2\">value2</HPC-jsdl:Environment>"
00601 "<HPC-jsdl:Environment name=\"var3\">value3</HPC-jsdl:Environment>"
00602 "<HPC-jsdl:WallTimeLimit>50</HPC-jsdl:WallTimeLimit>"
00603 "<HPC-jsdl:MemoryLimit>100</HPC-jsdl:MemoryLimit>"
00604 "<HPC-jsdl:CPUTimeLimit>110</HPC-jsdl:CPUTimeLimit>"
00605 "<HPC-jsdl:ProcessCountLimit>2</HPC-jsdl:ProcessCountLimit>"
00606 "<HPC-jsdl:VirtualMemoryLimit>500</HPC-jsdl:VirtualMemoryLimit>"
00607 "<HPC-jsdl:ThreadCountLimit>7</HPC-jsdl:ThreadCountLimit>"
00608 "</HPC-jsdl:HPCProfileApplication>"
00609 "</Application>"
00610 "</JobDescription>"
00611 "</JobDefinition>";
00612 
00613   job.Application.Input = "input";
00614   job.Application.Output = "output";
00615   job.Application.Error = "error";
00616 
00617   job.Application.Environment.push_back(std::make_pair("var1", "value1"));
00618   job.Application.Environment.push_back(std::make_pair("var2", "value2"));
00619   job.Application.Environment.push_back(std::make_pair("var3", "value3"));
00620 
00621   arcJob.Parse(hpcJSDLStr);
00622 
00623   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", job.Application.Executable.Name, arcJob.Application.Executable.Name);
00624   CPPUNIT_ASSERT_MESSAGE("HPC compliance failure", job.Application.Executable.Argument == arcJob.Application.Executable.Argument);
00625   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", job.Application.Input, arcJob.Application.Input);
00626   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", job.Application.Output, arcJob.Application.Output);
00627   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", job.Application.Error, arcJob.Application.Error);
00628   CPPUNIT_ASSERT_MESSAGE("HPC compliance failure", job.Application.Environment == arcJob.Application.Environment);
00629 
00630   Arc::XMLNode xmlArcJSDL(arcJob.UnParse("ARCJSDL"));
00631   Arc::XMLNode pApp = xmlArcJSDL["JobDescription"]["Application"]["HPCProfileApplication"];
00632 
00633   CPPUNIT_ASSERT_MESSAGE("HPC compliance failure", pApp);
00634   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", job.Application.Executable.Name, (std::string)pApp["Executable"]);
00635   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"arg1", (std::string)pApp["Argument"][0]);
00636   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"arg2", (std::string)pApp["Argument"][1]);
00637   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"arg3", (std::string)pApp["Argument"][2]);
00638   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", job.Application.Input, (std::string)pApp["Input"]);
00639   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", job.Application.Output, (std::string)pApp["Output"]);
00640   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", job.Application.Error, (std::string)pApp["Error"]);
00641 
00642   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"var1",   (std::string)pApp["Environment"][0].Attribute("name"));
00643   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"value1", (std::string)pApp["Environment"][0]);
00644   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"var2",   (std::string)pApp["Environment"][1].Attribute("name"));
00645   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"value2", (std::string)pApp["Environment"][1]);
00646   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"var3",   (std::string)pApp["Environment"][2].Attribute("name"));
00647   CPPUNIT_ASSERT_EQUAL_MESSAGE("HPC compliance failure", (std::string)"value3", (std::string)pApp["Environment"][2]);
00648 }
00649 
00650 CPPUNIT_TEST_SUITE_REGISTRATION(JobDescriptionTest);