Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
#ifndef MANTID_REMOTEALGORITHMS_SUBMITREMOTEJOBTEST_H_
#define MANTID_REMOTEALGORITHMS_SUBMITREMOTEJOBTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAPI/AlgorithmManager.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
#include "MantidRemoteAlgorithms/SubmitRemoteJob2.h"
using namespace Mantid::RemoteAlgorithms;
class SubmitRemoteJob2Test : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static SubmitRemoteJob2Test *createSuite() {
return new SubmitRemoteJob2Test();
}
static void destroySuite(SubmitRemoteJob2Test *suite) { delete suite; }
void test_algorithm() {
testAlg = Mantid::API::AlgorithmManager::Instance().create(
"SubmitRemoteJob" /*, 2*/);
TS_ASSERT(testAlg);
TS_ASSERT_EQUALS(testAlg->name(), "SubmitRemoteJob");
TS_ASSERT_EQUALS(testAlg->version(), 2);
}
void test_castAlgorithm() {
// can create
boost::shared_ptr<SubmitRemoteJob2> a;
TS_ASSERT(a = boost::make_shared<SubmitRemoteJob2>());
// can cast to inherited interfaces and base classes
TS_ASSERT(
dynamic_cast<Mantid::RemoteAlgorithms::SubmitRemoteJob2 *>(a.get()));
TS_ASSERT(dynamic_cast<Mantid::API::Algorithm *>(a.get()));
TS_ASSERT(dynamic_cast<Mantid::Kernel::PropertyManagerOwner *>(a.get()));
TS_ASSERT(dynamic_cast<Mantid::API::IAlgorithm *>(a.get()));
TS_ASSERT(dynamic_cast<Mantid::Kernel::IPropertyManager *>(a.get()));
}
void test_init() {
if (!testAlg->isInitialized())
TS_ASSERT_THROWS_NOTHING(testAlg->initialize());
TS_ASSERT(testAlg->isInitialized());
SubmitRemoteJob2 s;
TS_ASSERT_THROWS_NOTHING(s.initialize());
}
// TODO: when we have a RemoteJobManager capable of creating
// algorithms for different types of compute resources (example:
// Fermi@SNS and SCARF@STFC), create different algorithms for them
void test_propertiesMissing() {
SubmitRemoteJob2 alg1;
TS_ASSERT_THROWS_NOTHING(alg1.initialize());
// Transaction id missing
TS_ASSERT_THROWS_NOTHING(alg1.setPropertyValue("NumNodes", "1"));
TS_ASSERT_THROWS_NOTHING(alg1.setPropertyValue("CoresPerNode", "4"));
TS_ASSERT_THROWS_NOTHING(alg1.setPropertyValue("TaskName", "unit test"));
TS_ASSERT_THROWS_NOTHING(
alg1.setPropertyValue("ScriptName", "test script"));
TS_ASSERT_THROWS_NOTHING(
alg1.setPropertyValue("ScriptParams", "print 'hello world'"));
TS_ASSERT_THROWS(alg1.setPropertyValue("ComputeResource", "missing!"),
std::invalid_argument);
TS_ASSERT_THROWS(alg1.execute(), std::runtime_error);
TS_ASSERT(!alg1.isExecuted());
SubmitRemoteJob2 alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
// task name name missing
TS_ASSERT_THROWS(alg2.setPropertyValue("ComputeResource", "missing!"),
std::invalid_argument);
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("TransactionID", "id001"));
TS_ASSERT_THROWS_NOTHING(
alg2.setPropertyValue("ScriptName", "test script"));
TS_ASSERT_THROWS_NOTHING(
alg2.setPropertyValue("ScriptParams", "print 'hello world'"));
TS_ASSERT_THROWS(alg2.execute(), std::runtime_error);
TS_ASSERT(!alg2.isExecuted());
SubmitRemoteJob2 alg3;
TS_ASSERT_THROWS_NOTHING(alg3.initialize());
// script name name missing
TS_ASSERT_THROWS_NOTHING(alg3.setPropertyValue("TaskName", "unit test"));
TS_ASSERT_THROWS_NOTHING(alg3.setPropertyValue("TransactionID", "id001"));
TS_ASSERT_THROWS_NOTHING(
alg3.setPropertyValue("ScriptParams", "print 'hello world'"));
TS_ASSERT_THROWS(alg3.setPropertyValue("ComputeResource", "missing!"),
std::invalid_argument);
TS_ASSERT_THROWS(alg3.execute(), std::runtime_error);
TS_ASSERT(!alg3.isExecuted());
SubmitRemoteJob2 alg4;
TS_ASSERT_THROWS_NOTHING(alg4.initialize());
// compute resource missing
TS_ASSERT_THROWS_NOTHING(alg4.setPropertyValue("TransactionID", "id001"));
TS_ASSERT_THROWS_NOTHING(alg4.setPropertyValue("TaskName", "unit test"));
TS_ASSERT_THROWS_NOTHING(
alg4.setPropertyValue("ScriptName", "test script"));
TS_ASSERT_THROWS_NOTHING(
alg4.setPropertyValue("ScriptParams", "print 'hello world'"));
TS_ASSERT_THROWS(alg4.execute(), std::runtime_error);
TS_ASSERT(!alg4.isExecuted());
SubmitRemoteJob2 alg5;
TS_ASSERT_THROWS_NOTHING(alg5.initialize());
// py script missing
TS_ASSERT_THROWS_NOTHING(alg5.setPropertyValue("TransactionID", "id001"));
TS_ASSERT_THROWS_NOTHING(alg5.setPropertyValue("TaskName", "unit test"));
TS_ASSERT_THROWS_NOTHING(
alg5.setPropertyValue("ScriptName", "test script"));
TS_ASSERT_THROWS(alg5.setPropertyValue("ComputeResource", "missing!"),
std::invalid_argument);
TS_ASSERT_THROWS(alg5.execute(), std::runtime_error);
TS_ASSERT(!alg5.isExecuted());
}
void test_wrongProperty() {
SubmitRemoteJob2 s;
TS_ASSERT_THROWS_NOTHING(s.initialize();)
TS_ASSERT_THROWS(s.setPropertyValue("Compute", "anything"),
std::runtime_error);
TS_ASSERT_THROWS(s.setPropertyValue("NumNodes", "anything"),
std::invalid_argument);
TS_ASSERT_THROWS(s.setPropertyValue("NumNodes", "-3"),
std::invalid_argument);
TS_ASSERT_THROWS(s.setPropertyValue("CoresPerNode", "anything"),
std::invalid_argument);
TS_ASSERT_THROWS(s.setPropertyValue("Task", "anything"),
std::runtime_error);
TS_ASSERT_THROWS(s.setPropertyValue("Name", "anything"),
std::runtime_error);
TS_ASSERT_THROWS(s.setPropertyValue("Transaction", "anything"),
std::runtime_error);
TS_ASSERT_THROWS(s.setPropertyValue("ID", "anything"), std::runtime_error);
TS_ASSERT_THROWS(s.setPropertyValue("ScriptName", ""),
std::invalid_argument);
TS_ASSERT_THROWS(s.setPropertyValue("Scrip", "any name"),
std::runtime_error);
TS_ASSERT_THROWS(s.setPropertyValue("ScriptParams", ""),
std::invalid_argument);
}
void test_propertiesOK() {
testFacilities.push_back(std::make_pair("SNS", "Fermi"));
testFacilities.push_back(std::make_pair("ISIS", "SCARF@STFC"));
const Mantid::Kernel::FacilityInfo &prevFac =
Mantid::Kernel::ConfigService::Instance().getFacility();
for (size_t fi = 0; fi < testFacilities.size(); fi++) {
const std::string facName = testFacilities[fi].first;
const std::string compName = testFacilities[fi].second;
Mantid::Kernel::ConfigService::Instance().setFacility(facName);
SubmitRemoteJob2 s;
TS_ASSERT_THROWS_NOTHING(s.initialize());
TS_ASSERT_THROWS_NOTHING(s.setPropertyValue("ComputeResource", compName));
TS_ASSERT_THROWS_NOTHING(s.setPropertyValue("NumNodes", "1"));
TS_ASSERT_THROWS_NOTHING(s.setPropertyValue("CoresPerNode", "4"));
TS_ASSERT_THROWS_NOTHING(s.setPropertyValue("TaskName", "unit test"));
TS_ASSERT_THROWS_NOTHING(s.setPropertyValue("TransactionID", "tr001"));
TS_ASSERT_THROWS_NOTHING(s.setPropertyValue("ScriptName", "test script"));
TS_ASSERT_THROWS_NOTHING(
s.setPropertyValue("ScriptParams", "print 'hello world'"));
// TODO: this would run the algorithm and do a remote
// connection. uncomment only when/if we have a mock up for this
// TS_ASSERT_THROWS(s.execute(), std::exception);
TS_ASSERT(!s.isExecuted());
}
Mantid::Kernel::ConfigService::Instance().setFacility(prevFac.name());
}
// TODO: void test_runOK() - with a mock when we can add it.
// ideally, with different compute resources to check the remote job
// manager factory, etc.
private:
Mantid::API::IAlgorithm_sptr testAlg;
std::vector<std::pair<std::string, std::string>> testFacilities;
};
#endif // MANTID_REMOTEALGORITHMS_SUBMITREMOTEJOBTEST_H_