Newer
Older
Federico Montesino Pouzols
committed
#ifndef COMPUTERESOURCEINFOTEST_H_
#define COMPUTERESOURCEINFOTEST_H_
#include "MantidKernel/Exception.h"
Federico Montesino Pouzols
committed
#include "MantidKernel/FacilityInfo.h"
#include <Poco/DOM/AutoPtr.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/DOMParser.h>
#include <Poco/XML/XMLException.h>
Federico Montesino Pouzols
committed
using namespace Mantid::Kernel;
class ComputeResourceInfoTest : public CxxTest::TestSuite {
public:
void test_allMissing() {
Federico Montesino Pouzols
committed
FacilityInfo *fac = NULL;
TS_ASSERT_THROWS_NOTHING(fac =
createCRInfoInMinimalFacility(simpleInstStr));
TS_ASSERT(fac);
std::vector<ComputeResourceInfo> cri;
TS_ASSERT_THROWS_NOTHING(cri = fac->computeResInfos());
TS_ASSERT_EQUALS(cri.size(), 0);
Federico Montesino Pouzols
committed
delete fac;
fac = NULL;
TS_ASSERT_THROWS(fac = createCRInfoInMinimalFacility(
"<computeResource fooAtt=\"barVal\"/>"),
std::runtime_error);
TS_ASSERT(!fac);
delete fac;
}
Federico Montesino Pouzols
committed
void test_noURLTag() {
const std::string crTxt = "<computeResource name=\"foo\">"
"<u>" +
fermiURL + "</u>"
"</computeResource>";
FacilityInfo *fac = NULL;
TS_ASSERT_THROWS(fac = createCRInfoInMinimalFacility(crTxt),
std::runtime_error);
TS_ASSERT(!fac);
delete fac;
}
void test_wrongXML() {
const std::string crTxt = "<computeResource name=\"foo\">"
"<u_foo>" +
fermiURL + "</u_bar>"
"</compResource>";
FacilityInfo *fac = NULL;
TS_ASSERT_THROWS(fac = createCRInfoInMinimalFacility(crTxt),
Poco::XML::XMLException);
TS_ASSERT(!fac);
delete fac;
Federico Montesino Pouzols
committed
}
void test_normalFermi() {
const std::string fermi = "<computeResource name=\"" + fermiName +
"\">"
"<baseURL>" +
fermiURL + "</baseURL>"
"</computeResource>";
FacilityInfo *fac = NULL;
TS_ASSERT_THROWS_NOTHING(fac = createCRInfoInMinimalFacility(fermi));
TS_ASSERT(fac);
TS_ASSERT_EQUALS(fac->name(), this->testFacilityName);
std::vector<ComputeResourceInfo> cri;
TS_ASSERT_THROWS_NOTHING(cri = fac->computeResInfos());
TS_ASSERT_EQUALS(cri.size(), 1);
Federico Montesino Pouzols
committed
ComputeResourceInfo cr = fac->computeResInfos().front();
TS_ASSERT_THROWS(ComputeResourceInfo fail = fac->computeResource(scarfName),
Mantid::Kernel::Exception::NotFoundError);
ComputeResourceInfo cr2 = fac->computeResource(fermiName);
TS_ASSERT_EQUALS(cr, cr2);
TS_ASSERT_EQUALS(cr, cri.front());
TS_ASSERT_EQUALS(cr2, cri.front());
TS_ASSERT_EQUALS(cr.name(), fermiName);
TS_ASSERT_EQUALS(cr2.name(), fermiName);
TS_ASSERT_EQUALS(cr.baseURL(), fermiURL);
TS_ASSERT_EQUALS(cr2.baseURL(), fermiURL);
TS_ASSERT_EQUALS(cr.remoteJobManagerType(), defaultType);
TS_ASSERT_EQUALS(cr2.remoteJobManagerType(), defaultType);
TS_ASSERT_EQUALS(cr.facility().name(), fac->name());
TS_ASSERT_EQUALS(cr2.facility().name(), fac->name());
Federico Montesino Pouzols
committed
}
void test_brokenFermi() {
// wrong 'baseURL' tag
const std::string fermi = "<computeResource name=\"" + fermiName + "\">"
"<URL>" +
fermiURL + "</URL>"
"</computeResource>";
FacilityInfo *fac = NULL;
TS_ASSERT_THROWS(fac = createCRInfoInMinimalFacility(fermi),
std::runtime_error);
TS_ASSERT(!fac);
delete fac;
Federico Montesino Pouzols
committed
}
void test_normalSCARF() {
const std::string scarf = "<computeResource name=\"" + scarfName +
"\" JobManagerType=\"" + scarfType + "\">"
"<baseURL>" +
Federico Montesino Pouzols
committed
scarfURL + "</baseURL>"
"</computeResource>";
Federico Montesino Pouzols
committed
FacilityInfo *fac = NULL;
TS_ASSERT_THROWS_NOTHING(fac = createCRInfoInMinimalFacility(scarf));
TS_ASSERT(fac);
TS_ASSERT_EQUALS(fac->name(), this->testFacilityName);
std::vector<ComputeResourceInfo> cri;
TS_ASSERT_THROWS_NOTHING(cri = fac->computeResInfos());
TS_ASSERT_EQUALS(cri.size(), 1);
Federico Montesino Pouzols
committed
ComputeResourceInfo cr = fac->computeResInfos().front();
TS_ASSERT_THROWS(ComputeResourceInfo fail = fac->computeResource("inexistent!"),
Mantid::Kernel::Exception::NotFoundError);
ComputeResourceInfo cr2 = fac->computeResource(scarfName);
TS_ASSERT_EQUALS(cr, cr2);
TS_ASSERT_EQUALS(cri.front(), cr);
TS_ASSERT_EQUALS(cri.front(), cr2);
TS_ASSERT_EQUALS(scarfName, cr.name());
TS_ASSERT_EQUALS(scarfName, cr2.name());
TS_ASSERT_EQUALS(scarfURL, cr.baseURL());
TS_ASSERT_EQUALS(scarfURL, cr2.baseURL());
TS_ASSERT_EQUALS(scarfType, cr.remoteJobManagerType());
TS_ASSERT_EQUALS(scarfType, cr2.remoteJobManagerType());
TS_ASSERT_EQUALS(fac->name(), cr.facility().name());
TS_ASSERT_EQUALS(fac->name(), cr2.facility().name());
delete fac;
Federico Montesino Pouzols
committed
}
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
void test_brokenSCARF() {
const std::string type = "SCARFLSFJobManager";
const std::string err = "<computeResource foo=\"" + scarfName +
"\" JobManagerType=\"" + type + "\">"
"<URL>" +
scarfURL + "</URL>"
"</computeResource>";
FacilityInfo *fac = NULL;
TS_ASSERT_THROWS(fac = createCRInfoInMinimalFacility(err),
std::runtime_error);
TS_ASSERT(!fac);
delete fac;
}
void test_equals() {
const std::string otherName = "other";
const std::string otherURL = "www.example.com/foo/baz";
const std::string thirdName = "third";
const std::string rep = "<computeResource name=\"" + fermiName +
"\">"
"<baseURL>" +
fermiURL + "</baseURL>"
"</computeResource>"
"<computeResource name=\"" +
otherName + "\">"
"<baseURL>" +
otherURL + "</baseURL>"
"</computeResource>"
"<computeResource name=\"" +
thirdName + "\">"
"<baseURL>" +
fermiURL + "</baseURL>"
"</computeResource>"
"<computeResource name=\"" +
fermiName + "\">"
"<baseURL>" +
fermiURL + "</baseURL>"
"</computeResource>";
FacilityInfo *fac = NULL;
TS_ASSERT_THROWS_NOTHING(fac = createCRInfoInMinimalFacility(rep));
TS_ASSERT(fac);
TS_ASSERT_EQUALS(fac->computeResources().size(), 3);
TS_ASSERT_EQUALS(fac->computeResInfos().size(), 4);
// compare names
TS_ASSERT(fac->computeResources()[0] == fac->computeResources()[0]);
TS_ASSERT(!(fac->computeResources()[0] == fac->computeResources()[1]));
TS_ASSERT(!(fac->computeResources()[0] == fac->computeResources()[2]));
TS_ASSERT(!(fac->computeResources()[1] == fac->computeResources()[2]));
// compare full comp resource info
TS_ASSERT(fac->computeResInfos()[0] == fac->computeResInfos()[0]);
TS_ASSERT(!(fac->computeResInfos()[0] == fac->computeResInfos()[1]));
TS_ASSERT(!(fac->computeResInfos()[0] == fac->computeResInfos()[2]));
TS_ASSERT(!(fac->computeResInfos()[1] == fac->computeResInfos()[2]));
TS_ASSERT(!(fac->computeResInfos()[2] == fac->computeResInfos()[3]));
TS_ASSERT(fac->computeResInfos()[0] == fac->computeResInfos()[3]);
// compare comp resource info retrieved by names
TS_ASSERT(
!(fac->computeResource(fermiName) == fac->computeResource(otherName)));
TS_ASSERT(
!(fac->computeResource(fermiName) == fac->computeResource(thirdName)));
TS_ASSERT(
!(fac->computeResource(otherName) == fac->computeResource(thirdName)));
delete fac;
}
Federico Montesino Pouzols
committed
private:
/// make a minimal facilities file/xml string includin the compute resource
/// passed
FacilityInfo *createCRInfoInMinimalFacility(const std::string &crStr) {
const std::string xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<facilities>"
" <facility name=\"" +
testFacilityName +
"\" FileExtensions=\".xyz\">" + simpleInstStr +
crStr + " </facility>"
"</facilities>";
Federico Montesino Pouzols
committed
return createFacility(xmlStr);
}
FacilityInfo *createFacility(const std::string &xml) {
Poco::XML::DOMParser parser;
Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parseString(xml);
Poco::XML::Element *pRootElem = pDoc->documentElement();
Poco::XML::Element *elem = pRootElem->getChildElement("facility");
return new FacilityInfo(elem);
}
private:
// a minimal instrument to create a facility info
static const std::string simpleInstStr;
// default remote job manager type
static const std::string defaultType;
static const std::string testFacilityName;
Federico Montesino Pouzols
committed
static const std::string fermiName;
static const std::string fermiURL;
static const std::string scarfName;
static const std::string scarfURL;
static const std::string scarfType;
Federico Montesino Pouzols
committed
};
const std::string ComputeResourceInfoTest::simpleInstStr =
"<instrument name=\"AnInst\">"
" <technique>Measuring Stuff</technique>"
"</instrument>";
const std::string ComputeResourceInfoTest::defaultType =
"MantidWebServiceAPIJobManager";
const std::string ComputeResourceInfoTest::testFacilityName = "ATestFacility";
Federico Montesino Pouzols
committed
const std::string ComputeResourceInfoTest::fermiURL =
"https://fermi.ornl.gov/MantidRemote";
const std::string ComputeResourceInfoTest::fermiName = "Fermi";
const std::string ComputeResourceInfoTest::scarfURL =
"https://portal.scarf.rl.ac.uk";
const std::string ComputeResourceInfoTest::scarfName = "SCARF@STFC";
const std::string ComputeResourceInfoTest::scarfType = "SCARFLSFJobManager";
Federico Montesino Pouzols
committed
#endif // COMPUTERESOURCEINFOTEST_H_