TEST(TopologyConfigHelper, GetAndSetTopologyConfig) { heron::proto::api::Topology* test_topology = GenerateDummyTopology( "test_topology", "123", 3, NUM_SPOUT_INSTANCES, 3, NUM_BOLT_INSTANCES, heron::proto::api::SHUFFLE); // Test init config std::map<std::string, std::string> old_config; heron::config::TopologyConfigHelper::GetTopologyConfig(*test_topology, old_config); EXPECT_EQ(old_config[heron::config::TopologyConfigVars::TOPOLOGY_MESSAGE_TIMEOUT_SECS], MESSAGE_TIMEOUT); EXPECT_EQ(old_config[TOPOLOGY_USER_CONFIG], TOPOLOGY_USER_CONFIG_VALUE); // Set and then test updated config std::string runtime_user_config_key = TOPOLOGY_USER_CONFIG + ":runtime"; std::map<std::string, std::string> update; update[runtime_user_config_key] = NEW_TOPOLOGY_USER_CONFIG_VALUE; heron::config::TopologyConfigHelper::SetTopologyConfig(test_topology, update); std::map<std::string, std::string> updated_config; heron::config::TopologyConfigHelper::GetTopologyConfig(*test_topology, updated_config); EXPECT_EQ(updated_config[heron::config::TopologyConfigVars::TOPOLOGY_MESSAGE_TIMEOUT_SECS], MESSAGE_TIMEOUT); EXPECT_EQ(updated_config[TOPOLOGY_USER_CONFIG], TOPOLOGY_USER_CONFIG_VALUE); EXPECT_EQ(updated_config[runtime_user_config_key], NEW_TOPOLOGY_USER_CONFIG_VALUE); update[runtime_user_config_key] = NEW_TOPOLOGY_USER_CONFIG_VALUE_2; heron::config::TopologyConfigHelper::SetTopologyConfig(test_topology, update); updated_config.clear(); heron::config::TopologyConfigHelper::GetTopologyConfig(*test_topology, updated_config); EXPECT_EQ(updated_config[TOPOLOGY_USER_CONFIG], TOPOLOGY_USER_CONFIG_VALUE); EXPECT_EQ(updated_config[runtime_user_config_key], NEW_TOPOLOGY_USER_CONFIG_VALUE_2); }
void StartDummyTMaster(CommonResources& common) { // Generate a dummy topology common.topology_ = GenerateDummyTopology( common.topology_name_, common.topology_id_, common.num_spouts_, common.num_spout_instances_, common.num_bolts_, common.num_bolt_instances_, common.grouping_); // Populate the list of stmgrs for (int i = 0; i < common.num_stmgrs_; ++i) { sp_string id = STMGR_NAME; id += std::to_string(i); common.stmgrs_id_list_.push_back(id); } // Start the tmaster EventLoopImpl* tmaster_eventloop; StartDummyTMaster(tmaster_eventloop, common.tmaster_, common.tmaster_thread_, common.tmaster_port_); common.ss_list_.push_back(tmaster_eventloop); common.tmaster_piper_ = new Piper(tmaster_eventloop); }
void StartTMaster(CommonResources& common) { // Generate a dummy topology common.topology_ = GenerateDummyTopology( common.topology_name_, common.topology_id_, common.num_spouts_, common.num_spout_instances_, common.num_bolts_, common.num_bolt_instances_, common.grouping_); // Create the zk state on the local file system common.dpath_ = CreateLocalStateOnFS(common.topology_); // Poulate the list of stmgrs for (int i = 0; i < common.num_stmgrs_; ++i) { sp_string id = STMGR_NAME; id += std::to_string(i); common.stmgrs_id_list_.push_back(id); } // Start the tmaster EventLoopImpl* tmaster_eventLoop; StartTMaster(tmaster_eventLoop, common.tmaster_, common.tmaster_thread_, common.zkhostportlist_, common.topology_name_, common.topology_id_, common.dpath_, common.stmgrs_id_list_, common.tmaster_port_, common.tmaster_controller_port_); common.ss_list_.push_back(tmaster_eventLoop); }
TEST(TopologyConfigHelper, GetAndSetComponentConfig) { heron::proto::api::Topology* test_topology = GenerateDummyTopology( "test_topology", "123", 3, NUM_SPOUT_INSTANCES, 3, NUM_BOLT_INSTANCES, heron::proto::api::SHUFFLE); std::string test_spout = "test_spout1"; std::string non_test_spout = "test_spout2"; std::string test_bolt = "test_bolt2"; std::string non_test_bolt = "test_bolt1"; // Test init config std::map<std::string, std::string> old_config; heron::config::TopologyConfigHelper::GetComponentConfig(*test_topology, test_spout, old_config); EXPECT_EQ(old_config[heron::config::TopologyConfigVars::TOPOLOGY_COMPONENT_PARALLELISM], std::to_string(NUM_SPOUT_INSTANCES)); EXPECT_EQ(old_config[SPOUT_USER_CONFIG], SPOUT_USER_CONFIG_VALUE); old_config.clear(); heron::config::TopologyConfigHelper::GetComponentConfig(*test_topology, test_bolt, old_config); EXPECT_EQ(old_config[heron::config::TopologyConfigVars::TOPOLOGY_COMPONENT_PARALLELISM], std::to_string(NUM_BOLT_INSTANCES)); EXPECT_EQ(old_config[BOLT_USER_CONFIG], BOLT_USER_CONFIG_VALUE); // Set user configs to new values std::string runtime_spout_user_config_key = SPOUT_USER_CONFIG + ":runtime"; std::string runtime_bolt_user_config_key = BOLT_USER_CONFIG + ":runtime"; std::map<std::string, std::string> update; update[runtime_spout_user_config_key] = NEW_SPOUT_USER_CONFIG_VALUE; heron::config::TopologyConfigHelper::SetComponentConfig(test_topology, test_spout, update); update.clear(); update[runtime_bolt_user_config_key] = NEW_BOLT_USER_CONFIG_VALUE; heron::config::TopologyConfigHelper::SetComponentConfig(test_topology, test_bolt, update); // Test user configs are updated std::map<std::string, std::string> updated_config; heron::config::TopologyConfigHelper::GetComponentConfig( *test_topology, test_spout, updated_config); EXPECT_EQ(updated_config[heron::config::TopologyConfigVars::TOPOLOGY_COMPONENT_PARALLELISM], std::to_string(NUM_SPOUT_INSTANCES)); EXPECT_EQ(updated_config[SPOUT_USER_CONFIG], SPOUT_USER_CONFIG_VALUE); EXPECT_EQ(updated_config[runtime_spout_user_config_key], NEW_SPOUT_USER_CONFIG_VALUE); updated_config.clear(); heron::config::TopologyConfigHelper::GetComponentConfig( *test_topology, test_bolt, updated_config); EXPECT_EQ(updated_config[heron::config::TopologyConfigVars::TOPOLOGY_COMPONENT_PARALLELISM], std::to_string(NUM_BOLT_INSTANCES)); EXPECT_EQ(updated_config[BOLT_USER_CONFIG], BOLT_USER_CONFIG_VALUE); EXPECT_EQ(updated_config[runtime_bolt_user_config_key], NEW_BOLT_USER_CONFIG_VALUE); // Set to new value 2 and verify update.clear(); update[runtime_spout_user_config_key] = NEW_SPOUT_USER_CONFIG_VALUE_2; heron::config::TopologyConfigHelper::SetComponentConfig(test_topology, test_spout, update); update.clear(); update[runtime_bolt_user_config_key] = NEW_BOLT_USER_CONFIG_VALUE_2; heron::config::TopologyConfigHelper::SetComponentConfig(test_topology, test_bolt, update); // Test user configs are updated updated_config.clear(); heron::config::TopologyConfigHelper::GetComponentConfig( *test_topology, test_spout, updated_config); EXPECT_EQ(updated_config[heron::config::TopologyConfigVars::TOPOLOGY_COMPONENT_PARALLELISM], std::to_string(NUM_SPOUT_INSTANCES)); EXPECT_EQ(updated_config[SPOUT_USER_CONFIG], SPOUT_USER_CONFIG_VALUE); EXPECT_EQ(updated_config[runtime_spout_user_config_key], NEW_SPOUT_USER_CONFIG_VALUE_2); updated_config.clear(); heron::config::TopologyConfigHelper::GetComponentConfig( *test_topology, test_bolt, updated_config); EXPECT_EQ(updated_config[heron::config::TopologyConfigVars::TOPOLOGY_COMPONENT_PARALLELISM], std::to_string(NUM_BOLT_INSTANCES)); EXPECT_EQ(updated_config[BOLT_USER_CONFIG], BOLT_USER_CONFIG_VALUE); EXPECT_EQ(updated_config[runtime_bolt_user_config_key], NEW_BOLT_USER_CONFIG_VALUE_2); }