You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by zt...@apache.org on 2016/05/11 07:19:50 UTC
incubator-hawq git commit: HAWQ-730. Add return code for PSQL.
Repository: incubator-hawq
Updated Branches:
refs/heads/master 541cf4211 -> c3d8546e7
HAWQ-730. Add return code for PSQL.
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/c3d8546e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/c3d8546e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/c3d8546e
Branch: refs/heads/master
Commit: c3d8546e738674c2ec8de6475a191d5a8353e37d
Parents: 541cf42
Author: ztao1987 <zh...@gmail.com>
Authored: Wed May 11 15:11:05 2016 +0800
Committer: ztao1987 <zh...@gmail.com>
Committed: Wed May 11 15:19:40 2016 +0800
----------------------------------------------------------------------
src/test/feature/lib/Makefile | 2 +-
src/test/feature/lib/psql.cpp | 18 ++++++++++++--
src/test/feature/lib/psql.h | 6 +++++
src/test/feature/lib/sql-util.h | 39 ++++++++++++++++++------------
src/test/feature/testlib/test-lib.cpp | 2 ++
5 files changed, 49 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c3d8546e/src/test/feature/lib/Makefile
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/Makefile b/src/test/feature/lib/Makefile
index d6d4670..8c7d74d 100644
--- a/src/test/feature/lib/Makefile
+++ b/src/test/feature/lib/Makefile
@@ -8,7 +8,7 @@ override CPPFLAGS := -I/usr/include -I/usr/local/include -I/usr/include/libxml2
override LIBS := $(LIBS) -lpq -lxml2
override LDFLAGS += -L/usr/local/lib -L/usr/lib
-PROG = sql-util.h string-util.cpp psql.cpp command.cpp xml-parser.cpp hawq-config.cpp
+PROG = string-util.cpp psql.cpp command.cpp xml-parser.cpp hawq-config.cpp
all:
g++ $(CPPFLAGS) $(CXXFLAGS) $(PROG)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c3d8546e/src/test/feature/lib/psql.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/psql.cpp b/src/test/feature/lib/psql.cpp
index b9b7acf..0b0a8a6 100644
--- a/src/test/feature/lib/psql.cpp
+++ b/src/test/feature/lib/psql.cpp
@@ -97,13 +97,16 @@ void PSQLQueryResult::reset()
PSQL& PSQL::runSQLCommand(const std::string& sql_cmd)
{
- Command::getCommandStatus(this->_getPSQLQueryCommand(sql_cmd));
+ Command c(this->_getPSQLQueryCommand(sql_cmd));
+ c.run();
+ this->_last_status = c.getResultStatus();
+ this->_last_result = c.getResultOutput();
return *this;
}
PSQL& PSQL::runSQLFile(const std::string& sql_file)
{
- Command::getCommandStatus(this->_getPSQLFileCommand(sql_file));
+ this->_last_status = Command::getCommandStatus(this->_getPSQLFileCommand(sql_file));
return *this;
}
@@ -186,6 +189,17 @@ std::string PSQL::getConnectionString() const
return command;
}
+int PSQL::getLastStatus() const
+{
+ return this->_last_status;
+}
+
+const std::string& PSQL::getLastResult() const
+{
+ return this->_last_result;
+}
+
+
const std::string PSQL::_getPSQLBaseCommand() const
{
std::string command = "psql";
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c3d8546e/src/test/feature/lib/psql.h
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/psql.h b/src/test/feature/lib/psql.h
index 75bee61..575329e 100644
--- a/src/test/feature/lib/psql.h
+++ b/src/test/feature/lib/psql.h
@@ -60,6 +60,9 @@ public:
PSQL& setOutputFile(const std::string& out);
std::string getConnectionString() const;
+ int getLastStatus() const;
+ const std::string& getLastResult() const;
+
static bool checkDiff(const std::string& expect_file, const std::string& result_file, bool save_diff = true);
private:
@@ -77,6 +80,9 @@ private:
std::string _password;
std::string _output_file;
PSQLQueryResult _result;
+
+ int _last_status;
+ std::string _last_result;
};
#endif
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c3d8546e/src/test/feature/lib/sql-util.h
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/sql-util.h b/src/test/feature/lib/sql-util.h
index fdf23e6..3ede55f 100644
--- a/src/test/feature/lib/sql-util.h
+++ b/src/test/feature/lib/sql-util.h
@@ -2,33 +2,41 @@
#define SRC_TEST_FEATURE_LIB_SQL_UTIL_H_
#include <string>
-
#include "gtest/gtest.h"
#include "psql.h"
-#define HAWQ_DB (getenv("HAWQ_DB") ? getenv("HAWQ_DB") : "postgres")
-#define HAWQ_HOST (getenv("HAWQ_HOST") ? getenv("HAWQ_HOST") : "localhost")
-#define HAWQ_PORT (getenv("HAWQ_PORT") ? getenv("HAWQ_PORT") : "5432")
-#define HAWQ_USER (getenv("HAWQ_USER") ? getenv("HAWQ_USER") : "gpadmin")
-#define HAWQ_PASSWORD (getenv("HAWQ_PASSWORD") ? getenv("HAWQ_PASSWORD") : "")
+#define HAWQ_DB (getenv("PGDATABASE") ? getenv("PGDATABASE") : "postgres")
+#define HAWQ_HOST (getenv("PGHOST") ? getenv("PGHOST") : "localhost")
+#define HAWQ_PORT (getenv("PGPORT") ? getenv("PGPORT") : "5432")
+#define HAWQ_USER (getenv("PGUSER") ? getenv("PGUSER") : "taoz")
+#define HAWQ_PASSWORD (getenv("PGPASSWORD") ? getenv("PGPASSWORD") : "")
class SQLUtility {
public:
- SQLUtility() : conn(getConnection()) {
- const ::testing::TestInfo *const test_info =
- ::testing::UnitTest::GetInstance()->current_test_info();
+ SQLUtility()
+ : conn(getConnection()),
+ test_info(::testing::UnitTest::GetInstance()->current_test_info()) {
schemaName =
std::string(test_info->test_case_name()) + "_" + test_info->name();
- execute("DROP SCHEMA IF EXISTS " + schemaName + " CASCADE");
- execute("CREATE SCHEMA " + schemaName);
+ conn->runSQLCommand("DROP SCHEMA IF EXISTS " + schemaName + " CASCADE");
+ conn->runSQLCommand("CREATE SCHEMA " + schemaName);
}
- ~SQLUtility() { execute("DROP SCHEMA " + schemaName + " CASCADE"); }
+ ~SQLUtility() {
+ if (!test_info->result()->Failed())
+ conn->runSQLCommand("DROP SCHEMA " + schemaName + " CASCADE");
+ }
void execute(const std::string &sql) {
- conn->runSQLCommand("SET SEARCH_PATH=" + schemaName + ";" + sql);
- // should check the return code, depends on PSQL return code implementation
- // EXPECT_EQ(true, ret);
+ EXPECT_EQ(conn->runSQLCommand("SET SEARCH_PATH= " + schemaName + ";" + sql)
+ .getLastStatus(),
+ 0);
+ }
+
+ void query(const std::string &sql, int resultNum) {
+ PSQLQueryResult result =
+ conn->getQueryResult("SET SEARCH_PATH= " + schemaName + ";" + sql);
+ EXPECT_EQ(result.rowCount(), resultNum);
}
private:
@@ -41,6 +49,7 @@ class SQLUtility {
private:
std::string schemaName;
std::unique_ptr<PSQL> conn;
+ const ::testing::TestInfo *const test_info;
};
#endif // SRC_TEST_FEATURE_LIB_SQL_UTIL_H_
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c3d8546e/src/test/feature/testlib/test-lib.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/testlib/test-lib.cpp b/src/test/feature/testlib/test-lib.cpp
index c479f22..68413f9 100644
--- a/src/test/feature/testlib/test-lib.cpp
+++ b/src/test/feature/testlib/test-lib.cpp
@@ -71,4 +71,6 @@ TEST_F(TestCommonLib, TestCommand) {
TEST_F(TestCommonLib, TestSqlUtil) {
SQLUtility util;
util.execute("create table test(p int)");
+ util.execute("insert into test values(1),(2)");
+ util.query("select * from test", 2);
}