hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ztao1...@apache.org
Subject incubator-hawq git commit: add wrapper SQLUtility for test usage
Date Wed, 11 May 2016 02:58:50 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master d2dcfd172 -> f5f0b9b9b


add wrapper SQLUtility for test usage


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

Branch: refs/heads/master
Commit: f5f0b9b9b73edd8bd5aad0f833ab1c694f93901b
Parents: d2dcfd1
Author: ztao1987 <zhenglin.taozl@gmail.com>
Authored: Wed May 11 10:57:55 2016 +0800
Committer: ztao1987 <zhenglin.taozl@gmail.com>
Committed: Wed May 11 10:57:55 2016 +0800

----------------------------------------------------------------------
 src/test/feature/Makefile             |  3 +-
 src/test/feature/lib/Makefile         |  7 +++--
 src/test/feature/lib/sql-util.h       | 46 ++++++++++++++++++++++++++++++
 src/test/feature/testlib/test-lib.cpp | 31 ++++++--------------
 4 files changed, 61 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f5f0b9b9/src/test/feature/Makefile
----------------------------------------------------------------------
diff --git a/src/test/feature/Makefile b/src/test/feature/Makefile
index 8a5ab2d..c89fb1a 100644
--- a/src/test/feature/Makefile
+++ b/src/test/feature/Makefile
@@ -7,7 +7,8 @@ include $(top_builddir)/src/Makefile.global
 include $(top_builddir)/src/Makefile.global
 
 override CXXFLAGS = -Wall -O0 -g -std=c++11
-override CPPFLAGS := -I/usr/include -I/usr/local/include -I/usr/include/libxml2 -I$(top_builddir)/src/test/feature/
-I$(top_builddir)/src/test/feature/lib/
+override CPPFLAGS := -I/usr/include -I/usr/local/include -I/usr/include/libxml2 -I$(top_builddir)/src/test/feature/
-I$(top_builddir)/src/test/feature/lib/ -I$(top_builddir)/src/interfaces/libpq -I$(top_builddir)/src/interfaces
-I$(top_builddir)/src/include
+
 override LIBS := $(LIBS) -lgtest -lpq -lxml2 -ltest
 override LDFLAGS += -L/usr/local/lib -L/usr/lib -L$(top_builddir)/src/test/feature/lib
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f5f0b9b9/src/test/feature/lib/Makefile
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/Makefile b/src/test/feature/lib/Makefile
index 748f663..d6d4670 100644
--- a/src/test/feature/lib/Makefile
+++ b/src/test/feature/lib/Makefile
@@ -3,11 +3,12 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 override CXXFLAGS = -Wall -O0 -g -c -std=c++11
-override CPPFLAGS := -I/usr/include -I/usr/local/include -I/usr/include/libxml2
+override CPPFLAGS := -I/usr/include -I/usr/local/include -I/usr/include/libxml2 -I$(top_builddir)/src/interfaces/libpq
-I$(top_builddir)/src/interfaces -I$(top_builddir)/src/include
+
 override LIBS := $(LIBS) -lpq -lxml2
 override LDFLAGS += -L/usr/local/lib -L/usr/lib
 
-PROG = string-util.cpp psql.cpp command.cpp xml-parser.cpp hawq-config.cpp
+PROG = sql-util.h string-util.cpp psql.cpp command.cpp xml-parser.cpp hawq-config.cpp
 
 all:
 	g++ $(CPPFLAGS) $(CXXFLAGS) $(PROG) 
@@ -17,4 +18,4 @@ distclean clean:
 	rm -f libtest.a
 	rm -f *.o
 
-.PHONY: all distclean  clean
\ No newline at end of file
+.PHONY: all distclean  clean

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f5f0b9b9/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
new file mode 100644
index 0000000..fdf23e6
--- /dev/null
+++ b/src/test/feature/lib/sql-util.h
@@ -0,0 +1,46 @@
+#ifndef SRC_TEST_FEATURE_LIB_SQL_UTIL_H_
+#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") : "")
+
+class SQLUtility {
+ public:
+  SQLUtility() : conn(getConnection()) {
+    const ::testing::TestInfo *const 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);
+  }
+
+  ~SQLUtility() { execute("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);
+  }
+
+ private:
+  std::unique_ptr<PSQL> getConnection() {
+    std::unique_ptr<PSQL> psql(
+        new PSQL(HAWQ_DB, HAWQ_HOST, HAWQ_PORT, HAWQ_USER, HAWQ_PASSWORD));
+    return std::move(psql);
+  }
+
+ private:
+  std::string schemaName;
+  std::unique_ptr<PSQL> conn;
+};
+
+#endif  // SRC_TEST_FEATURE_LIB_SQL_UTIL_H_

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f5f0b9b9/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 663f841..c479f22 100644
--- a/src/test/feature/testlib/test-lib.cpp
+++ b/src/test/feature/testlib/test-lib.cpp
@@ -9,15 +9,14 @@
 #include "lib/command.h"
 #include "lib/common.h"
 #include "lib/hawq-config.h"
+#include "lib/sql-util.h"
 
 #include "gtest/gtest.h"
 
-class TestCommonLib: public ::testing::Test {
-  public:
-    TestCommonLib() {
-    }
-    ~TestCommonLib() {
-    }
+class TestCommonLib : public ::testing::Test {
+ public:
+  TestCommonLib() {}
+  ~TestCommonLib() {}
 };
 
 TEST_F(TestCommonLib, TestHawqConfig) {
@@ -67,21 +66,9 @@ TEST_F(TestCommonLib, TestCommand) {
   Command::getCommandStatus("date");
   Command::getCommandStatus("datewrong");
   Command::getCommandOutput("datewrong");
+}
 
-  PSQL psql("postgres", "localhost", "5432", "huanzhang");
-  psql.setOutputFile("/tmp/testlog");
-  psql.runSQLCommand("create table foo(i int)");
-  psql.runSQLCommand("SELECT * from foo LIMIT 1");
-
-  psql.setOutputFile("/tmp/testlog2");
-  psql.runSQLFile("/tmp/test.sql");
-
-  psql.checkDiff("/tmp/testlog", "/tmp/testlog");
-
-  PSQLQueryResult res = psql.getQueryResult("SELECT * from foo LIMIT 3");
-
-  const std::vector<std::vector<std::string> > rows = res.getRows();
-  const std::vector<std::string> fields = res.getFields();
-
-  psql.runSQLCommand("drop table foo");
+TEST_F(TestCommonLib, TestSqlUtil) {
+  SQLUtility util;
+  util.execute("create table test(p int)");
 }


Mime
View raw message