Move CreateTableForTesting into registration-test This utility function was only used in one spot, so moving it out of the header.
Change-Id: Id72a37b2dee05db65f27c27d52b0f18dd5c489f2 Reviewed-on: http://gerrit.cloudera.org:8080/6961 Reviewed-by: Alexey Serbin <[email protected]> Tested-by: Kudu Jenkins Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/3b934aeb Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/3b934aeb Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/3b934aeb Branch: refs/heads/master Commit: 3b934aeb240059907f113127072b04db05f9c880 Parents: 7f91a11 Author: Todd Lipcon <[email protected]> Authored: Mon May 22 19:19:08 2017 -0700 Committer: Todd Lipcon <[email protected]> Committed: Wed May 31 19:59:26 2017 +0000 ---------------------------------------------------------------------- src/kudu/integration-tests/registration-test.cc | 69 ++++++++++++++++++++ src/kudu/master/master-test-util.h | 59 ----------------- 2 files changed, 69 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/3b934aeb/src/kudu/integration-tests/registration-test.cc ---------------------------------------------------------------------- diff --git a/src/kudu/integration-tests/registration-test.cc b/src/kudu/integration-tests/registration-test.cc index 6492adf..a478616 100644 --- a/src/kudu/integration-tests/registration-test.cc +++ b/src/kudu/integration-tests/registration-test.cc @@ -56,11 +56,80 @@ namespace kudu { using std::vector; using std::shared_ptr; using std::string; + +using master::CatalogManager; +using master::CreateTableRequestPB; +using master::CreateTableResponsePB; +using master::GetTableLocationsResponsePB; +using master::GetTableSchemaRequestPB; +using master::GetTableSchemaResponsePB; +using master::IsCreateTableDoneRequestPB; +using master::IsCreateTableDoneResponsePB; using master::MiniMaster; using master::TSDescriptor; using master::TabletLocationsPB; using tserver::MiniTabletServer; +void CreateTableForTesting(MiniMaster* mini_master, + const string& table_name, + const Schema& schema, + string *tablet_id) { + { + CreateTableRequestPB req; + CreateTableResponsePB resp; + + req.set_name(table_name); + req.set_num_replicas(1); + ASSERT_OK(SchemaToPB(schema, req.mutable_schema())); + CatalogManager* catalog = mini_master->master()->catalog_manager(); + CatalogManager::ScopedLeaderSharedLock l(catalog); + ASSERT_OK(l.first_failed_status()); + ASSERT_OK(catalog->CreateTable(&req, &resp, NULL)); + } + + int wait_time = 1000; + bool is_table_created = false; + for (int i = 0; i < 80; ++i) { + IsCreateTableDoneRequestPB req; + IsCreateTableDoneResponsePB resp; + + req.mutable_table()->set_table_name(table_name); + CatalogManager* catalog = mini_master->master()->catalog_manager(); + { + CatalogManager::ScopedLeaderSharedLock l(catalog); + ASSERT_OK(l.first_failed_status()); + ASSERT_OK(catalog->IsCreateTableDone(&req, &resp)); + } + if (resp.done()) { + is_table_created = true; + break; + } + + VLOG(1) << "Waiting for table '" << table_name << "'to be created"; + + SleepFor(MonoDelta::FromMicroseconds(wait_time)); + wait_time = std::min(wait_time * 5 / 4, 1000000); + } + ASSERT_TRUE(is_table_created); + + { + GetTableSchemaRequestPB req; + GetTableSchemaResponsePB resp; + req.mutable_table()->set_table_name(table_name); + CatalogManager* catalog = mini_master->master()->catalog_manager(); + CatalogManager::ScopedLeaderSharedLock l(catalog); + ASSERT_OK(l.first_failed_status()); + ASSERT_OK(catalog->GetTableSchema(&req, &resp)); + ASSERT_TRUE(resp.create_table_done()); + } + + GetTableLocationsResponsePB resp; + ASSERT_OK(WaitForRunningTabletCount(mini_master, table_name, 1, &resp)); + *tablet_id = resp.tablet_locations(0).tablet_id(); + LOG(INFO) << "Got tablet " << *tablet_id << " for table " << table_name; +} + + // Tests for the Tablet Server registering with the Master, // and the master maintaining the tablet descriptor. class RegistrationTest : public KuduTest { http://git-wip-us.apache.org/repos/asf/kudu/blob/3b934aeb/src/kudu/master/master-test-util.h ---------------------------------------------------------------------- diff --git a/src/kudu/master/master-test-util.h b/src/kudu/master/master-test-util.h index 44a2874..7e7f021 100644 --- a/src/kudu/master/master-test-util.h +++ b/src/kudu/master/master-test-util.h @@ -68,65 +68,6 @@ Status WaitForRunningTabletCount(MiniMaster* mini_master, return Status::RuntimeError("Unreachable statement"); // Suppress compiler warnings. } -void CreateTableForTesting(MiniMaster* mini_master, - const string& table_name, - const Schema& schema, - string *tablet_id) { - { - CreateTableRequestPB req; - CreateTableResponsePB resp; - - req.set_name(table_name); - req.set_num_replicas(1); - ASSERT_OK(SchemaToPB(schema, req.mutable_schema())); - CatalogManager* catalog = mini_master->master()->catalog_manager(); - CatalogManager::ScopedLeaderSharedLock l(catalog); - ASSERT_OK(l.first_failed_status()); - ASSERT_OK(catalog->CreateTable(&req, &resp, NULL)); - } - - int wait_time = 1000; - bool is_table_created = false; - for (int i = 0; i < 80; ++i) { - IsCreateTableDoneRequestPB req; - IsCreateTableDoneResponsePB resp; - - req.mutable_table()->set_table_name(table_name); - CatalogManager* catalog = mini_master->master()->catalog_manager(); - { - CatalogManager::ScopedLeaderSharedLock l(catalog); - ASSERT_OK(l.first_failed_status()); - ASSERT_OK(catalog->IsCreateTableDone(&req, &resp)); - } - if (resp.done()) { - is_table_created = true; - break; - } - - VLOG(1) << "Waiting for table '" << table_name << "'to be created"; - - SleepFor(MonoDelta::FromMicroseconds(wait_time)); - wait_time = std::min(wait_time * 5 / 4, 1000000); - } - ASSERT_TRUE(is_table_created); - - { - GetTableSchemaRequestPB req; - GetTableSchemaResponsePB resp; - req.mutable_table()->set_table_name(table_name); - CatalogManager* catalog = mini_master->master()->catalog_manager(); - CatalogManager::ScopedLeaderSharedLock l(catalog); - ASSERT_OK(l.first_failed_status()); - ASSERT_OK(catalog->GetTableSchema(&req, &resp)); - ASSERT_TRUE(resp.create_table_done()); - } - - GetTableLocationsResponsePB resp; - ASSERT_OK(WaitForRunningTabletCount(mini_master, table_name, 1, &resp)); - *tablet_id = resp.tablet_locations(0).tablet_id(); - LOG(INFO) << "Got tablet " << *tablet_id << " for table " << table_name; -} - } // namespace master } // namespace kudu
