Back to index

nordugrid-arc-nox  1.1.0~rc6
BrokerTest.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include <cppunit/extensions/HelperMacros.h>
00004 
00005 #include <arc/Logger.h>
00006 #include <arc/UserConfig.h>
00007 #include <arc/client/Broker.h>
00008 #include <arc/client/ExecutionTarget.h>
00009 #include <arc/client/JobDescription.h>
00010 
00011 #define CPPASSERT(n)\
00012   tb.PreFilterTargets(etl, job);\
00013   CPPUNIT_ASSERT_EQUAL(n, (int)tb.GetTargets().size());\
00014   tb.clear();
00015 
00016 
00017 class BrokerTest
00018   : public CppUnit::TestFixture {
00019 
00020   CPPUNIT_TEST_SUITE(BrokerTest);
00021   CPPUNIT_TEST(CPUWallTimeTest);
00022   CPPUNIT_TEST(BenckmarkCPUWallTimeTest);
00023   CPPUNIT_TEST_SUITE_END();
00024 
00025 public:
00026   BrokerTest();
00027   void setUp();
00028   void tearDown();
00029   void CPUWallTimeTest();
00030   void BenckmarkCPUWallTimeTest();
00031 
00032   class TestBroker
00033     : public Arc::Broker {
00034   public:
00035     TestBroker(const Arc::UserConfig& usercfg) : Arc::Broker(usercfg) {}
00036     void SortTargets() {}
00037     void clear() { PossibleTargets.clear(); }
00038     const std::list<Arc::ExecutionTarget*>& GetTargets() { return PossibleTargets; }
00039   };
00040 
00041 private:
00042   Arc::LogStream logcerr;
00043   Arc::Logger logger;
00044   const Arc::UserConfig usercfg;
00045   TestBroker tb;
00046   std::list<Arc::ExecutionTarget> etl;
00047   Arc::JobDescription job;
00048 };
00049 
00050 BrokerTest::BrokerTest()
00051   : usercfg(Arc::initializeCredentialsType(Arc::initializeCredentialsType::SkipCredentials)),
00052     tb(usercfg),
00053     etl(1, Arc::ExecutionTarget()),
00054     logger(Arc::Logger::getRootLogger(), "BrokerTest"),
00055     logcerr(std::cerr) {}
00056 
00057 void BrokerTest::setUp() {
00058   etl.front().url = Arc::URL("http://localhost/test");
00059   etl.front().HealthState = "ok";
00060 }
00061 
00062 void BrokerTest::tearDown() {}
00063 
00064 void BrokerTest::CPUWallTimeTest() {
00065   etl.front().MaxCPUTime = 100;
00066   job.Resources.TotalCPUTime.range.max = 110; CPPASSERT(0)
00067   job.Resources.TotalCPUTime.range.max = 100; CPPASSERT(1)
00068   job.Resources.TotalCPUTime.range.max = 90;  CPPASSERT(1)
00069 
00070   etl.front().MinCPUTime = 10;
00071   job.Resources.TotalCPUTime.range.min = 5; CPPASSERT(0)
00072   job.Resources.TotalCPUTime.range.min = 10; CPPASSERT(1)
00073   job.Resources.TotalCPUTime.range.min = 15; CPPASSERT(1)
00074 
00075   etl.front().MaxWallTime = 100;
00076   job.Resources.TotalWallTime.range.max = 110; CPPASSERT(0)
00077   job.Resources.TotalWallTime.range.max = 100; CPPASSERT(1)
00078   job.Resources.TotalWallTime.range.max = 90;  CPPASSERT(1)
00079 
00080   etl.front().MinWallTime = 10;
00081   job.Resources.TotalWallTime.range.min = 5;  CPPASSERT(0)
00082   job.Resources.TotalWallTime.range.min = 10; CPPASSERT(1)
00083   job.Resources.TotalWallTime.range.min = 15; CPPASSERT(1)
00084 }
00085 
00086 void BrokerTest::BenckmarkCPUWallTimeTest() {
00087   etl.front().Benchmarks["TestBenchmark"] = 100.;
00088 
00089   job.Resources.TotalCPUTime.benchmark = std::pair<std::string, double>("TestBenchmark", 50.);
00090   etl.front().MaxCPUTime = 100;
00091   job.Resources.TotalCPUTime.range.max = 210; CPPASSERT(0)
00092   job.Resources.TotalCPUTime.range.max = 200; CPPASSERT(1)
00093   job.Resources.TotalCPUTime.range.max = 190;  CPPASSERT(1)
00094 
00095   etl.front().MinCPUTime = 10;
00096   job.Resources.TotalCPUTime.range.min = 10; CPPASSERT(0)
00097   job.Resources.TotalCPUTime.range.min = 20; CPPASSERT(1)
00098   job.Resources.TotalCPUTime.range.min = 30; CPPASSERT(1)
00099 
00100   job.Resources.TotalWallTime.benchmark = std::pair<std::string, double>("TestBenchmark", 50.);
00101   etl.front().MaxWallTime = 100;
00102   job.Resources.TotalWallTime.range.max = 210; CPPASSERT(0)
00103   job.Resources.TotalWallTime.range.max = 200; CPPASSERT(1)
00104   job.Resources.TotalWallTime.range.max = 190;  CPPASSERT(1)
00105 
00106   etl.front().MinWallTime = 10;
00107   job.Resources.TotalWallTime.range.min = 10;  CPPASSERT(0)
00108   job.Resources.TotalWallTime.range.min = 20; CPPASSERT(1)
00109   job.Resources.TotalWallTime.range.min = 30; CPPASSERT(1)
00110 
00111   etl.front().CPUClockSpeed = 2500;
00112   job.Resources.TotalCPUTime.benchmark = std::pair<std::string, double>("ARC-clockrate", 1000.);
00113   etl.front().MaxCPUTime = 100;
00114   job.Resources.TotalCPUTime.range.max = 300; CPPASSERT(0)
00115   job.Resources.TotalCPUTime.range.max = 250; CPPASSERT(1)
00116   job.Resources.TotalCPUTime.range.max = 200;  CPPASSERT(1)
00117 
00118   etl.front().Benchmarks.erase("ARC-clockrate");
00119   etl.front().CPUClockSpeed = 5600;
00120   etl.front().MaxCPUTime = 200;
00121   job.Resources.TotalCPUTime.range.max = -1;
00122   job.Resources.TotalCPUTime.benchmark = std::pair<std::string, double>("", -1);
00123   std::string xrsl = "&(executable=/bin/echo)(gridtime=600s)";
00124   CPPUNIT_ASSERT(job.Parse(xrsl)); CPPASSERT(0)
00125   xrsl = "&(executable=/bin/echo)(gridtime=400s)";
00126   CPPUNIT_ASSERT(job.Parse(xrsl)); CPPASSERT(1)
00127   xrsl = "&(executable=/bin/echo)(gridtime=200s)";
00128   CPPUNIT_ASSERT(job.Parse(xrsl)); CPPASSERT(1)
00129 }
00130 
00131 CPPUNIT_TEST_SUITE_REGISTRATION(BrokerTest);