You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by gc...@apache.org on 2015/11/04 19:35:55 UTC

incubator-hawq git commit: HAWQ-79. Re-enable unit test for shared input scan

Repository: incubator-hawq
Updated Branches:
  refs/heads/master a88bbdfec -> 04c0f28b9


HAWQ-79. Re-enable unit test for shared input scan


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

Branch: refs/heads/master
Commit: 04c0f28b9674dad7002010571b7fb7a6626a81a6
Parents: a88bbdf
Author: Nikos Armenatzoglou <ni...@gmail.com>
Authored: Mon Nov 2 13:57:38 2015 -0800
Committer: Nikos Armenatzoglou <ni...@gmail.com>
Committed: Wed Nov 4 10:34:43 2015 -0800

----------------------------------------------------------------------
 src/backend/executor/test/.gitignore            |   1 +
 src/backend/executor/test/Makefile              | 156 +++++++++++++++++
 src/backend/executor/test/execAmi_test.c        |  37 ++++
 src/backend/executor/test/execHHashagg_test.c   | 145 ++++++++++++++++
 src/backend/executor/test/execWorkfile_test.c   | 101 +++++++++++
 .../executor/test/nodeShareInputScan_test.c     | 102 +++++++++++
 src/backend/executor/test/nodeSubplan_test.c    | 171 +++++++++++++++++++
 src/backend/executor/test_discard/.gitignore    |   1 -
 src/backend/executor/test_discard/Makefile      | 157 -----------------
 .../executor/test_discard/execAmi_test.c        |  37 ----
 .../executor/test_discard/execHHashagg_test.c   | 145 ----------------
 .../executor/test_discard/execWorkfile_test.c   | 101 -----------
 .../test_discard/nodeShareInputScan_test.c      | 102 -----------
 .../executor/test_discard/nodeSubplan_test.c    | 159 -----------------
 14 files changed, 713 insertions(+), 702 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test/.gitignore
