Repository: incubator-hawq
Updated Branches:
  refs/heads/master b6dcecda2 -> 3ac393add


HAWQ-725. Refactor feature test framework.


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

Branch: refs/heads/master
Commit: 3ac393addc9dcb12bcddfb3290a0de6768424902
Parents: b6dcecd
Author: hzhang2 <[email protected]>
Authored: Tue May 10 15:29:34 2016 +0800
Committer: hzhang2 <[email protected]>
Committed: Wed May 11 09:12:19 2016 +0800

----------------------------------------------------------------------
 src/Makefile                              |  2 +-
 src/test/Makefile                         |  2 +
 src/test/feature/Makefile                 | 21 ++++++-
 src/test/feature/example/Makefile         | 16 -----
 src/test/feature/example/test_example.cpp | 10 ---
 src/test/feature/lib/Makefile             | 20 ++++++
 src/test/feature/test-main.cpp            |  8 +++
 src/test/feature/testlib/test-lib.cpp     | 87 ++++++++++++++++++++++++++
 8 files changed, 136 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3ac393ad/src/Makefile
----------------------------------------------------------------------
diff --git a/src/Makefile b/src/Makefile
index 9cd4d8a..866a9bf 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -30,7 +30,7 @@ feature_test:
        $(MAKE) -C test feature_test
 
 feature_test_clean:
-       $(MAKE) -C test feature_test clean
+       $(MAKE) -C test clean
 
 install: install-local
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3ac393ad/src/test/Makefile
----------------------------------------------------------------------
diff --git a/src/test/Makefile b/src/test/Makefile
index 4a7649c..ba4e729 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -14,6 +14,8 @@
 #.DEFAULT:
 #      $(MAKE) -C regress $@
 
+.PHONY: feature_test clean
+
 feature_test:
        $(MAKE) -C feature all
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3ac393ad/src/test/feature/Makefile
----------------------------------------------------------------------
diff --git a/src/test/feature/Makefile b/src/test/feature/Makefile
index 64ef46d..8a5ab2d 100644
--- a/src/test/feature/Makefile
+++ b/src/test/feature/Makefile
@@ -4,8 +4,23 @@ include $(top_builddir)/src/Makefile.global
 #.DEFAULT:
 #$(MAKE) -C lib $@
 
+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 LIBS := $(LIBS) -lgtest -lpq -lxml2 -ltest
+override LDFLAGS += -L/usr/local/lib -L/usr/lib 
-L$(top_builddir)/src/test/feature/lib
+
+PROG = test-main.cpp testlib/test-lib.cpp
+
+.PHONY: all distclean  clean
+
 all:
-       $(MAKE) -C example all
+       $(MAKE) -C lib all
+       g++ $(CPPFLAGS) $(CXXFLAGS) $(PROG) $(LDFLAGS) $(LIBS) -o feature-test
 
-clean:
-       $(MAKE) -C example clean
+clean distclean:
+       rm -f feature-test
+       rm -rf feature-test.dSYM
+       $(MAKE) -C lib clean
+       

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3ac393ad/src/test/feature/example/Makefile
----------------------------------------------------------------------
diff --git a/src/test/feature/example/Makefile 
b/src/test/feature/example/Makefile
deleted file mode 100644
index afe3672..0000000
--- a/src/test/feature/example/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-subdir = src/test/feature/example
-top_builddir = ../../../..
-include $(top_builddir)/src/Makefile.global
-
-override CXXFLAGS = -Wall -O0 -g -std=c++11
-override CPPFLAGS := -I/usr/include -I/usr/local/include 
-I$(top_builddir)/src/test/feature/
-override LIBS := $(LIBS) -lgtest
-override LDFLAGS += -L/usr/local/lib -L/usr/lib
-
-PROG = test_example.cpp
-
-all:
-       g++ $(CPPFLAGS) $(CXXFLAGS) $(PROG) $(LDFLAGS) $(LIBS) -o test_example
-
-distclean clean:
-       rm -f test_example

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3ac393ad/src/test/feature/example/test_example.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/example/test_example.cpp 
b/src/test/feature/example/test_example.cpp
deleted file mode 100644
index ee1c268..0000000
--- a/src/test/feature/example/test_example.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <vector>
-#include "lib/common.h"
-
-int main(int argc, char *argv[])
-{
-  std::vector<int> A = {1, 2, 3};
-  std::vector<int> B = {1, 2, 3};
-  hawq::test::EQUAL_CHECK(A, B);
-  return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3ac393ad/src/test/feature/lib/Makefile
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/Makefile b/src/test/feature/lib/Makefile
new file mode 100644
index 0000000..748f663
--- /dev/null
+++ b/src/test/feature/lib/Makefile
@@ -0,0 +1,20 @@
+subdir = src/test/feature/lib
+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 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
+
+all:
+       g++ $(CPPFLAGS) $(CXXFLAGS) $(PROG) 
+       ar -r libtest.a  *.o
+
+distclean clean:
+       rm -f libtest.a
+       rm -f *.o
+
+.PHONY: all distclean  clean
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3ac393ad/src/test/feature/test-main.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/test-main.cpp b/src/test/feature/test-main.cpp
new file mode 100644
index 0000000..9347288
--- /dev/null
+++ b/src/test/feature/test-main.cpp
@@ -0,0 +1,8 @@
+
+#include "gtest/gtest.h"
+
+int main(int argc, char** argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+
+  return RUN_ALL_TESTS();
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3ac393ad/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
new file mode 100644
index 0000000..663f841
--- /dev/null
+++ b/src/test/feature/testlib/test-lib.cpp
@@ -0,0 +1,87 @@
+#include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <vector>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "lib/command.h"
+#include "lib/common.h"
+#include "lib/hawq-config.h"
+
+#include "gtest/gtest.h"
+
+class TestCommonLib: public ::testing::Test {
+  public:
+    TestCommonLib() {
+    }
+    ~TestCommonLib() {
+    }
+};
+
+TEST_F(TestCommonLib, TestHawqConfig) {
+  std::string hostname = "";
+  int port = 0;
+  struct passwd *pw;
+  uid_t uid;
+  uid = geteuid();
+  pw = getpwuid(uid);
+  std::string uname(pw->pw_name);
+  HawqConfig hc(uname);
+  hc.getMaster(hostname, port);
+
+  hostname = "";
+  port = 0;
+  hc.getStandbyMaster(hostname, port);
+
+  std::vector<std::string> segmentHostname;
+  std::vector<int> segmentPort;
+  hc.getSlaves(segmentHostname);
+
+  segmentHostname.clear();
+  segmentPort.clear();
+  hc.getTotalSegments(segmentHostname, segmentPort);
+
+  segmentHostname.clear();
+  segmentPort.clear();
+  hc.getDownSegments(segmentHostname, segmentPort);
+
+  segmentHostname.clear();
+  segmentPort.clear();
+  hc.getUpSegments(segmentHostname, segmentPort);
+
+  hc.isMasterMirrorSynchronized();
+  hc.isMultinodeMode();
+
+  hc.setGucValue("default_hash_table_bucket_number", "4");
+  hc.getGucValue("default_hash_table_bucket_number");
+  return;
+}
+
+TEST_F(TestCommonLib, TestCommand) {
+  Command c("ls ./");
+  c.run().getResultOutput();
+
+  Command::getCommandOutput("pwd");
+  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");
+}

Reply via email to