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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
/*
* 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 <boost/test/unit_test.hpp>
#include "TestUtil.hpp"
#include "ecflow/attribute/AutoCancelAttr.hpp"
#include "ecflow/core/Filesystem.hpp"
#include "ecflow/node/Defs.hpp"
#include "ecflow/node/Family.hpp"
#include "ecflow/node/Suite.hpp"
#include "ecflow/node/Task.hpp"
#include "ecflow/node/formatter/DefsWriter.hpp"
#include "ecflow/simulator/Simulator.hpp"
using namespace ecf;
/// Simulate definition files that are created on then fly. This us to validate
/// Defs file, to check for correctness
BOOST_AUTO_TEST_SUITE(S_Simulator)
BOOST_AUTO_TEST_SUITE(T_AutoCancel)
BOOST_AUTO_TEST_CASE(test_autocancel_ast_node_reset) {
std::cout << "Simulator:: ...test_autocancel_ast_node_reset\n";
// ****: Since we have no time dependencies the simulator calendar increment
// ****: is in hours. Hence autocancel at hour resolution
Defs theDefs;
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("s1");
suite->addClock(clockAttr);
family_ptr fam = suite->add_family("family");
task_ptr task = fam->add_task("t");
task->add_trigger("/s2/family/t == complete");
task_ptr task2 = fam->add_task("t2");
task2->add_trigger("/s3/family/t == complete");
task2->add_complete("/s2/family == complete");
task_ptr task3 = fam->add_task("t3");
task3->add_trigger("/s3 == complete");
task3->add_complete("/s2 == complete");
}
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("s2");
suite->addClock(clockAttr);
suite->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(1, 0), false));
family_ptr fam = suite->add_family("family");
fam->add_task("t");
}
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("s3");
suite->addClock(clockAttr);
suite->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(1, 0), false));
family_ptr fam = suite->add_family("family");
fam->add_task("t");
}
// Check number of AST nodes. The AST should be created on the fly
std::set<Node*> theSet;
theDefs.getAllAstNodes(theSet);
BOOST_CHECK_MESSAGE(theSet.size() == 5,
"Expected to have 5 AST nodes in trigger/complete expressions but found " << theSet.size());
// Run the simulator
Simulator simulator;
std::string errorMsg;
BOOST_CHECK_MESSAGE(simulator.run(theDefs, findTestDataLocation("test_autocancel_ast_node_reset.def"), errorMsg),
errorMsg);
// Auto cancel should delete suite s2 and s3, leaving one suite i.e s1
BOOST_CHECK_MESSAGE(theDefs.suiteVec().size() == 1,
"Expected to have 1 suites but found " << theDefs.suiteVec().size());
// The references to nodes in suites s2, s3 should have been cleared in suite s1
{
std::set<Node*> theSet;
theDefs.getAllAstNodes(theSet);
BOOST_CHECK_MESSAGE(theSet.empty(),
"Expected to have 0 AST nodes in trigger/complete expressions but found " << theSet.size());
}
// remove generated log file. Comment out to debug
std::string logFileName = findTestDataLocation("test_autocancel_ast_node_reset.def") + ".log";
fs::remove(logFileName);
}
BOOST_AUTO_TEST_CASE(test_autocancel_suite) {
std::cout << "Simulator:: ...test_autocancel_suite\n";
// ****: Since we have no time dependencies the simulator calendar increment
// ****: is in hours. Hence autocancel at hour resolution
Defs theDefs;
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_autocancel_10_hours_relative");
suite->addClock(clockAttr);
suite->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(10, 0), true));
family_ptr fam = suite->add_family("family");
fam->add_task("t");
}
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_autocancel_1_hours_real");
suite->addClock(clockAttr);
suite->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(1, 0), false));
family_ptr fam = suite->add_family("family");
fam->add_task("t");
}
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_autocancel_1_day_relative");
suite->addClock(clockAttr);
suite->addAutoCancel(ecf::AutoCancelAttr(1));
family_ptr fam = suite->add_family("family");
fam->add_task("t");
}
Simulator simulator;
std::string errorMsg;
BOOST_CHECK_MESSAGE(simulator.run(theDefs, findTestDataLocation("test_autocancel_suite.def"), errorMsg), errorMsg);
// make sure autocancel deletes the suite.
BOOST_CHECK_MESSAGE(theDefs.suiteVec().size() == 0,
"Expected to have 0 suites but found " << theDefs.suiteVec().size());
// remove generated log file. Comment out to debug
std::string logFileName = findTestDataLocation("test_autocancel_suite.def") + ".log";
fs::remove(logFileName);
}
BOOST_AUTO_TEST_CASE(test_autocancel_family_and_task) {
std::cout << "Simulator:: ...test_autocancel_family_and_task\n";
// ****: Since we have no time dependencies the simulator calendar increment
// ****: is in hours. Hence autocancel at hour resolution
Defs theDefs;
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_autocancel_9_10_hours_relative");
suite->addClock(clockAttr);
family_ptr fam = suite->add_family("family");
fam->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(10, 0), true));
task_ptr task = fam->add_task("t");
task->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(9, 0), true));
}
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_autocancel_1_2_hours_real");
suite->addClock(clockAttr);
family_ptr fam = suite->add_family("family");
fam->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(2, 0), false));
task_ptr task = fam->add_task("t");
task->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(1, 0), false));
}
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
ClockAttr end_clock(true);
end_clock.date(14, 10, 2009); // 14 October 2009 was a Wednesday
suite_ptr suite = theDefs.add_suite("test_autocancel_1_2_day_relative");
suite->addClock(clockAttr);
suite->add_end_clock(end_clock);
family_ptr fam = suite->add_family("family");
fam->addAutoCancel(ecf::AutoCancelAttr(2)); // 2 days
task_ptr task = fam->add_task("t");
task->addAutoCancel(ecf::AutoCancelAttr(1)); // 1 days
}
// cout << theDefs << "\n";
Simulator simulator;
std::string errorMsg;
BOOST_CHECK_MESSAGE(simulator.run(theDefs, findTestDataLocation("test_autocancel_family_and_task.def"), errorMsg),
errorMsg);
// make sure autocancel deletes the families.
std::vector<Family*> famVec;
theDefs.getAllFamilies(famVec);
BOOST_CHECK_MESSAGE(famVec.size() == 0,
"Expected to have 0 families but found " << famVec.size() << "\n"
<< ecf::as_string(theDefs, PrintStyle::DEFS));
// remove generated log file. Comment out to debug
std::string logFileName = findTestDataLocation("test_autocancel_family_and_task.def") + ".log";
fs::remove(logFileName);
}
BOOST_AUTO_TEST_CASE(test_autocancel_task) {
std::cout << "Simulator:: ...test_autocancel_task\n";
// ****: Since we have no time dependencies the simulator calendar increment
// ****: is in hours. Hence autocancel at hour resolution
Defs theDefs;
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_autocancel_10_hours_relative");
suite->addClock(clockAttr);
family_ptr fam = suite->add_family("family");
task_ptr task = fam->add_task("t");
task->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(10, 0), true));
}
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_autocancel_1_hours_real");
suite->addClock(clockAttr);
family_ptr fam = suite->add_family("family");
task_ptr task = fam->add_task("t");
task->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(1, 0), false));
}
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_autocancel_1_day_relative");
suite->addClock(clockAttr);
family_ptr fam = suite->add_family("family");
task_ptr task = fam->add_task("t");
task->addAutoCancel(ecf::AutoCancelAttr(1));
}
Simulator simulator;
std::string errorMsg;
BOOST_CHECK_MESSAGE(simulator.run(theDefs, findTestDataLocation("test_autocancel_task.def"), errorMsg), errorMsg);
// make sure autocancel deletes the tasks and leaves families intact.
std::vector<task_ptr> task_vec;
theDefs.get_all_tasks(task_vec);
std::vector<Family*> famVec;
theDefs.getAllFamilies(famVec);
BOOST_CHECK_MESSAGE(famVec.size() == 3, "Expected to have 3 families but found " << famVec.size());
BOOST_CHECK_MESSAGE(task_vec.size() == 0, "Expected to have 0 tasks but found " << task_vec.size());
// remove generated log file. Comment out to debug
std::string logFileName = findTestDataLocation("test_autocancel_task.def") + ".log";
fs::remove(logFileName);
}
BOOST_AUTO_TEST_CASE(test_two_autocancel_in_hierarchy) {
std::cout << "Simulator:: ...test_two_autocancel_in_hierarchy\n"; // ECFLOW-556
// ****: Since we have no time dependencies the simulator calendar increment
// ****: is in hours. Hence autocancel at hour resolution
Defs theDefs;
{
ClockAttr clockAttr(true);
clockAttr.date(12, 10, 2009); // 12 October 2009 was a Monday
suite_ptr suite = theDefs.add_suite("test_two_autocancel_in_hierarchy");
suite->addClock(clockAttr);
family_ptr fam = suite->add_family("family");
fam->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(1, 0), true));
task_ptr task = fam->add_task("t");
task->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(1, 0), true));
}
Simulator simulator;
std::string errorMsg;
BOOST_CHECK_MESSAGE(simulator.run(theDefs, findTestDataLocation("test_two_autocancel_in_hierarchy.def"), errorMsg),
errorMsg);
std::vector<task_ptr> task_vec;
theDefs.get_all_tasks(task_vec);
std::vector<Family*> famVec;
theDefs.getAllFamilies(famVec);
BOOST_CHECK_MESSAGE(famVec.size() == 0, "Expected to have 0 families but found " << famVec.size());
BOOST_CHECK_MESSAGE(task_vec.size() == 0, "Expected to have 0 tasks but found " << task_vec.size());
// remove generated log file. Comment out to debug
std::string logFileName = findTestDataLocation("test_two_autocancel_in_hierarchy.def") + ".log";
fs::remove(logFileName);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|