----------------------------------------------------------------------
diff --git a/src/backend/executor/test/.gitignore b/src/backend/executor/test/.gitignore
new file mode 100644
index 0000000..a8d6b6c
--- /dev/null
+++ b/src/backend/executor/test/.gitignore
@@ -0,0 +1 @@
+*.t

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test/Makefile
----------------------------------------------------------------------
diff --git a/src/backend/executor/test/Makefile b/src/backend/executor/test/Makefile
new file mode 100644
index 0000000..d52c10d
--- /dev/null
+++ b/src/backend/executor/test/Makefile
@@ -0,0 +1,156 @@
+subdir=src/backend/executor
+top_builddir=../../../..
+
+TARGETS=nodeSubplan nodeShareInputScan execAmi execWorkfile execHHashagg
+
+# Objects from backend, which don't need to be mocked but need to be linked.
+nodeSubplan_REAL_OBJS=\
+        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
+        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
+	$(top_srcdir)/src/backend/executor/execUtils.o \
+        $(top_srcdir)/src/backend/lib/stringinfo.o \
+	$(top_srcdir)/src/backend/nodes/bitmapset.o \
+        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
+        $(top_srcdir)/src/backend/nodes/list.o \
+        $(top_srcdir)/src/backend/parser/gram.o \
+        $(top_srcdir)/src/backend/regex/regcomp.o \
+        $(top_srcdir)/src/backend/regex/regerror.o \
+        $(top_srcdir)/src/backend/regex/regexec.o \
+        $(top_srcdir)/src/backend/regex/regfree.o \
+        $(top_srcdir)/src/backend/storage/page/itemptr.o \
+	$(top_srcdir)/src/backend/utils/adt/datum.o \
+        $(top_srcdir)/src/backend/utils/adt/like.o \
+        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
+        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
+        $(top_srcdir)/src/backend/utils/misc/guc.o \
+        $(top_srcdir)/src/backend/utils/init/globals.o \
+        $(top_srcdir)/src/port/exec.o \
+        $(top_srcdir)/src/port/path.o \
+        $(top_srcdir)/src/port/pgsleep.o \
+        $(top_srcdir)/src/port/pgstrcasecmp.o \
+        $(top_srcdir)/src/port/qsort.o \
+        $(top_srcdir)/src/port/strlcpy.o \
+        $(top_srcdir)/src/port/thread.o \
+        $(top_srcdir)/src/timezone/localtime.o \
+        $(top_srcdir)/src/timezone/pgtz.o
+
+nodeShareInputScan_REAL_OBJS=\
+        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
+        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
+        $(top_srcdir)/src/backend/lib/stringinfo.o \
+	$(top_srcdir)/src/backend/nodes/bitmapset.o \
+        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
+        $(top_srcdir)/src/backend/nodes/list.o \
+        $(top_srcdir)/src/backend/parser/gram.o \
+        $(top_srcdir)/src/backend/regex/regcomp.o \
+        $(top_srcdir)/src/backend/regex/regerror.o \
+        $(top_srcdir)/src/backend/regex/regexec.o \
+        $(top_srcdir)/src/backend/regex/regfree.o \
+        $(top_srcdir)/src/backend/storage/page/itemptr.o \
+	$(top_srcdir)/src/backend/utils/adt/datum.o \
+        $(top_srcdir)/src/backend/utils/adt/like.o \
+        $(top_srcdir)/src/backend/utils/fmgrtab.o \
+        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
+        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
+        $(top_srcdir)/src/backend/utils/misc/guc.o \
+        $(top_srcdir)/src/backend/utils/init/globals.o \
+        $(top_srcdir)/src/port/exec.o \
+        $(top_srcdir)/src/port/path.o \
+        $(top_srcdir)/src/port/pgsleep.o \
+        $(top_srcdir)/src/port/pgstrcasecmp.o \
+        $(top_srcdir)/src/port/qsort.o \
+        $(top_srcdir)/src/port/strlcpy.o \
+        $(top_srcdir)/src/port/thread.o \
+        $(top_srcdir)/src/timezone/localtime.o \
+        $(top_srcdir)/src/timezone/pgtz.o
+
+execAmi_REAL_OBJS=\
+        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
+        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
+        $(top_srcdir)/src/backend/lib/stringinfo.o \
+        $(top_srcdir)/src/backend/nodes/bitmapset.o \
+        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
+        $(top_srcdir)/src/backend/nodes/list.o \
+        $(top_srcdir)/src/backend/parser/gram.o \
+        $(top_srcdir)/src/backend/regex/regcomp.o \
+        $(top_srcdir)/src/backend/regex/regerror.o \
+        $(top_srcdir)/src/backend/regex/regexec.o \
+        $(top_srcdir)/src/backend/regex/regfree.o \
+        $(top_srcdir)/src/backend/storage/page/itemptr.o \
+        $(top_srcdir)/src/backend/utils/adt/datum.o \
+        $(top_srcdir)/src/backend/utils/adt/like.o \
+        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
+        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
+        $(top_srcdir)/src/backend/utils/misc/guc.o \
+        $(top_srcdir)/src/backend/utils/init/globals.o \
+        $(top_srcdir)/src/port/exec.o \
+        $(top_srcdir)/src/port/path.o \
+        $(top_srcdir)/src/port/pgsleep.o \
+        $(top_srcdir)/src/port/pgstrcasecmp.o \
+        $(top_srcdir)/src/port/qsort.o \
+        $(top_srcdir)/src/port/strlcpy.o \
+        $(top_srcdir)/src/port/thread.o \
+        $(top_srcdir)/src/timezone/localtime.o \
+        $(top_srcdir)/src/timezone/pgtz.o
+
+execWorkfile_REAL_OBJS=\
+        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
+        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
+        $(top_srcdir)/src/backend/lib/stringinfo.o \
+	$(top_srcdir)/src/backend/nodes/bitmapset.o \
+        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
+        $(top_srcdir)/src/backend/nodes/list.o \
+        $(top_srcdir)/src/backend/parser/gram.o \
+        $(top_srcdir)/src/backend/regex/regcomp.o \
+        $(top_srcdir)/src/backend/regex/regerror.o \
+        $(top_srcdir)/src/backend/regex/regexec.o \
+        $(top_srcdir)/src/backend/regex/regfree.o \
+        $(top_srcdir)/src/backend/storage/page/itemptr.o \
+	$(top_srcdir)/src/backend/utils/adt/datum.o \
+        $(top_srcdir)/src/backend/utils/adt/like.o \
+        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
+        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
+        $(top_srcdir)/src/backend/utils/misc/guc.o \
+        $(top_srcdir)/src/backend/utils/init/globals.o \
+        $(top_srcdir)/src/port/exec.o \
+        $(top_srcdir)/src/port/path.o \
+        $(top_srcdir)/src/port/pgsleep.o \
+        $(top_srcdir)/src/port/pgstrcasecmp.o \
+        $(top_srcdir)/src/port/qsort.o \
+        $(top_srcdir)/src/port/strlcpy.o \
+        $(top_srcdir)/src/port/thread.o \
+        $(top_srcdir)/src/timezone/localtime.o \
+        $(top_srcdir)/src/timezone/pgtz.o
+
+execHHashagg_REAL_OBJS=\
+        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
+        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
+	$(top_srcdir)/src/backend/executor/execUtils.o \
+        $(top_srcdir)/src/backend/lib/stringinfo.o \
+	$(top_srcdir)/src/backend/nodes/bitmapset.o \
+        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
+        $(top_srcdir)/src/backend/nodes/list.o \
+        $(top_srcdir)/src/backend/parser/gram.o \
+        $(top_srcdir)/src/backend/regex/regcomp.o \
+        $(top_srcdir)/src/backend/regex/regerror.o \
+        $(top_srcdir)/src/backend/regex/regexec.o \
+        $(top_srcdir)/src/backend/regex/regfree.o \
+        $(top_srcdir)/src/backend/storage/page/itemptr.o \
+	$(top_srcdir)/src/backend/utils/adt/datum.o \
+        $(top_srcdir)/src/backend/utils/adt/like.o \
+        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
+        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
+        $(top_srcdir)/src/backend/utils/misc/guc.o \
+        $(top_srcdir)/src/backend/utils/init/globals.o \
+        $(top_srcdir)/src/port/exec.o \
+        $(top_srcdir)/src/port/path.o \
+        $(top_srcdir)/src/port/pgsleep.o \
+        $(top_srcdir)/src/port/pgstrcasecmp.o \
+        $(top_srcdir)/src/port/qsort.o \
+        $(top_srcdir)/src/port/strlcpy.o \
+        $(top_srcdir)/src/port/thread.o \
+        $(top_srcdir)/src/timezone/localtime.o \
+        $(top_srcdir)/src/timezone/pgtz.o
+
+include ../../../Makefile.mock
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test/execAmi_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test/execAmi_test.c b/src/backend/executor/test/execAmi_test.c
new file mode 100644
index 0000000..9947104
--- /dev/null
+++ b/src/backend/executor/test/execAmi_test.c
@@ -0,0 +1,37 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include "cmockery.h"
+
+#include "c.h"
+#include "postgres.h"
+#include "nodes/nodes.h"
+
+#include "../execAmi.c"
+
+/* ==================== ExecEagerFree ==================== */
+/*
+ * Tests that ExecEageFree calls the new ExecEagerFreeShareInputScan
+ * function when the input is a ShareInputScanState
+ */
+void
+test__ExecEagerFree_ExecEagerFreeShareInputScan(void **state)
+{
+	ShareInputScanState *sisc = makeNode(ShareInputScanState);
+
+	expect_value(ExecEagerFreeShareInputScan, node, sisc);
+	will_be_called(ExecEagerFreeShareInputScan);
+
+	ExecEagerFree(sisc);
+}
+
+int
+main(int argc, char* argv[])
+{
+        cmockery_parse_arguments(argc, argv);
+
+        const UnitTest tests[] = {
+                        unit_test(test__ExecEagerFree_ExecEagerFreeShareInputScan)
+        };
+        return run_tests(tests);
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test/execHHashagg_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test/execHHashagg_test.c b/src/backend/executor/test/execHHashagg_test.c
new file mode 100644
index 0000000..0972ad9
--- /dev/null
+++ b/src/backend/executor/test/execHHashagg_test.c
@@ -0,0 +1,145 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include "cmockery.h"
+
+#include "c.h"
+#include "postgres.h"
+
+/* Ignore elog */
+#include "utils/elog.h"
+#undef elog
+#define elog
+
+
+/* Provide specialized mock implementations for memory allocation functions */
+
+#undef palloc
+#define palloc getSpillFile_palloc_mock
+void *getSpillFile_palloc_mock(Size size);
+
+#include "../execHHashagg.c"
+
+
+/*
+ * This is a mocked version of palloc to be used in getSpillFile().
+ * It returns allocated memory padded with 0x7f pattern.
+ */
+void *
+getSpillFile_palloc_mock(Size size)
+{
+ void *ptr = MemoryContextAlloc(CurrentMemoryContext, size);
+ MemSetAligned(ptr, 0x7f, size);
+ return ptr; 
+}
+
+
+/* ==================== getSpillFile ==================== */
+/*
+ * Test that the spill_file->file_info->wfile field is allocated 
+ * and initialized during normal execution (no exception thrown).
+ */
+void
+test__getSpillFile__Initialize_wfile_success(void **state)
+{
+  int alloc_size = 0; 
+  int file_no = 0;
+  int branching_factor = 32; 
+  ExecWorkFile *ewfile = (ExecWorkFile *) palloc0(sizeof(ExecWorkFile)); 
+  workfile_set *work_set = (workfile_set *) palloc0(sizeof(workfile_set)); 
+  SpillSet *spill_set = (SpillSet *) palloc0(sizeof(SpillSet) + (branching_factor-1) * sizeof (SpillFile));
+
+  SpillFile *spill_file = &spill_set->spill_files[file_no];
+  spill_file->file_info = NULL; 
+
+  expect_value(workfile_mgr_create_file, work_set, work_set);
+  will_return(workfile_mgr_create_file, ewfile); 
+  
+  getSpillFile(work_set, spill_set, file_no, &alloc_size); 
+
+  assert_true(spill_file->file_info != NULL); 
+  assert_int_equal(spill_file->file_info->total_bytes, 0); 
+  assert_int_equal(spill_file->file_info->ntuples, 0); 
+  assert_int_equal(alloc_size, BATCHFILE_METADATA);
+
+  /*
+   * During normal execution, wfile should be initialized with 
+   * the result of workfile_mgr_create_wfile, a valid ExecWorkFile pointer
+   */ 
+  assert_true(spill_file->file_info->wfile == ewfile); 
+}
+
+/*
+ * Function used a side effect to simulate throwing exception 
+ * by a certain function. 
+ */
+void
+throw_exception_side_effect()
+{
+  PG_RE_THROW();
+}
+
+/* ==================== getSpillFile ==================== */
+/*
+ * Test that the spill_file->file_info->wfile field is initialized to NULL 
+ * when creating a workfile throws an exception. 
+ */
+void
+test__getSpillFile__Initialize_wfile_exception(void **state)
+{
+
+  int alloc_size = 0; 
+  int file_no = 0;
+  int branching_factor = 32; 
+  ExecWorkFile *ewfile = (ExecWorkFile *) palloc0(sizeof(ExecWorkFile)); 
+  workfile_set *work_set = (workfile_set *) palloc0(sizeof(workfile_set)); 
+  SpillSet *spill_set = (SpillSet *) palloc0(sizeof(SpillSet) + (branching_factor-1) * sizeof (SpillFile));
+
+  SpillFile *spill_file = &spill_set->spill_files[0];
+  spill_file->file_info = NULL; 
+
+  /* Make workfile_mgr_create_file throw an exception, using the side effect function */ 
+  expect_value(workfile_mgr_create_file, work_set, work_set);
+  will_return_with_sideeffect(workfile_mgr_create_file, ewfile, &throw_exception_side_effect, NULL); 
+  
+  PG_TRY(); 
+  {
+    
+    /* This function will throw an exception, and we'll catch it below */
+    getSpillFile(work_set, spill_set, file_no, &alloc_size); 
+
+  }
+  PG_CATCH(); 
+  {
+    assert_true(spill_file->file_info != NULL); 
+    assert_int_equal(spill_file->file_info->total_bytes, 0); 
+    assert_int_equal(spill_file->file_info->ntuples, 0); 
+    assert_int_equal(alloc_size, 0);
+
+    /* 
+     * This is the main test: We must initialize this pointer to NULL, even 
+     * if an exception is thrown
+     */
+    assert_true(spill_file->file_info->wfile == NULL); 
+    return; 
+  }
+  PG_END_TRY(); 
+
+  /* We shouldn't get here, the getSpillFile should throw an exception */ 
+  assert_true(false);
+
+}
+
+/* ==================== main ==================== */
+int
+main(int argc, char* argv[])
+{
+    cmockery_parse_arguments(argc, argv);
+
+    const UnitTest tests[] = {
+      unit_test(test__getSpillFile__Initialize_wfile_success),
+      unit_test(test__getSpillFile__Initialize_wfile_exception)
+                             };
+
+    return run_tests(tests);
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test/execWorkfile_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test/execWorkfile_test.c b/src/backend/executor/test/execWorkfile_test.c
new file mode 100644
index 0000000..9d95a1f
--- /dev/null
+++ b/src/backend/executor/test/execWorkfile_test.c
@@ -0,0 +1,101 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include "cmockery.h"
+
+#include "c.h"
+#include "postgres.h"
+#include "storage/buffile.h"
+#include "storage/bfz.h"
+#include "executor/execWorkfile.h"
+#include "utils/memutils.h"
+
+/* Ignore elog */
+#include "utils/elog.h"
+
+#undef elog
+#define elog
+
+/* Provide specialized mock implementations for memory allocation functions */
+#undef palloc0
+#define palloc0 execWorkfile_palloc0_mock
+void *execWorkfile_palloc0_mock(Size size);
+
+#undef pstrdup
+#define pstrdup execWorkfile_pstrdup_mock
+char *execWorkfile_pstrdup_mock(const char *string);
+
+#include "../execWorkfile.c"
+
+/*
+ * This is a mocked version of palloc0 to be used in ExecWorkFile_Create.
+ *   It asserts that it is executed in the TopMemoryContext.
+ */
+void *
+execWorkfile_palloc0_mock(Size size)
+{
+	assert_int_equal(CurrentMemoryContext, TopMemoryContext);
+	return MemoryContextAllocZero(CurrentMemoryContext, size);
+}
+
+/*
+ * This is a mocked version of pstrdup to be used in ExecWorkFile_Create.
+ *   It asserts that it is executed in the TopMemoryContext.
+ */
+char *execWorkfile_pstrdup_mock(const char *string)
+{
+	assert_int_equal(CurrentMemoryContext, TopMemoryContext);
+	return MemoryContextStrdup(CurrentMemoryContext, string);
+}
+
+
+/* ==================== ExecWorkFile_Create ==================== */
+/*
+ * Test that the ExecWorkFile struct is allocated in TopMemoryContext
+ */
+void
+test__ExecWorkFile_Create__InTopMemContext(void **state)
+{
+
+	char *test_filename = "foo";
+
+	will_return(WorkfileQueryspace_AddWorkfile, true);
+
+	expect_value(BufFileCreateFile, fileName, test_filename);
+	expect_value(BufFileCreateFile, delOnClose, true);
+	expect_value(BufFileCreateFile, interXact, false);
+	will_return(BufFileCreateFile, NULL);
+
+	expect_value(BufFileSetWorkfile, buffile, NULL);
+	will_be_called(BufFileSetWorkfile);
+
+	/*
+	 * All the memory context stuff is mocked, so the TopMemoryContext is NULL
+	 * at this point. Set it to something specific so we can distinguish it from
+	 * the CurrentMemoryContext.
+	 */
+	TopMemoryContext = (MemoryContext) 0xdeadbeef;
+	CurrentMemoryContext = (MemoryContext) 0xfeadbead;
+
+	/*
+	 * ExecWorkFile_Create will call our mocked palloc0 function execWorkfile__palloc0_mock
+	 * and our mocked pstrdup function execWorkfile_pstrdup_mock.
+	 * These functions will assert that the allocation of the result happens
+	 * in the TopMemoryContext.
+	 */
+	ExecWorkFile *ewf = ExecWorkFile_Create(test_filename, BUFFILE, true /* delOnClose */, 0 /* compressType */);
+
+}
+
+/* ==================== main ==================== */
+int
+main(int argc, char* argv[])
+{
+    cmockery_parse_arguments(argc, argv);
+
+    const UnitTest tests[] = {
+                                 unit_test(test__ExecWorkFile_Create__InTopMemContext)
+                             };
+
+    return run_tests(tests);
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test/nodeShareInputScan_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test/nodeShareInputScan_test.c b/src/backend/executor/test/nodeShareInputScan_test.c
new file mode 100644
index 0000000..7bb8b92
--- /dev/null
+++ b/src/backend/executor/test/nodeShareInputScan_test.c
@@ -0,0 +1,102 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include "cmockery.h"
+
+#include "c.h"
+#include "postgres.h"
+#include "nodes/nodes.h"
+#include "../nodeShareInputScan.c"
+
+#define FIXED_POINTER_VAL ((LargestIntegralType) 0x0000beef)
+#define SHARE_NODE_ENTRY_REFCOUNT 78
+
+/*
+ * Tests ExecEagerFreeShareInputScan when plan->share_type = SHARE_NOTSHARED
+ * Verifies that all the pointers are set to NULL
+ */
+void
+test__ExecEagerFreeShareInputScan_SHARE_NOTSHARED(void **state)
+{
+	ShareInputScanState *sisc = makeNode(ShareInputScanState);
+	ShareInputScan *plan = makeNode(ShareInputScan);
+	sisc->ss.ps.plan = plan;
+
+	sisc->ts_markpos = FIXED_POINTER_VAL;
+	sisc->ts_pos = FIXED_POINTER_VAL;
+	sisc->ts_state = FIXED_POINTER_VAL;
+	sisc->freed = false;
+
+	plan->share_type = SHARE_NOTSHARED;
+
+	ExecEagerFreeShareInputScan(sisc);
+
+	assert_int_equal(sisc->ts_markpos, NULL);
+	assert_int_equal(sisc->ts_pos, NULL);
+	assert_int_equal(sisc->ts_state, NULL);
+	assert_true(sisc->freed);
+
+	return;
+}
+
+/* ==================== ExecEagerFreeShareInputScan ==================== */
+/*
+ * Tests ExecEagerFreeShareInputScan when plan->share_type = SHARE_MATERIAL
+ * Verifies that the tuplestore accessor and the tuplestore state are destroyed,
+ * and that all the pointers are set to NULL
+ */
+void
+test__ExecEagerFreeShareInputScan_SHARE_MATERIAL(void **state)
+{
+	ShareInputScanState *sisc = makeNode(ShareInputScanState);
+	ShareInputScan *plan = makeNode(ShareInputScan);
+	sisc->ss.ps.plan = plan;
+
+	sisc->ts_markpos = NULL;
+	sisc->ts_pos = FIXED_POINTER_VAL;
+	sisc->ts_state = (GenericTupStore *) palloc0(sizeof(GenericTupStore));
+	sisc->ts_state->matstore = FIXED_POINTER_VAL;
+	sisc->freed = false;
+
+	plan->share_type = SHARE_MATERIAL;
+
+	expect_value(ntuplestore_destroy_accessor, acc, FIXED_POINTER_VAL);
+	will_be_called(ntuplestore_destroy_accessor);
+
+	expect_value(ntuplestore_is_readerwriter_reader, nts, FIXED_POINTER_VAL);
+	will_return(ntuplestore_is_readerwriter_reader, true);
+
+	expect_value(ntuplestore_destroy, ts, FIXED_POINTER_VAL);
+	will_be_called(ntuplestore_destroy);
+
+
+	ShareNodeEntry *shareNodeEntry = makeNode(ShareNodeEntry);
+	shareNodeEntry->refcount = SHARE_NODE_ENTRY_REFCOUNT;
+
+	expect_any(ExecGetShareNodeEntry, estate);
+	expect_any(ExecGetShareNodeEntry, shareidx);
+	expect_value(ExecGetShareNodeEntry, fCreate, false);
+	will_return(ExecGetShareNodeEntry, shareNodeEntry);
+
+	ExecEagerFreeShareInputScan(sisc);
+
+	assert_int_equal(sisc->ts_markpos, NULL);
+	assert_int_equal(sisc->ts_pos, NULL);
+	assert_int_equal(sisc->ts_state, NULL);
+	assert_int_equal(shareNodeEntry->refcount, SHARE_NODE_ENTRY_REFCOUNT - 1);
+	assert_true(sisc->freed);
+
+	return;
+}
+
+int
+main(int argc, char* argv[])
+{
+        cmockery_parse_arguments(argc, argv);
+
+        const UnitTest tests[] = {
+                        unit_test(test__ExecEagerFreeShareInputScan_SHARE_NOTSHARED),
+                        unit_test(test__ExecEagerFreeShareInputScan_SHARE_MATERIAL)
+        };
+        return run_tests(tests);
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test/nodeSubplan_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test/nodeSubplan_test.c b/src/backend/executor/test/nodeSubplan_test.c
new file mode 100644
index 0000000..4786220
--- /dev/null
+++ b/src/backend/executor/test/nodeSubplan_test.c
@@ -0,0 +1,171 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include "cmockery.h"
+
+#include "c.h"
+#include "postgres.h"
+#include "nodes/nodes.h"
+#include "../nodeSubplan.c"
+
+/* Function passed to testing framework
+ * in order to force SetupInterconnect to fail */ 
+void
+_RETHROW( )
+{
+	PG_RE_THROW();
+}
+
+
+/* Checks CdbCheckDispatchResult is called when queryDesc
+ * is not null (when shouldDispatch is true).
+ * This test falls in PG_CATCH when SetupInterconnect
+ * does not allocate queryDesc->estate->interconnect_context.
+ * The test is successful if the */
+void 
+test__ExecSetParamPlan__Check_Dispatch_Results(void **state) 
+{
+
+	/*Set plan to explain.*/
+	SubPlanState *plan = makeNode(SubPlanState);
+	plan->xprstate.expr = makeNode(SubPlanState);
+	plan->planstate = makeNode(SubPlanState);
+	plan->planstate->instrument = (Instrumentation *)palloc(sizeof(Instrumentation));
+	plan->planstate->plan = makeNode(SubPlanState);
+	
+	/*Function needed for estate.*/
+	expect_any(AllocSetContextCreate,parent);
+	expect_any(AllocSetContextCreate,name);
+	expect_any(AllocSetContextCreate,minContextSize);
+	expect_any(AllocSetContextCreate,initBlockSize);
+	expect_any(AllocSetContextCreate,maxBlockSize);
+	will_be_called(AllocSetContextCreate);
+	EState *estate = CreateExecutorState();
+
+	/*Assign mocked estate to plan.*/
+	((PlanState *)(plan->planstate))->state= estate;
+
+	/*Function needed for GetPerTupleExprContext*/
+	expect_any(AllocSetContextCreate,parent);
+	expect_any(AllocSetContextCreate,name);
+	expect_any(AllocSetContextCreate,minContextSize);
+	expect_any(AllocSetContextCreate,initBlockSize);
+	expect_any(AllocSetContextCreate,maxBlockSize);
+	will_be_called(AllocSetContextCreate);
+
+	/*Re-use estate mocked object. Needed as input parameter for
+	tested function */
+	ExprContext *econtext = GetPerTupleExprContext(estate);
+
+
+	/*Set QueryDescriptor input parameter for tested function */
+	PlannedStmt   *plannedstmt = (PlannedStmt *)palloc(sizeof(PlannedStmt));
+	QueryDesc *queryDesc = (QueryDesc *)palloc(sizeof(QueryDesc));
+	queryDesc->plannedstmt = plannedstmt;
+	queryDesc->estate = (EState *)palloc(sizeof(EState));
+	queryDesc->estate->es_sliceTable = (SliceTable *) palloc(sizeof(SliceTable));
+
+	/*Set of functions called within tested function*/
+	expect_any(MemoryContextGetPeakSpace,context);
+	will_be_called(MemoryContextGetPeakSpace);
+
+	expect_any(MemoryContextSetPeakSpace,context);
+	expect_any(MemoryContextSetPeakSpace,nbytes);
+	will_be_called(MemoryContextSetPeakSpace);
+
+	/*QueryDescriptor generated when shouldDispatch is true.*/
+	QueryDesc *internalQueryDesc = (QueryDesc *)palloc(sizeof(QueryDesc));
+	internalQueryDesc->estate = (EState *)palloc(sizeof(EState));
+	/* Added to force assertion on queryDesc->estate->interconnect_context;
+	to fail */
+	internalQueryDesc->estate->interconnect_context=NULL;
+	internalQueryDesc->estate->es_sliceTable = (SliceTable *) palloc(sizeof(SliceTable));
+
+	expect_any(CreateQueryDesc,plannedstmt);
+	expect_any(CreateQueryDesc,sourceText);
+	expect_any(CreateQueryDesc,snapshot);
+	expect_any(CreateQueryDesc,crosscheck_snapshot);
+	expect_any(CreateQueryDesc,dest);
+	expect_any(CreateQueryDesc,params);
+	expect_any(CreateQueryDesc,doInstrument);
+	will_return(CreateQueryDesc,internalQueryDesc);
+
+	expect_any(AllocSetContextCreate,parent);
+	expect_any(AllocSetContextCreate,name);
+	expect_any(AllocSetContextCreate,minContextSize);
+	expect_any(AllocSetContextCreate,initBlockSize);
+	expect_any(AllocSetContextCreate,maxBlockSize);
+	will_be_called(AllocSetContextCreate);
+
+	Gp_role = GP_ROLE_DISPATCH;
+	plan->planstate->plan->dispatch=DISPATCH_PARALLEL;
+
+	expect_any(SetupInterconnect,estate);
+	/* Force SetupInterconnect to fail */
+	will_be_called_with_sideeffect(SetupInterconnect,&_RETHROW,NULL);
+
+
+	expect_any(cdbexplain_localExecStats,planstate);
+	expect_any(cdbexplain_localExecStats,showstatctx);
+	will_be_called(cdbexplain_localExecStats);
+
+	expect_any(cdbexplain_recvExecStats,planstate);
+	expect_any(cdbexplain_recvExecStats,dispatchResults);
+	expect_any(cdbexplain_recvExecStats,sliceIndex);
+	expect_any(cdbexplain_recvExecStats,showstatctx);
+	expect_any(cdbexplain_recvExecStats,segmentNum);
+	will_be_called(cdbexplain_recvExecStats);
+
+	expect_any(MemoryContextSetPeakSpace,context);
+	expect_any(MemoryContextSetPeakSpace,nbytes);
+	will_be_called(MemoryContextSetPeakSpace);
+
+	will_be_called(TeardownSequenceServer);
+
+	expect_any(TeardownInterconnect,transportStates);
+	expect_any(TeardownInterconnect,mlStates);
+	expect_any(TeardownInterconnect,forceEOS);
+	will_be_called(TeardownInterconnect);
+
+	expect_any(initialize_dispatch_data, resource);
+	expect_any(initialize_dispatch_data, dispatch_to_all_cached_executors);
+	will_be_called(initialize_dispatch_data);
+
+	expect_any(prepare_dispatch_query_desc, data);
+	expect_any(prepare_dispatch_query_desc, queryDesc);
+	will_be_called(prepare_dispatch_query_desc);
+
+	expect_any(dispatch_run, data);
+	will_be_called(dispatch_run);
+
+	expect_any(cleanup_dispatch_data, data);
+	will_be_called(cleanup_dispatch_data);
+
+	expect_any(dispatch_wait, data);
+	will_be_called(dispatch_wait);
+
+	expect_any(dispatch_get_segment_num, data);
+	will_be_called(dispatch_get_segment_num);
+
+	expect_any(dispatch_get_results, data);
+	will_be_called(dispatch_get_results);
+
+	/* Catch PG_RE_THROW(); after cleaning with CdbCheckDispatchResult */
+	PG_TRY();
+		ExecSetParamPlan(plan,econtext,queryDesc);
+	PG_CATCH();
+		assert_true(true);
+	PG_END_TRY();
+}
+
+int 
+main(int argc, char* argv[]) 
+{
+        cmockery_parse_arguments(argc, argv);
+        
+        const UnitTest tests[] = {
+                        unit_test(test__ExecSetParamPlan__Check_Dispatch_Results)
+        };
+        return run_tests(tests);
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test_discard/.gitignore
----------------------------------------------------------------------
diff --git a/src/backend/executor/test_discard/.gitignore b/src/backend/executor/test_discard/.gitignore
deleted file mode 100644
index a8d6b6c..0000000
--- a/src/backend/executor/test_discard/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-*.t

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test_discard/Makefile
----------------------------------------------------------------------
diff --git a/src/backend/executor/test_discard/Makefile b/src/backend/executor/test_discard/Makefile
deleted file mode 100644
index bdc2f8f..0000000
--- a/src/backend/executor/test_discard/Makefile
+++ /dev/null
@@ -1,157 +0,0 @@
-subdir=src/backend/executor
-top_builddir=../../../..
-
-TARGETS=nodeSubplan nodeShareInputScan execAmi execWorkfile execHHashagg
-
-# Objects from backend, which don't need to be mocked but need to be linked.
-nodeSubplan_REAL_OBJS=\
-        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
-        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
-	$(top_srcdir)/src/backend/executor/execUtils.o \
-        $(top_srcdir)/src/backend/lib/stringinfo.o \
-	$(top_srcdir)/src/backend/nodes/bitmapset.o \
-        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
-        $(top_srcdir)/src/backend/nodes/list.o \
-        $(top_srcdir)/src/backend/parser/gram.o \
-        $(top_srcdir)/src/backend/regex/regcomp.o \
-        $(top_srcdir)/src/backend/regex/regerror.o \
-        $(top_srcdir)/src/backend/regex/regexec.o \
-        $(top_srcdir)/src/backend/regex/regfree.o \
-        $(top_srcdir)/src/backend/storage/page/itemptr.o \
-	$(top_srcdir)/src/backend/utils/adt/datum.o \
-        $(top_srcdir)/src/backend/utils/adt/like.o \
-        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
-        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
-        $(top_srcdir)/src/backend/utils/misc/guc.o \
-        $(top_srcdir)/src/backend/utils/init/globals.o \
-        $(top_srcdir)/src/port/exec.o \
-        $(top_srcdir)/src/port/path.o \
-        $(top_srcdir)/src/port/pgsleep.o \
-        $(top_srcdir)/src/port/pgstrcasecmp.o \
-        $(top_srcdir)/src/port/qsort.o \
-        $(top_srcdir)/src/port/strlcpy.o \
-        $(top_srcdir)/src/port/thread.o \
-        $(top_srcdir)/src/timezone/localtime.o \
-        $(top_srcdir)/src/timezone/pgtz.o
-
-nodeShareInputScan_REAL_OBJS=\
-        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
-        $(top_srcdir)/src/backend/access/transam/filerepdefs.o \
-        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
-        $(top_srcdir)/src/backend/lib/stringinfo.o \
-	$(top_srcdir)/src/backend/nodes/bitmapset.o \
-        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
-        $(top_srcdir)/src/backend/nodes/list.o \
-        $(top_srcdir)/src/backend/parser/gram.o \
-        $(top_srcdir)/src/backend/regex/regcomp.o \
-        $(top_srcdir)/src/backend/regex/regerror.o \
-        $(top_srcdir)/src/backend/regex/regexec.o \
-        $(top_srcdir)/src/backend/regex/regfree.o \
-        $(top_srcdir)/src/backend/storage/page/itemptr.o \
-	$(top_srcdir)/src/backend/utils/adt/datum.o \
-        $(top_srcdir)/src/backend/utils/adt/like.o \
-        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
-        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
-        $(top_srcdir)/src/backend/utils/misc/guc.o \
-        $(top_srcdir)/src/backend/utils/init/globals.o \
-        $(top_srcdir)/src/port/exec.o \
-        $(top_srcdir)/src/port/path.o \
-        $(top_srcdir)/src/port/pgsleep.o \
-        $(top_srcdir)/src/port/pgstrcasecmp.o \
-        $(top_srcdir)/src/port/qsort.o \
-        $(top_srcdir)/src/port/strlcpy.o \
-        $(top_srcdir)/src/port/thread.o \
-        $(top_srcdir)/src/timezone/localtime.o \
-        $(top_srcdir)/src/timezone/pgtz.o
-
-execAmi_REAL_OBJS=\
-        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
-        $(top_srcdir)/src/backend/access/transam/filerepdefs.o \
-        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
-        $(top_srcdir)/src/backend/lib/stringinfo.o \
-        $(top_srcdir)/src/backend/nodes/bitmapset.o \
-        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
-        $(top_srcdir)/src/backend/nodes/list.o \
-        $(top_srcdir)/src/backend/parser/gram.o \
-        $(top_srcdir)/src/backend/regex/regcomp.o \
-        $(top_srcdir)/src/backend/regex/regerror.o \
-        $(top_srcdir)/src/backend/regex/regexec.o \
-        $(top_srcdir)/src/backend/regex/regfree.o \
-        $(top_srcdir)/src/backend/storage/page/itemptr.o \
-        $(top_srcdir)/src/backend/utils/adt/datum.o \
-        $(top_srcdir)/src/backend/utils/adt/like.o \
-        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
-        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
-        $(top_srcdir)/src/backend/utils/misc/guc.o \
-        $(top_srcdir)/src/backend/utils/init/globals.o \
-        $(top_srcdir)/src/port/exec.o \
-        $(top_srcdir)/src/port/path.o \
-        $(top_srcdir)/src/port/pgsleep.o \
-        $(top_srcdir)/src/port/pgstrcasecmp.o \
-        $(top_srcdir)/src/port/qsort.o \
-        $(top_srcdir)/src/port/strlcpy.o \
-        $(top_srcdir)/src/port/thread.o \
-        $(top_srcdir)/src/timezone/localtime.o \
-        $(top_srcdir)/src/timezone/pgtz.o
-
-execWorkfile_REAL_OBJS=\
-        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
-        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
-        $(top_srcdir)/src/backend/lib/stringinfo.o \
-	$(top_srcdir)/src/backend/nodes/bitmapset.o \
-        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
-        $(top_srcdir)/src/backend/nodes/list.o \
-        $(top_srcdir)/src/backend/parser/gram.o \
-        $(top_srcdir)/src/backend/regex/regcomp.o \
-        $(top_srcdir)/src/backend/regex/regerror.o \
-        $(top_srcdir)/src/backend/regex/regexec.o \
-        $(top_srcdir)/src/backend/regex/regfree.o \
-        $(top_srcdir)/src/backend/storage/page/itemptr.o \
-	$(top_srcdir)/src/backend/utils/adt/datum.o \
-        $(top_srcdir)/src/backend/utils/adt/like.o \
-        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
-        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
-        $(top_srcdir)/src/backend/utils/misc/guc.o \
-        $(top_srcdir)/src/backend/utils/init/globals.o \
-        $(top_srcdir)/src/port/exec.o \
-        $(top_srcdir)/src/port/path.o \
-        $(top_srcdir)/src/port/pgsleep.o \
-        $(top_srcdir)/src/port/pgstrcasecmp.o \
-        $(top_srcdir)/src/port/qsort.o \
-        $(top_srcdir)/src/port/strlcpy.o \
-        $(top_srcdir)/src/port/thread.o \
-        $(top_srcdir)/src/timezone/localtime.o \
-        $(top_srcdir)/src/timezone/pgtz.o
-
-execHHashagg_REAL_OBJS=\
-        $(top_srcdir)/src/backend/access/hash/hashfunc.o \
-        $(top_srcdir)/src/backend/bootstrap/bootparse.o \
-	$(top_srcdir)/src/backend/executor/execUtils.o \
-        $(top_srcdir)/src/backend/lib/stringinfo.o \
-	$(top_srcdir)/src/backend/nodes/bitmapset.o \
-        $(top_srcdir)/src/backend/nodes/equalfuncs.o \
-        $(top_srcdir)/src/backend/nodes/list.o \
-        $(top_srcdir)/src/backend/parser/gram.o \
-        $(top_srcdir)/src/backend/regex/regcomp.o \
-        $(top_srcdir)/src/backend/regex/regerror.o \
-        $(top_srcdir)/src/backend/regex/regexec.o \
-        $(top_srcdir)/src/backend/regex/regfree.o \
-        $(top_srcdir)/src/backend/storage/page/itemptr.o \
-	$(top_srcdir)/src/backend/utils/adt/datum.o \
-        $(top_srcdir)/src/backend/utils/adt/like.o \
-        $(top_srcdir)/src/backend/utils/hash/dynahash.o \
-        $(top_srcdir)/src/backend/utils/hash/hashfn.o \
-        $(top_srcdir)/src/backend/utils/misc/guc.o \
-        $(top_srcdir)/src/backend/utils/init/globals.o \
-        $(top_srcdir)/src/port/exec.o \
-        $(top_srcdir)/src/port/path.o \
-        $(top_srcdir)/src/port/pgsleep.o \
-        $(top_srcdir)/src/port/pgstrcasecmp.o \
-        $(top_srcdir)/src/port/qsort.o \
-        $(top_srcdir)/src/port/strlcpy.o \
-        $(top_srcdir)/src/port/thread.o \
-        $(top_srcdir)/src/timezone/localtime.o \
-        $(top_srcdir)/src/timezone/pgtz.o
-
-include ../../../Makefile.mock
-

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test_discard/execAmi_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test_discard/execAmi_test.c b/src/backend/executor/test_discard/execAmi_test.c
deleted file mode 100644
index 9947104..0000000
--- a/src/backend/executor/test_discard/execAmi_test.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include "cmockery.h"
-
-#include "c.h"
-#include "postgres.h"
-#include "nodes/nodes.h"
-
-#include "../execAmi.c"
-
-/* ==================== ExecEagerFree ==================== */
-/*
- * Tests that ExecEageFree calls the new ExecEagerFreeShareInputScan
- * function when the input is a ShareInputScanState
- */
-void
-test__ExecEagerFree_ExecEagerFreeShareInputScan(void **state)
-{
-	ShareInputScanState *sisc = makeNode(ShareInputScanState);
-
-	expect_value(ExecEagerFreeShareInputScan, node, sisc);
-	will_be_called(ExecEagerFreeShareInputScan);
-
-	ExecEagerFree(sisc);
-}
-
-int
-main(int argc, char* argv[])
-{
-        cmockery_parse_arguments(argc, argv);
-
-        const UnitTest tests[] = {
-                        unit_test(test__ExecEagerFree_ExecEagerFreeShareInputScan)
-        };
-        return run_tests(tests);
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test_discard/execHHashagg_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test_discard/execHHashagg_test.c b/src/backend/executor/test_discard/execHHashagg_test.c
deleted file mode 100644
index 0972ad9..0000000
--- a/src/backend/executor/test_discard/execHHashagg_test.c
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include "cmockery.h"
-
-#include "c.h"
-#include "postgres.h"
-
-/* Ignore elog */
-#include "utils/elog.h"
-#undef elog
-#define elog
-
-
-/* Provide specialized mock implementations for memory allocation functions */
-
-#undef palloc
-#define palloc getSpillFile_palloc_mock
-void *getSpillFile_palloc_mock(Size size);
-
-#include "../execHHashagg.c"
-
-
-/*
- * This is a mocked version of palloc to be used in getSpillFile().
- * It returns allocated memory padded with 0x7f pattern.
- */
-void *
-getSpillFile_palloc_mock(Size size)
-{
- void *ptr = MemoryContextAlloc(CurrentMemoryContext, size);
- MemSetAligned(ptr, 0x7f, size);
- return ptr; 
-}
-
-
-/* ==================== getSpillFile ==================== */
-/*
- * Test that the spill_file->file_info->wfile field is allocated 
- * and initialized during normal execution (no exception thrown).
- */
-void
-test__getSpillFile__Initialize_wfile_success(void **state)
-{
-  int alloc_size = 0; 
-  int file_no = 0;
-  int branching_factor = 32; 
-  ExecWorkFile *ewfile = (ExecWorkFile *) palloc0(sizeof(ExecWorkFile)); 
-  workfile_set *work_set = (workfile_set *) palloc0(sizeof(workfile_set)); 
-  SpillSet *spill_set = (SpillSet *) palloc0(sizeof(SpillSet) + (branching_factor-1) * sizeof (SpillFile));
-
-  SpillFile *spill_file = &spill_set->spill_files[file_no];
-  spill_file->file_info = NULL; 
-
-  expect_value(workfile_mgr_create_file, work_set, work_set);
-  will_return(workfile_mgr_create_file, ewfile); 
-  
-  getSpillFile(work_set, spill_set, file_no, &alloc_size); 
-
-  assert_true(spill_file->file_info != NULL); 
-  assert_int_equal(spill_file->file_info->total_bytes, 0); 
-  assert_int_equal(spill_file->file_info->ntuples, 0); 
-  assert_int_equal(alloc_size, BATCHFILE_METADATA);
-
-  /*
-   * During normal execution, wfile should be initialized with 
-   * the result of workfile_mgr_create_wfile, a valid ExecWorkFile pointer
-   */ 
-  assert_true(spill_file->file_info->wfile == ewfile); 
-}
-
-/*
- * Function used a side effect to simulate throwing exception 
- * by a certain function. 
- */
-void
-throw_exception_side_effect()
-{
-  PG_RE_THROW();
-}
-
-/* ==================== getSpillFile ==================== */
-/*
- * Test that the spill_file->file_info->wfile field is initialized to NULL 
- * when creating a workfile throws an exception. 
- */
-void
-test__getSpillFile__Initialize_wfile_exception(void **state)
-{
-
-  int alloc_size = 0; 
-  int file_no = 0;
-  int branching_factor = 32; 
-  ExecWorkFile *ewfile = (ExecWorkFile *) palloc0(sizeof(ExecWorkFile)); 
-  workfile_set *work_set = (workfile_set *) palloc0(sizeof(workfile_set)); 
-  SpillSet *spill_set = (SpillSet *) palloc0(sizeof(SpillSet) + (branching_factor-1) * sizeof (SpillFile));
-
-  SpillFile *spill_file = &spill_set->spill_files[0];
-  spill_file->file_info = NULL; 
-
-  /* Make workfile_mgr_create_file throw an exception, using the side effect function */ 
-  expect_value(workfile_mgr_create_file, work_set, work_set);
-  will_return_with_sideeffect(workfile_mgr_create_file, ewfile, &throw_exception_side_effect, NULL); 
-  
-  PG_TRY(); 
-  {
-    
-    /* This function will throw an exception, and we'll catch it below */
-    getSpillFile(work_set, spill_set, file_no, &alloc_size); 
-
-  }
-  PG_CATCH(); 
-  {
-    assert_true(spill_file->file_info != NULL); 
-    assert_int_equal(spill_file->file_info->total_bytes, 0); 
-    assert_int_equal(spill_file->file_info->ntuples, 0); 
-    assert_int_equal(alloc_size, 0);
-
-    /* 
-     * This is the main test: We must initialize this pointer to NULL, even 
-     * if an exception is thrown
-     */
-    assert_true(spill_file->file_info->wfile == NULL); 
-    return; 
-  }
-  PG_END_TRY(); 
-
-  /* We shouldn't get here, the getSpillFile should throw an exception */ 
-  assert_true(false);
-
-}
-
-/* ==================== main ==================== */
-int
-main(int argc, char* argv[])
-{
-    cmockery_parse_arguments(argc, argv);
-
-    const UnitTest tests[] = {
-      unit_test(test__getSpillFile__Initialize_wfile_success),
-      unit_test(test__getSpillFile__Initialize_wfile_exception)
-                             };
-
-    return run_tests(tests);
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test_discard/execWorkfile_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test_discard/execWorkfile_test.c b/src/backend/executor/test_discard/execWorkfile_test.c
deleted file mode 100644
index 9d95a1f..0000000
--- a/src/backend/executor/test_discard/execWorkfile_test.c
+++ /dev/null
@@ -1,101 +0,0 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include "cmockery.h"
-
-#include "c.h"
-#include "postgres.h"
-#include "storage/buffile.h"
-#include "storage/bfz.h"
-#include "executor/execWorkfile.h"
-#include "utils/memutils.h"
-
-/* Ignore elog */
-#include "utils/elog.h"
-
-#undef elog
-#define elog
-
-/* Provide specialized mock implementations for memory allocation functions */
-#undef palloc0
-#define palloc0 execWorkfile_palloc0_mock
-void *execWorkfile_palloc0_mock(Size size);
-
-#undef pstrdup
-#define pstrdup execWorkfile_pstrdup_mock
-char *execWorkfile_pstrdup_mock(const char *string);
-
-#include "../execWorkfile.c"
-
-/*
- * This is a mocked version of palloc0 to be used in ExecWorkFile_Create.
- *   It asserts that it is executed in the TopMemoryContext.
- */
-void *
-execWorkfile_palloc0_mock(Size size)
-{
-	assert_int_equal(CurrentMemoryContext, TopMemoryContext);
-	return MemoryContextAllocZero(CurrentMemoryContext, size);
-}
-
-/*
- * This is a mocked version of pstrdup to be used in ExecWorkFile_Create.
- *   It asserts that it is executed in the TopMemoryContext.
- */
-char *execWorkfile_pstrdup_mock(const char *string)
-{
-	assert_int_equal(CurrentMemoryContext, TopMemoryContext);
-	return MemoryContextStrdup(CurrentMemoryContext, string);
-}
-
-
-/* ==================== ExecWorkFile_Create ==================== */
-/*
- * Test that the ExecWorkFile struct is allocated in TopMemoryContext
- */
-void
-test__ExecWorkFile_Create__InTopMemContext(void **state)
-{
-
-	char *test_filename = "foo";
-
-	will_return(WorkfileQueryspace_AddWorkfile, true);
-
-	expect_value(BufFileCreateFile, fileName, test_filename);
-	expect_value(BufFileCreateFile, delOnClose, true);
-	expect_value(BufFileCreateFile, interXact, false);
-	will_return(BufFileCreateFile, NULL);
-
-	expect_value(BufFileSetWorkfile, buffile, NULL);
-	will_be_called(BufFileSetWorkfile);
-
-	/*
-	 * All the memory context stuff is mocked, so the TopMemoryContext is NULL
-	 * at this point. Set it to something specific so we can distinguish it from
-	 * the CurrentMemoryContext.
-	 */
-	TopMemoryContext = (MemoryContext) 0xdeadbeef;
-	CurrentMemoryContext = (MemoryContext) 0xfeadbead;
-
-	/*
-	 * ExecWorkFile_Create will call our mocked palloc0 function execWorkfile__palloc0_mock
-	 * and our mocked pstrdup function execWorkfile_pstrdup_mock.
-	 * These functions will assert that the allocation of the result happens
-	 * in the TopMemoryContext.
-	 */
-	ExecWorkFile *ewf = ExecWorkFile_Create(test_filename, BUFFILE, true /* delOnClose */, 0 /* compressType */);
-
-}
-
-/* ==================== main ==================== */
-int
-main(int argc, char* argv[])
-{
-    cmockery_parse_arguments(argc, argv);
-
-    const UnitTest tests[] = {
-                                 unit_test(test__ExecWorkFile_Create__InTopMemContext)
-                             };
-
-    return run_tests(tests);
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test_discard/nodeShareInputScan_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test_discard/nodeShareInputScan_test.c b/src/backend/executor/test_discard/nodeShareInputScan_test.c
deleted file mode 100644
index 7bb8b92..0000000
--- a/src/backend/executor/test_discard/nodeShareInputScan_test.c
+++ /dev/null
@@ -1,102 +0,0 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include "cmockery.h"
-
-#include "c.h"
-#include "postgres.h"
-#include "nodes/nodes.h"
-#include "../nodeShareInputScan.c"
-
-#define FIXED_POINTER_VAL ((LargestIntegralType) 0x0000beef)
-#define SHARE_NODE_ENTRY_REFCOUNT 78
-
-/*
- * Tests ExecEagerFreeShareInputScan when plan->share_type = SHARE_NOTSHARED
- * Verifies that all the pointers are set to NULL
- */
-void
-test__ExecEagerFreeShareInputScan_SHARE_NOTSHARED(void **state)
-{
-	ShareInputScanState *sisc = makeNode(ShareInputScanState);
-	ShareInputScan *plan = makeNode(ShareInputScan);
-	sisc->ss.ps.plan = plan;
-
-	sisc->ts_markpos = FIXED_POINTER_VAL;
-	sisc->ts_pos = FIXED_POINTER_VAL;
-	sisc->ts_state = FIXED_POINTER_VAL;
-	sisc->freed = false;
-
-	plan->share_type = SHARE_NOTSHARED;
-
-	ExecEagerFreeShareInputScan(sisc);
-
-	assert_int_equal(sisc->ts_markpos, NULL);
-	assert_int_equal(sisc->ts_pos, NULL);
-	assert_int_equal(sisc->ts_state, NULL);
-	assert_true(sisc->freed);
-
-	return;
-}
-
-/* ==================== ExecEagerFreeShareInputScan ==================== */
-/*
- * Tests ExecEagerFreeShareInputScan when plan->share_type = SHARE_MATERIAL
- * Verifies that the tuplestore accessor and the tuplestore state are destroyed,
- * and that all the pointers are set to NULL
- */
-void
-test__ExecEagerFreeShareInputScan_SHARE_MATERIAL(void **state)
-{
-	ShareInputScanState *sisc = makeNode(ShareInputScanState);
-	ShareInputScan *plan = makeNode(ShareInputScan);
-	sisc->ss.ps.plan = plan;
-
-	sisc->ts_markpos = NULL;
-	sisc->ts_pos = FIXED_POINTER_VAL;
-	sisc->ts_state = (GenericTupStore *) palloc0(sizeof(GenericTupStore));
-	sisc->ts_state->matstore = FIXED_POINTER_VAL;
-	sisc->freed = false;
-
-	plan->share_type = SHARE_MATERIAL;
-
-	expect_value(ntuplestore_destroy_accessor, acc, FIXED_POINTER_VAL);
-	will_be_called(ntuplestore_destroy_accessor);
-
-	expect_value(ntuplestore_is_readerwriter_reader, nts, FIXED_POINTER_VAL);
-	will_return(ntuplestore_is_readerwriter_reader, true);
-
-	expect_value(ntuplestore_destroy, ts, FIXED_POINTER_VAL);
-	will_be_called(ntuplestore_destroy);
-
-
-	ShareNodeEntry *shareNodeEntry = makeNode(ShareNodeEntry);
-	shareNodeEntry->refcount = SHARE_NODE_ENTRY_REFCOUNT;
-
-	expect_any(ExecGetShareNodeEntry, estate);
-	expect_any(ExecGetShareNodeEntry, shareidx);
-	expect_value(ExecGetShareNodeEntry, fCreate, false);
-	will_return(ExecGetShareNodeEntry, shareNodeEntry);
-
-	ExecEagerFreeShareInputScan(sisc);
-
-	assert_int_equal(sisc->ts_markpos, NULL);
-	assert_int_equal(sisc->ts_pos, NULL);
-	assert_int_equal(sisc->ts_state, NULL);
-	assert_int_equal(shareNodeEntry->refcount, SHARE_NODE_ENTRY_REFCOUNT - 1);
-	assert_true(sisc->freed);
-
-	return;
-}
-
-int
-main(int argc, char* argv[])
-{
-        cmockery_parse_arguments(argc, argv);
-
-        const UnitTest tests[] = {
-                        unit_test(test__ExecEagerFreeShareInputScan_SHARE_NOTSHARED),
-                        unit_test(test__ExecEagerFreeShareInputScan_SHARE_MATERIAL)
-        };
-        return run_tests(tests);
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04c0f28b/src/backend/executor/test_discard/nodeSubplan_test.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/test_discard/nodeSubplan_test.c b/src/backend/executor/test_discard/nodeSubplan_test.c
deleted file mode 100644
index 9e6aa0b..0000000
--- a/src/backend/executor/test_discard/nodeSubplan_test.c
+++ /dev/null
@@ -1,159 +0,0 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include "cmockery.h"
-
-#include "c.h"
-#include "postgres.h"
-#include "nodes/nodes.h"
-#include "../nodeSubplan.c"
-
-/* Function passed to testing framework
- * in order to force SetupInterconnect to fail */ 
-void
-_RETHROW( )
-{
-	PG_RE_THROW();
-}
-
-
-/* Checks CdbCheckDispatchResult is called when queryDesc
- * is not null (when shouldDispatch is true).
- * This test falls in PG_CATCH when SetupInterconnect
- * does not allocate queryDesc->estate->interconnect_context.
- * The test is successful if the */
-void 
-test__ExecSetParamPlan__Check_Dispatch_Results(void **state) 
-{
-
-	/*Set plan to explain.*/
-	SubPlanState *plan = makeNode(SubPlanState);
-	plan->xprstate.expr = makeNode(SubPlanState);
-	plan->planstate = makeNode(SubPlanState);
-	plan->planstate->instrument = (Instrumentation *)palloc(sizeof(Instrumentation));
-	plan->planstate->plan = makeNode(SubPlanState);
-	
-	/*Function needed for estate.*/
-	expect_any(AllocSetContextCreate,parent);
-	expect_any(AllocSetContextCreate,name);
-	expect_any(AllocSetContextCreate,minContextSize);
-	expect_any(AllocSetContextCreate,initBlockSize);
-	expect_any(AllocSetContextCreate,maxBlockSize);
-	will_be_called(AllocSetContextCreate);	
-	EState *estate = CreateExecutorState();
-
-	/*Assign mocked estate to plan.*/
-	((PlanState *)(plan->planstate))->state= estate;
-
-	/*Function needed for GetPerTupleExprContext*/
-	expect_any(AllocSetContextCreate,parent);
-	expect_any(AllocSetContextCreate,name);
-	expect_any(AllocSetContextCreate,minContextSize);
-	expect_any(AllocSetContextCreate,initBlockSize);
-	expect_any(AllocSetContextCreate,maxBlockSize);
-	will_be_called(AllocSetContextCreate);
-
-	/*Re-use estate mocked object. Needed as input parameter for
-	tested function */
-	ExprContext *econtext = GetPerTupleExprContext(estate);
-
-
-	/*Set QueryDescriptor input parameter for tested function */
-	PlannedStmt   *plannedstmt = (PlannedStmt *)palloc(sizeof(PlannedStmt));
-	QueryDesc *queryDesc = (QueryDesc *)palloc(sizeof(QueryDesc));
-	queryDesc->plannedstmt = plannedstmt;
-	queryDesc->estate = (EState *)palloc(sizeof(EState));
-	queryDesc->estate->es_sliceTable = (SliceTable *) palloc(sizeof(SliceTable));
-	
-	/*Set of functions called within tested function*/
-	expect_any(MemoryContextGetPeakSpace,context);
-	will_be_called(MemoryContextGetPeakSpace);
-
-	expect_any(MemoryContextSetPeakSpace,context);
-	expect_any(MemoryContextSetPeakSpace,nbytes);
-	will_be_called(MemoryContextSetPeakSpace);
-
-	/*QueryDescriptor generated when shouldDispatch is true.*/
-	QueryDesc *internalQueryDesc = (QueryDesc *)palloc(sizeof(QueryDesc));
-	internalQueryDesc->estate = (EState *)palloc(sizeof(EState));
-	/* Added to force assertion on queryDesc->estate->interconnect_context;
-	to fail */
-	internalQueryDesc->estate->interconnect_context=NULL;
-	internalQueryDesc->estate->es_sliceTable = (SliceTable *) palloc(sizeof(SliceTable));
-
-	expect_any(CreateQueryDesc,plannedstmt);
-	expect_any(CreateQueryDesc,sourceText);
-	expect_any(CreateQueryDesc,snapshot);
-	expect_any(CreateQueryDesc,crosscheck_snapshot);
-	expect_any(CreateQueryDesc,dest);
-	expect_any(CreateQueryDesc,params);
-	expect_any(CreateQueryDesc,doInstrument);
-	will_return(CreateQueryDesc,internalQueryDesc);
-	
-	expect_any(AllocSetContextCreate,parent);
-	expect_any(AllocSetContextCreate,name);
-	expect_any(AllocSetContextCreate,minContextSize);
-	expect_any(AllocSetContextCreate,initBlockSize);
-	expect_any(AllocSetContextCreate,maxBlockSize);
-	will_be_called(AllocSetContextCreate);
-
-	Gp_role = GP_ROLE_DISPATCH;
-	plan->planstate->plan->dispatch=DISPATCH_PARALLEL;
-
-	will_be_called(isCurrentDtxTwoPhase);
-
-	expect_any(cdbdisp_dispatchPlan,queryDesc);
-	expect_any(cdbdisp_dispatchPlan,planRequiresTxn);
-	expect_any(cdbdisp_dispatchPlan,cancelOnError);
-	expect_any(cdbdisp_dispatchPlan,ds);
-	will_be_called(cdbdisp_dispatchPlan);
-
-	expect_any(SetupInterconnect,estate);
-	/* Force SetupInterconnect to fail */
-	will_be_called_with_sideeffect(SetupInterconnect,&_RETHROW,NULL);
-
-
-	expect_any(cdbexplain_localExecStats,planstate);
-	expect_any(cdbexplain_localExecStats,showstatctx);
-	will_be_called(cdbexplain_localExecStats);
-
-	expect_any(CdbCheckDispatchResult,ds);
-	expect_any(CdbCheckDispatchResult,cancelUnfinishedWork);
-	will_be_called(CdbCheckDispatchResult);
-
-	expect_any(cdbexplain_recvExecStats,planstate);
-	expect_any(cdbexplain_recvExecStats,dispatchResults);
-	expect_any(cdbexplain_recvExecStats,sliceIndex);
-	expect_any(cdbexplain_recvExecStats,showstatctx);
-	will_be_called(cdbexplain_recvExecStats);
-
-	expect_any(MemoryContextSetPeakSpace,context);
-	expect_any(MemoryContextSetPeakSpace,nbytes);
-	will_be_called(MemoryContextSetPeakSpace);
-
-	will_be_called(TeardownSequenceServer);
-
-	expect_any(TeardownInterconnect,transportStates);
-	expect_any(TeardownInterconnect,mlStates);
-	expect_any(TeardownInterconnect,forceEOS);
-	will_be_called(TeardownInterconnect);
-
-	/* Catch PG_RE_THROW(); after cleaning with CdbCheckDispatchResult */
-	PG_TRY();
-		ExecSetParamPlan(plan,econtext,queryDesc);
-	PG_CATCH();
-		assert_true(true);
-	PG_END_TRY();
-}
-
-int 
-main(int argc, char* argv[]) 
-{
-        cmockery_parse_arguments(argc, argv);
-        
-        const UnitTest tests[] = {
-                        unit_test(test__ExecSetParamPlan__Check_Dispatch_Results)
-        };
-        return run_tests(tests);
-}
-