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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
/*
* Copyright 2009- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/
#include <iostream>
#include <string>
#include <boost/test/unit_test.hpp>
#include "TestHelper.hpp"
#include "ecflow/attribute/QueueAttr.hpp"
#include "ecflow/base/cts/task/QueueCmd.hpp"
#include "ecflow/node/Defs.hpp"
#include "ecflow/node/Family.hpp"
#include "ecflow/node/Suite.hpp"
#include "ecflow/node/System.hpp"
#include "ecflow/node/Task.hpp"
#include "ecflow/test/scaffold/Naming.hpp"
using namespace std;
using namespace ecf;
BOOST_AUTO_TEST_SUITE(U_Base)
BOOST_AUTO_TEST_SUITE(T_QueueCmd)
BOOST_AUTO_TEST_CASE(test_queue_cmd) {
ECF_NAME_THIS_TEST();
TestLog test_log("test_queue_cmd.log"); // will create log file, and destroy log and remove file at end of scope
// Create the defs file.
// suite suite
// queue q1 s1 s2 s3
// family f
// queue q2 f1 f2 f3
// task t
// queue q3 t1 t2 t3
// endfamily
// endsuite
Defs defs;
string suite_f_t = "/suite/f/t";
suite_ptr s = defs.add_suite("suite");
QueueAttr q1("q1", {"s1", "s2", "s3"});
s->add_queue(q1);
QueueAttr& q1_ref = s->findQueue("q1");
BOOST_REQUIRE_MESSAGE(!q1_ref.empty(), "queue not found");
BOOST_CHECK_MESSAGE(q1_ref.index_or_value() == 0, "Expected to 0 index but found " << q1_ref.index_or_value());
BOOST_CHECK_MESSAGE(q1_ref.value() == "s1", "Expected to s1 but found " << q1_ref.value());
family_ptr f = s->add_family("f");
QueueAttr q2("q2", {"f1", "f2", "f3"});
f->add_queue(q2);
QueueAttr& q2_ref = f->findQueue("q2");
BOOST_REQUIRE_MESSAGE(!q2_ref.empty(), "queue not found");
BOOST_CHECK_MESSAGE(q2_ref.index_or_value() == 0, "Expected to 0 index but found " << q2_ref.index_or_value());
BOOST_CHECK_MESSAGE(q2_ref.value() == "f1", "Expected to f1 but found " << q2_ref.value());
task_ptr t = f->add_task("t");
QueueAttr q3("q3", {"t1", "t2", "t3"});
t->add_queue(q3);
QueueAttr& q3_ref = t->findQueue("q3");
BOOST_REQUIRE_MESSAGE(!q3_ref.empty(), "queue not found");
BOOST_CHECK_MESSAGE(q3_ref.index_or_value() == 0, "Expected to 0 index but found " << q3_ref.index_or_value());
BOOST_CHECK_MESSAGE(q3_ref.value() == "t1", "Expected to t1 but found " << q3_ref.value());
// cout << defs;
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Update q1, this on the suite. hence we should find it up the hierarchy
std::string step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q1",
"active")));
BOOST_CHECK_MESSAGE(step == "s1", "Expected step s1 but found " << step);
BOOST_CHECK_MESSAGE(NState::ACTIVE == q1_ref.state(step),
"Expected ACTIVE step but found " << NState::toString(q1_ref.state(step)));
q1_ref.aborted(step);
BOOST_CHECK_MESSAGE(NState::ABORTED == q1_ref.state(step),
"Expected ABORTED step but found " << NState::toString(q1_ref.state(step)));
q1_ref.complete(step);
BOOST_CHECK_MESSAGE(NState::COMPLETE == q1_ref.state(step),
"Expected COMPLETE step but found " << NState::toString(q1_ref.state(step)));
BOOST_CHECK_MESSAGE(q1_ref.index_or_value() == 1, "Expected 1 for index but found " << q1_ref.index_or_value());
BOOST_CHECK_MESSAGE(q1_ref.value() == "s2", "Expected s2 for value but found " << q1_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q1",
"active")));
BOOST_CHECK_MESSAGE(step == "s2", "Expected step s2 but found " << step);
BOOST_CHECK_MESSAGE(NState::ACTIVE == q1_ref.state(step),
"Expected ACTIVE step but found " << NState::toString(q1_ref.state(step)));
q1_ref.aborted(step);
BOOST_CHECK_MESSAGE(NState::ABORTED == q1_ref.state(step),
"Expected ABORTED step but found " << NState::toString(q1_ref.state(step)));
BOOST_CHECK_MESSAGE(q1_ref.no_of_aborted() == "1", "Expected 1 aborted step but found " << q1_ref.no_of_aborted());
q1_ref.complete(step);
BOOST_CHECK_MESSAGE(q1_ref.no_of_aborted() == "",
"Expected *NO* aborted step but found " << q1_ref.no_of_aborted());
BOOST_CHECK_MESSAGE(q1_ref.index_or_value() == 2, "Expected 2 for index but found " << q1_ref.index_or_value());
BOOST_CHECK_MESSAGE(q1_ref.value() == "s3", "Expected to s3 but found " << q1_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q1",
"active")));
BOOST_CHECK_MESSAGE(step == "s3", "Expected step s3 but found " << step);
BOOST_CHECK_MESSAGE(NState::ACTIVE == q1_ref.state(step),
"Expected ACTIVE step but found " << NState::toString(q1_ref.state(step)));
q1_ref.aborted(step);
BOOST_CHECK_MESSAGE(NState::ABORTED == q1_ref.state(step),
"Expected ABORTED step but found " << NState::toString(q1_ref.state(step)));
q1_ref.complete(step);
BOOST_CHECK_MESSAGE(q1_ref.index_or_value() == 3, "Expected 3 for index but found " << q1_ref.index_or_value());
BOOST_CHECK_MESSAGE(q1_ref.value() == "<NULL>", "Expected to <NULL> but found " << q1_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q1",
"active")),
false);
BOOST_CHECK_MESSAGE(step == "<NULL>", "Expected step <NULL> but found " << step);
BOOST_CHECK_MESSAGE(q1_ref.index_or_value() == 3, "Expected 3 for index but found " << q1_ref.index_or_value());
BOOST_CHECK_MESSAGE(q1_ref.value() == "<NULL>", "Expected to <NULL> but found " << q1_ref.value());
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Update q2, this on the family, In this we sill specify path to the queue
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q2",
"active",
"",
"/suite/f")));
BOOST_CHECK_MESSAGE(step == "f1", "Expected step f1 but found " << step);
BOOST_CHECK_MESSAGE(q2_ref.index_or_value() == 1, "Expected 1 for index but found " << q2_ref.index_or_value());
BOOST_CHECK_MESSAGE(q2_ref.value() == "f2", "Expected to f2 but found " << q2_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q2",
"active",
"",
"/suite/f")));
BOOST_CHECK_MESSAGE(step == "f2", "Expected step f2 but found " << step);
BOOST_CHECK_MESSAGE(q2_ref.index_or_value() == 2, "Expected 2 for index but found " << q2_ref.index_or_value());
BOOST_CHECK_MESSAGE(q2_ref.value() == "f3", "Expected to f3 but found " << q2_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q2",
"active",
"",
"/suite/f")));
BOOST_CHECK_MESSAGE(step == "f3", "Expected step f3 but found " << step);
BOOST_CHECK_MESSAGE(q2_ref.index_or_value() == 3, "Expected 3 for index but found " << q2_ref.index_or_value());
BOOST_CHECK_MESSAGE(q2_ref.value() == "<NULL>", "Expected to <NULL> but found " << q2_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q2",
"active",
"",
"/suite/f")),
false);
BOOST_CHECK_MESSAGE(q2_ref.index_or_value() == 3, "Expected 3 for index but found " << q2_ref.index_or_value());
BOOST_CHECK_MESSAGE(q2_ref.value() == "<NULL>", "Expected to <NULL> but found " << q2_ref.value());
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Update q3, this on the task
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q3",
"active")));
BOOST_CHECK_MESSAGE(step == "t1", "Expected step t1 but found " << step);
BOOST_CHECK_MESSAGE(q3_ref.index_or_value() == 1, "Expected 1 for index but found " << q3_ref.index_or_value());
BOOST_CHECK_MESSAGE(q3_ref.value() == "t2", "Expected to t2 but found " << q3_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q3",
"active")));
BOOST_CHECK_MESSAGE(step == "t2", "Expected step t2 but found " << step);
BOOST_CHECK_MESSAGE(q3_ref.index_or_value() == 2, "Expected 2 for index but found " << q3_ref.index_or_value());
BOOST_CHECK_MESSAGE(q3_ref.value() == "t3", "Expected to t3 but found " << q3_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q3",
"active")));
BOOST_CHECK_MESSAGE(step == "t3", "Expected step t3 but found " << step);
BOOST_CHECK_MESSAGE(q3_ref.index_or_value() == 3, "Expected 3 for index but found " << q3_ref.index_or_value());
BOOST_CHECK_MESSAGE(q3_ref.value() == "<NULL>", "Expected to <NULL> but found " << q3_ref.value());
step = TestHelper::invokeRequest(&defs,
Cmd_ptr(new QueueCmd(suite_f_t,
Submittable::DUMMY_JOBS_PASSWORD(),
Submittable::DUMMY_PROCESS_OR_REMOTE_ID(),
1,
"q3",
"active")),
false);
BOOST_CHECK_MESSAGE(step == "<NULL>", "Expected step <NULL> but found " << step);
BOOST_CHECK_MESSAGE(q3_ref.index_or_value() == 3, "Expected 3 for index but found " << q3_ref.index_or_value());
BOOST_CHECK_MESSAGE(q3_ref.value() == "<NULL>", "Expected to <NULL> but found " << q3_ref.value());
/// Destroy System singleton to avoid valgrind from complaining
System::destroy();
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|