Repository: incubator-hawq
Updated Branches:
  refs/heads/master c8319dedb -> b5c77addd


HAWQ-1044. Add some error path test case for hawq 
register(TestUsage2Case1ErrorHashTableRegistry, TestUsage2Case1LargerEof, 
TestUsage2Case1WrongDistributionPolicy)


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/b5c77add
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/b5c77add
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/b5c77add

Branch: refs/heads/master
Commit: b5c77addd51236242de1561fbf519be7d1c1b05b
Parents: 01c740d
Author: Chunling Wang <wangchunlin...@126.com>
Authored: Wed Sep 21 16:32:38 2016 +0800
Committer: Chunling Wang <wangchunlin...@126.com>
Committed: Wed Sep 21 16:32:54 2016 +0800

----------------------------------------------------------------------
 .../feature/ManagementTool/test_hawq_register.h |  31 ++++++
 .../test_hawq_register_usage2_case1.cpp         | 100 +++++++++++++++++++
 .../test_hawq_register_usage2_case2.cpp         |   5 +
 .../test_hawq_register_usage2_case3.cpp         |   5 +
 .../usage2case1/larger_eof_tpl.yml              |  21 ++++
 .../wrong_distributed_policy_tpl.yml            |  21 ++++
 6 files changed, 183 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b5c77add/src/test/feature/ManagementTool/test_hawq_register.h
----------------------------------------------------------------------
diff --git a/src/test/feature/ManagementTool/test_hawq_register.h 
b/src/test/feature/ManagementTool/test_hawq_register.h
index 70a2998..f033f6d 100644
--- a/src/test/feature/ManagementTool/test_hawq_register.h
+++ b/src/test/feature/ManagementTool/test_hawq_register.h
@@ -49,6 +49,37 @@ class TestHawqRegister : public ::testing::Test {
             return "";
         }
 
