Salome HOME
Merge class BatchManager_eClient into class BatchManager
[tools/libbatch.git] / src / Local / Test / Test_Local_RSH.cxx
index db7203cfec4c6d8700e483bd5ed01e6656e56346..2bf22bd6a60220c6152e9962f73c9e369f996652 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -64,14 +64,12 @@ int main(int argc, char** argv)
     Job job;
     // ... and its parameters ...
     Parametre p;
-    p[EXECUTABLE]    = "source copied-test-script.sh";
+    p[EXECUTABLE]    = "test-script.sh";
     p[NAME]          = "Test_Local_RSH";
     p[WORKDIR]       = workdir;
-    p[INFILE]        = Couple("seta.sh", "copied-seta.sh");
-    p[INFILE]       += Couple("setb.sh", "copied-setb.sh");
-    p[INFILE]       += Couple("test-script.sh", "copied-test-script.sh");
-    p[OUTFILE]       = Couple("result.txt", "orig-result.txt");
-    p[EXECUTIONHOST] = exechost;
+    p[INFILE]        = Couple("seta.sh", workdir + "/copied-seta.sh");
+    p[INFILE]       += Couple("setb.sh", workdir + "/copied-setb.sh");
+    p[OUTFILE]       = Couple("result.txt", workdir + "/orig-result.txt");
     p[USER]          = user;
     job.setParametre(p);
     // ... and its environment
@@ -83,12 +81,12 @@ int main(int argc, char** argv)
     BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
 
     // Create a BatchManager of type Local_RSH on localhost
-    FactBatchManager * fbm = c("RSH");
+    FactBatchManager * fbm = c("LOCAL");
     if (fbm == NULL) {
       cerr << "Can't get RSH batch manager factory" << endl;
       return 1;
     }
-    BatchManager * bm = (*fbm)("localhost");
+    BatchManager * bm = (*fbm)(exechost.c_str(), user.c_str(), RSH);
 
     // Submit the job to the BatchManager
     JobId jobid = bm->submitJob(job);
@@ -97,13 +95,18 @@ int main(int argc, char** argv)
     // Wait for the end of the job
     string state = bm->waitForJobEnd(jobid, timeout);
 
-    if (state != FINISHED && state != FAILED) {
-      cerr << "Error: Job not finished after timeout" << endl;
+    if (state == FINISHED) {
+      cout << "Job " << jobid.__repr__() << " is done" << endl;
+      bm->importOutputFiles(job, "resultdir/seconddirname");
+    } else if (state == FAILED) {
+      cerr << "Job " << jobid.__repr__() << " finished in error" << endl;
+      bm->importOutputFiles(job, "resultdir/seconddirname");
+      return 1;
+    } else {
+      cerr << "Timeout while executing job" << endl;
       return 1;
     }
 
-    cout << "Job " << jobid.__repr__() << " is done" << endl;
-
   } catch (GenericException e) {
     cerr << "Error: " << e << endl;
     return 1;
@@ -115,7 +118,7 @@ int main(int argc, char** argv)
   // test the result file
   string exp = "c = 12";
   string res;
-  ifstream f("result.txt");
+  ifstream f("resultdir/seconddirname/result.txt");
   getline(f, res);
   f.close();