1#include "TestStopConditions.h"
2
3namespace DB
4{
5
6void TestStopConditions::loadFromConfig(ConfigurationPtr & stop_conditions_config)
7{
8 if (stop_conditions_config->has("all_of"))
9 {
10 ConfigurationPtr config_all_of(stop_conditions_config->createView("all_of"));
11 conditions_all_of.loadFromConfig(config_all_of);
12 }
13 if (stop_conditions_config->has("any_of"))
14 {
15 ConfigurationPtr config_any_of(stop_conditions_config->createView("any_of"));
16 conditions_any_of.loadFromConfig(config_any_of);
17 }
18}
19
20bool TestStopConditions::areFulfilled() const
21{
22 return (conditions_all_of.initialized_count && conditions_all_of.fulfilled_count >= conditions_all_of.initialized_count)
23 || (conditions_any_of.initialized_count && conditions_any_of.fulfilled_count);
24}
25
26UInt64 TestStopConditions::getMaxExecTime() const
27{
28 UInt64 all_of_time = conditions_all_of.total_time_ms.value;
29 if (all_of_time == 0 && conditions_all_of.initialized_count != 0) /// max time is not set in all conditions
30 return 0;
31 else if(all_of_time != 0 && conditions_all_of.initialized_count > 1) /// max time is set, but we have other conditions
32 return 0;
33
34 UInt64 any_of_time = conditions_any_of.total_time_ms.value;
35 return std::max(all_of_time, any_of_time);
36}
37
38}
39