+        void checkPgAOSegValue(std::string relname, std::string value, 
std::string fmt) {
+            std::string reloid = getTableOid(relname);
+
+            const hawq::test::PSQLQueryResult &result1 = conn->getQueryResult(
+                hawq::test::stringFormat("SELECT tupcount from 
pg_aoseg.pg_%s_%s;", fmt.c_str(), reloid.c_str()));
+            std::vector<std::vector<std::string>> table = result1.getRows();
+            if (table.size() > 0) {
+                for (int i = 0; i < table.size(); i++) {
+                    EXPECT_EQ(table[i][0], value);
+                }
+            }
+
+            const hawq::test::PSQLQueryResult &result2 = conn->getQueryResult(
+                hawq::test::stringFormat("SELECT varblockcount from 
pg_aoseg.pg_%s_%s;", fmt.c_str(), reloid.c_str()));
+            table = result2.getRows();
+            if (table.size() > 0) {
+                for (int i = 0; i < table.size(); i++) {
+                    EXPECT_EQ(table[i][0], value);
+                }
+            }
+
+            const hawq::test::PSQLQueryResult &result3 = conn->getQueryResult(
+                hawq::test::stringFormat("SELECT eofuncompressed from 
pg_aoseg.pg_%s_%s;", fmt.c_str(), reloid.c_str()));
+            table = result3.getRows();
+            if (table.size() > 0) {
+                for (int i = 0; i < table.size(); i++) {
+                    EXPECT_EQ(table[i][0], value);
+                }
+            }
+        }
+
     private:
         std::unique_ptr<hawq::test::PSQL> conn;
 };

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b5c77add/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp
----------------------------------------------------------------------
diff --git 
a/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp 
b/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp
index 44d2d76..6640775 100644
--- a/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp
+++ b/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp
@@ -54,6 +54,9 @@ TEST_F(TestHawqRegister, TestUsage2Case1Expected) {
 TEST_F(TestHawqRegister, TestUsage2Case1ErrorEncoding) {
     SQLUtility util;
     string test_root(util.getTestRootPath());
+    util.execute("drop table if exists t;");
+    util.execute("drop table if exists nt;");
+    
     util.execute("create table t(i int) with (appendonly=true, 
orientation=row) distributed randomly;");
     util.execute("insert into t select generate_series(1, 100);");
     util.query("select * from t;", 100);
@@ -77,6 +80,9 @@ TEST_F(TestHawqRegister, TestUsage2Case1ErrorEncoding) {
 TEST_F(TestHawqRegister, TestUsage2Case1Bucket0) {
     SQLUtility util;
     string test_root(util.getTestRootPath());
+    util.execute("drop table if exists t;");
+    util.execute("drop table if exists nt;");
+    
     util.execute("create table t(i int) with (appendonly=true, 
orientation=row) distributed by (i);");
     util.execute("insert into t select generate_series(1, 100);");
     util.query("select * from t;", 100);
@@ -105,3 +111,97 @@ TEST_F(TestHawqRegister, TestUsage2Case1IncludeDirectory) {
     EXPECT_EQ(1, Command::getCommandStatus(hawq::test::stringFormat("hawq 
register -d %s -c %s testhawqregister_testusage2case1includedirectory.nt", 
HAWQ_DB, t_yml.c_str())));
     EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hdfs dfs 
-rm -r %s/usage2case1", getHdfsLocation().c_str())));
 }
+
+TEST_F(TestHawqRegister, TestUsage2Case1ErrorHashTableRegistry) {
+    SQLUtility util;
+    util.execute("drop table if exists t_1_1;");
+    util.execute("drop table if exists t_1_2;");
+    util.execute("drop table if exists t_1_3;");
+    util.execute("drop table if exists t_2;");
+    util.execute("drop table if exists nt_1;");
+    util.execute("drop table if exists nt_2;");
+
+    util.execute("create table t_1_1(i int, j int, k int) with 
(appendonly=true, orientation=row, bucketnum=12) distributed by (i, j);");
+    util.execute("insert into t_1_1 select generate_series(1, 100);");
+    util.query("select * from t_1_1;", 100);
+    util.execute("create table t_1_2(i int, j int, k int) with 
(appendonly=true, orientation=row) distributed by (i);");
+    util.execute("insert into t_1_2 select generate_series(1, 100);");
+    util.query("select * from t_1_2;", 100);
+    util.execute("create table t_1_3(i int, j int, k int) with 
(appendonly=true, orientation=row) distributed randomly;");
+    util.execute("insert into t_1_3 select generate_series(1, 100);");
+    util.query("select * from t_1_3;", 100);
+    util.execute("create table t_2(i int, j int, k int) with (appendonly=true, 
orientation=row) distributed by (i);");
+    util.execute("insert into t_2 select generate_series(1, 100);");
+    util.query("select * from t_2;", 100);
+    util.execute("create table nt_1(i int, j int, k int) with 
(appendonly=true, orientation=row) distributed by (i, j);");
+    util.execute("insert into nt_1 select generate_series(1, 100);");
+    util.query("select * from nt_1;", 100);
+    util.execute("create table nt_2(i int, j int, k int) with 
(appendonly=true, orientation=row) distributed by (j);");
+    util.execute("insert into nt_2 select generate_series(1, 100);");
+    util.query("select * from nt_2;", 100);
+
+    EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq 
extract -d %s -o t_1_1.yml 
testhawqregister_testusage2case1errorhashtableregistry.t_1_1", HAWQ_DB)));
+    EXPECT_EQ(1, Command::getCommandStatus(hawq::test::stringFormat("hawq 
register -d %s -c t_1_1.yml 
testhawqregister_testusage2case1errorhashtableregistry.nt_1", HAWQ_DB)));
+    EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq 
extract -d %s -o t_1_2.yml 
testhawqregister_testusage2case1errorhashtableregistry.t_1_2", HAWQ_DB)));
+    EXPECT_EQ(1, Command::getCommandStatus(hawq::test::stringFormat("hawq 
register -d %s -c t_1_2.yml 
testhawqregister_testusage2case1errorhashtableregistry.nt_1", HAWQ_DB)));
+    EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq 
extract -d %s -o t_1_3.yml 
testhawqregister_testusage2case1errorhashtableregistry.t_1_3", HAWQ_DB)));
+    EXPECT_EQ(1, Command::getCommandStatus(hawq::test::stringFormat("hawq 
register -d %s -c t_1_3.yml 
testhawqregister_testusage2case1errorhashtableregistry.nt_1", HAWQ_DB)));
+    EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq 
extract -d %s -o t_2.yml 
testhawqregister_testusage2case1errorhashtableregistry.t_2", HAWQ_DB)));
+    EXPECT_EQ(1, Command::getCommandStatus(hawq::test::stringFormat("hawq 
register -d %s -c t_2.yml 
testhawqregister_testusage2case1errorhashtableregistry.nt_2", HAWQ_DB)));
+
+    EXPECT_EQ(0, Command::getCommandStatus("rm -rf t_1_1.yml"));
+    EXPECT_EQ(0, Command::getCommandStatus("rm -rf t_1_2.yml"));
+    EXPECT_EQ(0, Command::getCommandStatus("rm -rf t_1_3.yml"));
+    EXPECT_EQ(0, Command::getCommandStatus("rm -rf t_2.yml"));
+    util.execute("drop table t_1_1;");
+    util.execute("drop table t_1_2;");
+    util.execute("drop table t_1_3;");
+    util.execute("drop table t_2;");
+    util.execute("drop table nt_1;");
+    util.execute("drop table nt_2;");
+}
+
+TEST_F(TestHawqRegister, TestUsage2Case1LargerEof) {
+    SQLUtility util;
+    string test_root(util.getTestRootPath());
+    util.execute("drop table if exists t;");
+    util.execute("drop table if exists nt;");
+    
+    util.execute("create table t(i int) with (appendonly=true, 
orientation=row) distributed randomly;");
+    util.execute("insert into t select generate_series(1, 100);");
+    util.query("select * from t;", 100);
+    string 
t_yml(hawq::test::stringFormat("%s/ManagementTool/usage2case1/larger_eof.yml", 
test_root.c_str()));
+    string 
t_yml_tpl(hawq::test::stringFormat("%s/ManagementTool/usage2case1/larger_eof_tpl.yml",
 test_root.c_str()));
+    hawq::test::FileReplace frep;
+    std::unordered_map<std::string, std::string> strs_src_dst;
+    strs_src_dst["@DATABASE_OID@"]= getDatabaseOid();
+    strs_src_dst["@TABLE_OID@"]= getTableOid("t");
+    frep.replace(t_yml_tpl, t_yml, strs_src_dst);
+    EXPECT_EQ(1, Command::getCommandStatus(hawq::test::stringFormat("hawq 
register -d %s -c %s testhawqregister_testusage2case1largereof.nt", HAWQ_DB, 
t_yml.c_str())));
+
+    EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("rm -rf 
%s", t_yml.c_str())));
+    util.execute("drop table t;");
+}
+
+
+TEST_F(TestHawqRegister, TestUsage2Case1WrongDistributionPolicy) {
+    SQLUtility util;
+    string test_root(util.getTestRootPath());
+    util.execute("drop table if exists t;");
+    util.execute("drop table if exists nt;");
+    
+    util.execute("create table t(i int) with (appendonly=true, 
orientation=row) distributed randomly;");
+    util.execute("insert into t select generate_series(1, 100);");
+    util.query("select * from t;", 100);
+    string 
t_yml(hawq::test::stringFormat("%s/ManagementTool/usage2case1/wrong_distributed_policy.yml",
 test_root.c_str()));
+    string 
t_yml_tpl(hawq::test::stringFormat("%s/ManagementTool/usage2case1/wrong_distributed_policy_tpl.yml",
 test_root.c_str()));
+    hawq::test::FileReplace frep;
+    std::unordered_map<std::string, std::string> strs_src_dst;
+    strs_src_dst["@DATABASE_OID@"]= getDatabaseOid();
+    strs_src_dst["@TABLE_OID@"]= getTableOid("t");
+    frep.replace(t_yml_tpl, t_yml, strs_src_dst);
+    EXPECT_EQ(1, Command::getCommandStatus(hawq::test::stringFormat("hawq 
register -d %s -c %s 
testhawqregister_testusage2case1wrongdistributionpolicy.nt", HAWQ_DB, 
t_yml.c_str())));
+
+    EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("rm -rf 
%s", t_yml.c_str())));
+    util.execute("drop table t;");
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b5c77add/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp
----------------------------------------------------------------------
diff --git 
a/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp 
b/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp
index 1d0bb4d..1545315 100644
--- a/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp
+++ b/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp
@@ -61,6 +61,11 @@ TEST_F(TestHawqRegister, TestUsage2Case2Expected) {
                 EXPECT_EQ(0, 
Command::getCommandStatus(hawq::test::stringFormat("hawq register %s -d %s -c 
%s testhawqregister_testusage2case2expected.%s", opt.c_str(), HAWQ_DB, 
t_yml_new.c_str(), nt.c_str())));
                 util.query(hawq::test::stringFormat("select * from %s;", 
nt.c_str()), 150);
 
+                if (fmt == "row")
+                   checkPgAOSegValue(nt, "-1", "aoseg");
+                else 
+                   checkPgAOSegValue(nt, "-1", "paqseg");
+                
                 EXPECT_EQ(0, 
Command::getCommandStatus(hawq::test::stringFormat("rm -rf %s", 
t_yml.c_str())));
                 EXPECT_EQ(0, 
Command::getCommandStatus(hawq::test::stringFormat("rm -rf %s", 
t_yml_new.c_str())));
                 util.execute(hawq::test::stringFormat("drop table %s;", 
t.c_str()));

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b5c77add/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp
----------------------------------------------------------------------
diff --git 
a/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp 
b/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp
index 8037f0f..1d021d3 100644
--- a/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp
+++ b/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp
@@ -61,6 +61,11 @@ TEST_F(TestHawqRegister, TestUsage2Case3Expected) {
                 EXPECT_EQ(0, 
Command::getCommandStatus(hawq::test::stringFormat("hawq register %s -d %s -c 
%s testhawqregister_testusage2case3expected.%s", opt.c_str(), HAWQ_DB, 
t_yml_old.c_str(), nt.c_str())));
                 util.query(hawq::test::stringFormat("select * from %s;", 
nt.c_str()), 100);
 
+                if (fmt == "row")
+                   checkPgAOSegValue(nt, "-1", "aoseg");
+                else 
+                   checkPgAOSegValue(nt, "-1", "paqseg");
+                
                 EXPECT_EQ(0, 
Command::getCommandStatus(hawq::test::stringFormat("rm -rf t_%s.yml", 
std::to_string(suffix).c_str())));
                 EXPECT_EQ(0, 
Command::getCommandStatus(hawq::test::stringFormat("rm -rf %s", 
t_yml_old.c_str())));
                 util.execute(hawq::test::stringFormat("drop table %s;", 
t.c_str()));

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b5c77add/src/test/feature/ManagementTool/usage2case1/larger_eof_tpl.yml
----------------------------------------------------------------------
diff --git a/src/test/feature/ManagementTool/usage2case1/larger_eof_tpl.yml 
b/src/test/feature/ManagementTool/usage2case1/larger_eof_tpl.yml
new file mode 100644
index 0000000..a8f7911
--- /dev/null
+++ b/src/test/feature/ManagementTool/usage2case1/larger_eof_tpl.yml
@@ -0,0 +1,21 @@
+AO_FileLocations:
+  Blocksize: 32768
+  Checksum: false
+  CompressionLevel: 0
+  CompressionType: null
+  Files:
+  - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/1
+    size: 2016
+AO_Schema:
+- name: i
+  type: int4
+Bucketnum: 6
+DBVersion: PostgreSQL 8.2.15 (Greenplum Database 4.2.0 build 1) (HAWQ 2.0.1.0 
build
+  dev) on x86_64-apple-darwin14.5.0, compiled by GCC Apple LLVM version 6.1.0 
(clang-602.0.53)
+  (based on LLVM 3.6.0svn) compiled on Jul  6 2016 10:22:33
+DFS_URL: hdfs://localhost:8020
+Distribution_Policy: DISTRIBUTED RANDOMLY
+Encoding: UTF8
+FileFormat: AO
+TableName: public.t
+Version: 1.0.0

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b5c77add/src/test/feature/ManagementTool/usage2case1/wrong_distributed_policy_tpl.yml
----------------------------------------------------------------------
diff --git 
a/src/test/feature/ManagementTool/usage2case1/wrong_distributed_policy_tpl.yml 
b/src/test/feature/ManagementTool/usage2case1/wrong_distributed_policy_tpl.yml
new file mode 100644
index 0000000..5ed2203
--- /dev/null
+++ 
b/src/test/feature/ManagementTool/usage2case1/wrong_distributed_policy_tpl.yml
@@ -0,0 +1,21 @@
+AO_FileLocations:
+  Blocksize: 32768
+  Checksum: false
+  CompressionLevel: 0
+  CompressionType: null
+  Files:
+  - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/1
+    size: 1016
+AO_Schema:
+- name: i
+  type: int4
+Bucketnum: 6
+DBVersion: PostgreSQL 8.2.15 (Greenplum Database 4.2.0 build 1) (HAWQ 2.0.1.0 
build
+  dev) on x86_64-apple-darwin14.5.0, compiled by GCC Apple LLVM version 6.1.0 
(clang-602.0.53)
+  (based on LLVM 3.6.0svn) compiled on Jul  6 2016 10:22:33
+DFS_URL: hdfs://localhost:8020
+Distribution_Policy: DISTRIBUETD RANDOMLY
+Encoding: UTF8
+FileFormat: AO
+TableName: public.t
+Version: 1.0.0

Reply via email to