Fix: remove qingcloud platform-specific unit-tests
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 2ee3fbe..d3aafc0 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -7,7 +7,6 @@
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
-
permissions:
id-token: write
contents: read
diff --git a/src/backend/cdb/test/Makefile b/src/backend/cdb/test/Makefile
index 4e43c27..6a33e5d 100644
--- a/src/backend/cdb/test/Makefile
+++ b/src/backend/cdb/test/Makefile
@@ -6,8 +6,6 @@
TARGETS += cdbappendonlyxlog
-TARGETS += cdbutils
-
# There are some functions both defined in src/backend/storage/file/fd.c
# and libpgcommon.a which contains object files with FRONTEND defined,
# for use by client applications.
@@ -26,11 +24,3 @@
$(MOCK_DIR)/backend/access/transam/xlogutils_mock.o \
$(MOCK_DIR)/backend/access/hash/hash_mock.o \
$(MOCK_DIR)/backend/utils/fmgr/fmgr_mock.o
-
-cdbutils.t: \
- $(MOCK_DIR)/backend/storage/lmgr/lwlock_mock.o \
- $(MOCK_DIR)/backend/catalog/namespace_mock.o \
- $(MOCK_DIR)/backend/access/table/table_mock.o \
- $(MOCK_DIR)/backend/access/hash/hash_mock.o \
- $(MOCK_DIR)/backend/utils/fmgr/fmgr_mock.o \
- $(MOCK_DIR)/backend/storage/ipc/shmem_mock.o
\ No newline at end of file
diff --git a/src/backend/cdb/test/cdbutils_test.c b/src/backend/cdb/test/cdbutils_test.c
deleted file mode 100644
index 693d0dc..0000000
--- a/src/backend/cdb/test/cdbutils_test.c
+++ /dev/null
@@ -1,609 +0,0 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include "cmockery.h"
-#include "cdb/cdbutil.h"
-#include "utils/etcd.h"
-#include "utils/memutils.h"
-#include "storage/lockdefs.h"
-#include "storage/lwlock.h"
-#include "common/etcdutils.h"
-
-#ifndef USE_INTERNAL_FTS
-
-static MemoryContext testMemoryContext = NULL;
-
-static
-void expect_heap_open_and_close(void) {
- expect_string_count(RelnameGetRelid, relname, GpSegmentConfigRelationName, -1);
- will_return_count(RelnameGetRelid, 1, -1);
-
- expect_value_count(table_open, relationId, 1, -1);
- expect_value_count(table_open, lockmode, AccessShareLock, -1);
- will_return_count(table_open, NULL, -1);
-
- expect_any_count(table_close, relation, -1);
- expect_value_count(table_close, lockmode, NoLock, -1);
- will_be_called_count(table_close, -1);
-}
-
-static
-void expect_lock_acquire_and_release(void) {
- expect_value_count(LWLockAcquire, lock, CdbConfigCacheLock, -1);
- expect_value_count(LWLockAcquire, mode, LW_EXCLUSIVE, -1);
- will_return_count(LWLockAcquire, true, -1);
-
- expect_value_count(LWLockRelease, lock, CdbConfigCacheLock, -1);
- will_be_called_count(LWLockRelease, -1);
-}
-
-static void enable_segment_cache() {
- gp_etcd_enable_cache = true;
-}
-
-static void disable_segment_cache() {
- gp_etcd_enable_cache = false;
-}
-
-static void clean_segments_with_cache() {
- enable_segment_cache();
- cleanSegments();
- disable_segment_cache();
-}
-
-static void
-SetupDataStructures(void **state)
-{
- GpSegConfigEntry *config_cached = NULL;
-
- if (NULL == TopMemoryContext)
- {
- assert_true(NULL == testMemoryContext);
- MemoryContextInit();
-
- testMemoryContext = AllocSetContextCreate(TopMemoryContext,
- "Test Context",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
-
- MemoryContextSwitchTo(testMemoryContext);
-
- TopMemoryContext = testMemoryContext;
- }
-
- // Init global etcd config
- char *endpoints = GP_ETCD_TEST_SINGLE_ENDPOINTS;
- gp_etcd_endpoints = strdup(endpoints);
- gp_etcd_account_id = GP_ETCD_ACCOUNT_ID_DEFAULT;
- gp_etcd_cluster_id = GP_ETCD_CLUSTER_ID_DEFAULT;
- gp_etcd_namespace = GP_ETCD_NAMESPACE_DEFAULT;
- assert_true(NULL != testMemoryContext &&
- CurrentMemoryContext == testMemoryContext);
-
- int total_dbs = 0;
- expect_lock_acquire_and_release();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
-
- if (total_dbs != 0) {
- expect_heap_open_and_close();
- clean_segments_with_cache();
- }
-
- if (config_cached) {
- pfree(config_cached);
- config_cached = NULL;
- }
-}
-
-/*
- * cleans up memory by reseting testMemoryContext
- */
-static void
-TeardownDataStructures(void **state)
-{
- expect_lock_acquire_and_release();
- expect_heap_open_and_close();
- clean_segments_with_cache();
- if (gp_etcd_endpoints) {
- free(gp_etcd_endpoints);
- gp_etcd_endpoints = NULL;
- }
-}
-
-void * cache_mem = NULL;
-
-static void
-test_cdb_utils_init_cache(void **state)
-{
- /* init cache */
- cache_mem = malloc(ShmemSegmentConfigsCacheSize());
- memset(cache_mem, 0, ShmemSegmentConfigsCacheSize());
-
- expect_value(ShmemAlloc, size, ShmemSegmentConfigsCacheSize());
- will_return(ShmemAlloc, cache_mem);
-
- ShmemSegmentConfigsCacheAllocation();
- enable_segment_cache();
- assert_true(isSegmentConfigsCacheEnable());
-
- /* disable cache and check */
- disable_segment_cache();
- assert_false(isSegmentConfigsCacheEnable());
- assert_false(isSegmentConfigsCached());
-}
-
-static void
-test_cdb_utils_segment_ops(void **state)
-{
- GpSegConfigEntry *config_cached = NULL;
- int total_dbs = 0;
-
- disable_segment_cache();
- expect_heap_open_and_close();
- expect_lock_acquire_and_release();
-
- /* make sure env is clean */
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 0);
- assert_true(config_cached == NULL);
-
- /* add segment-1 */
- GpSegConfigEntry config_entry;
- config_entry.dbid = 1;
- config_entry.segindex = 0;
- config_entry.role = GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY;
- config_entry.preferred_role = GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY;
- config_entry.status = GP_SEGMENT_CONFIGURATION_STATUS_UP;
- config_entry.mode = GP_SEGMENT_CONFIGURATION_MODE_INSYNC;
- config_entry.port = 10000;
- config_entry.address = "localhost";
- config_entry.hostname = "localhost";
- config_entry.datadir = "null";
-
- addSegment(&config_entry);
-
- /* read segment configuration cache and check */
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_int_equal(config_cached[0].dbid, config_entry.dbid);
- assert_string_equal(config_cached[0].datadir, config_entry.datadir);
- pfree(config_cached);
-
- /* rewrite segment-1 and segment-2 */
- rewriteSegments("1 0 p p n d 10000 localhost localhost datadir1\n"\
- "2 0 m m n u 10001 localhost localhost datadir2\n", true);
-
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_int_equal(config_cached[0].dbid, 1);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_int_equal(config_cached[1].dbid, 2);
- assert_string_equal(config_cached[1].datadir, "datadir2");
- pfree(config_cached);
-
- /* delete segment-2 */
- delSegment(2);
-
- /* read segment configuration cache and check */
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_int_equal(config_cached[0].dbid, 1);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_NOTINSYNC);
- assert_true(config_cached[0].status == GP_SEGMENT_CONFIGURATION_STATUS_DOWN);
- pfree(config_cached);
-
- /* update segment mode and check cache have been updated */
- updateSegmentModeStatus(1, GP_SEGMENT_CONFIGURATION_MODE_INSYNC, GP_SEGMENT_CONFIGURATION_STATUS_UP);
-
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_int_equal(config_cached[0].dbid, 1);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_INSYNC);
- assert_true(config_cached[0].status == GP_SEGMENT_CONFIGURATION_STATUS_UP);
- pfree(config_cached);
-
- /* rewrite segment-51 segment-52 and make sure cache have been updated */
- rewriteSegments("51 -1 p p n u 10000 localhost localhost datadir1\n" \
- "52 -1 m m n u 10001 localhost localhost datadir2\n", true);
- activateStandby(52, 51);
-
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 52);
- assert_true(config_cached[0].role == GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY);
- assert_true(config_cached[0].preferred_role == GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY);
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_NOTINSYNC);
- assert_string_equal(config_cached[0].datadir, "datadir2");
- pfree(config_cached);
-
- /* clean up and check */
- clean_segments_with_cache();
- assert_false(isSegmentConfigsCached());
-}
-
-static void
-test_cdb_utils_segment_cache_add_segment(void **state)
-{
- GpSegConfigEntry *config_cached = NULL;
- char * cached_buff = NULL;
- int total_dbs = 0;
-
- enable_segment_cache();
- expect_heap_open_and_close();
- expect_lock_acquire_and_release();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 0);
- assert_true(config_cached == NULL);
-
- /* add segment-1 */
- GpSegConfigEntry config_entry;
- config_entry.dbid = 1;
- config_entry.segindex = 0;
- config_entry.role = GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY;
- config_entry.preferred_role = GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY;
- config_entry.status = GP_SEGMENT_CONFIGURATION_STATUS_UP;
- config_entry.mode = GP_SEGMENT_CONFIGURATION_MODE_INSYNC;
- config_entry.port = 10000;
- config_entry.address = "localhost";
- config_entry.hostname = "localhost";
- config_entry.datadir = "null";
-
- addSegment(&config_entry);
-
- /* read segment configuration cache and check */
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(cached_buff != NULL);
- config_cached = readGpSegConfig(cached_buff, &total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached->dbid, config_entry.dbid);
- assert_string_equal(config_cached->datadir, config_entry.datadir);
- pfree(config_cached);
- pfree(cached_buff);
-
- /* disable read configuration from cache and check */
- disable_segment_cache();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(config_cached->dbid, config_entry.dbid);
- assert_string_equal(config_cached->datadir, config_entry.datadir);
- pfree(config_cached);
- enable_segment_cache();
-
-
- /* add segment-100 */
- config_entry.dbid = 100;
- config_entry.datadir = "datadir-100";
- addSegment(&config_entry);
-
- /* read segment configuration cache and check */
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(cached_buff != NULL);
- config_cached = readGpSegConfig(cached_buff, &total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 1);
- assert_string_equal(config_cached[0].datadir, "null");
- assert_int_equal(config_cached[1].dbid, config_entry.dbid);
- assert_string_equal(config_cached[1].datadir, config_entry.datadir);
- pfree(config_cached);
- pfree(cached_buff);
-
- /* disable read from cache and check */
- disable_segment_cache();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_int_equal(config_cached[0].dbid, 1);
- assert_string_equal(config_cached[0].datadir, "null");
- assert_int_equal(config_cached[1].dbid, config_entry.dbid);
- assert_string_equal(config_cached[1].datadir, config_entry.datadir);
- pfree(config_cached);
-
- /* clean up and check */
- clean_segments_with_cache();
- assert_false(isSegmentConfigsCached());
-}
-
-static void
-test_cdb_utils_segment_cache_del_segment(void **state)
-{
- GpSegConfigEntry *config_cached = NULL;
- char * cached_buff = NULL;
- int total_dbs = 0;
-
- disable_segment_cache();
- expect_lock_acquire_and_release();
-
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 0);
-
- enable_segment_cache();
-
- expect_heap_open_and_close();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 0);
- assert_true(config_cached == NULL);
-
- /* rewrite segment-11 segment-21 segment-31 */
- rewriteSegments("11 0 p p n u 10000 localhost localhost datadir1\n" \
- "21 0 m m n u 10001 localhost localhost datadir2\n" \
- "31 0 m m n u 10001 localhost localhost datadir3\n", true);
-
- /* read from etcd cache and check */
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 3);
- assert_true(cached_buff != NULL);
-
- config_cached = readGpSegConfig(cached_buff, &total_dbs);
- assert_int_equal(total_dbs, 3);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 11);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_int_equal(config_cached[1].dbid, 21);
- assert_string_equal(config_cached[1].datadir, "datadir2");
- assert_int_equal(config_cached[2].dbid, 31);
- assert_string_equal(config_cached[2].datadir, "datadir3");
- pfree(cached_buff);
- pfree(config_cached);
-
- /* delete segment-21 */
- delSegment(21);
-
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(cached_buff != NULL);
- config_cached = readGpSegConfig(cached_buff, &total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 11);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_int_equal(config_cached[1].dbid, 31);
- assert_string_equal(config_cached[1].datadir, "datadir3");
- pfree(cached_buff);
- pfree(config_cached);
-
- /* disable read from cache and check */
- disable_segment_cache();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 11);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_int_equal(config_cached[1].dbid, 31);
- assert_string_equal(config_cached[1].datadir, "datadir3");
- pfree(config_cached);
- enable_segment_cache();
-
- /* delete segment-11 */
- delSegment(11);
-
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(cached_buff != NULL);
- config_cached = readGpSegConfig(cached_buff, &total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 31);
- assert_string_equal(config_cached[0].datadir, "datadir3");
- pfree(cached_buff);
- pfree(config_cached);
-
- /* disable read from cache and check */
- disable_segment_cache();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 31);
- assert_string_equal(config_cached[0].datadir, "datadir3");
- pfree(config_cached);
- enable_segment_cache();
-
- /* delete segment-31 */
- delSegment(31);
-
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 0);
- assert_true(cached_buff == NULL);
-
- disable_segment_cache();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 0);
- assert_true(config_cached == NULL);
-
- /* no need clean, cause nothing in ETCD */
- assert_false(isSegmentConfigsCached());
-}
-
-static void
-test_cdb_utils_segment_cache_activate_standby(void **state)
-{
- GpSegConfigEntry *config_cached = NULL;
- char * cached_buff = NULL;
- int total_dbs = 0;
-
- enable_segment_cache();
- expect_heap_open_and_close();
- expect_lock_acquire_and_release();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 0);
- assert_true(config_cached == NULL);
-
- /* rewrite master-51 and standby-52 */
- rewriteSegments("51 -1 p p n u 10000 localhost localhost datadir1\n" \
- "52 -1 m m n u 10001 localhost localhost datadir2\n", true);
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(cached_buff != NULL);
- pfree(cached_buff);
-
- /* do active standby and check */
- activateStandby(52, 51);
-
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(cached_buff != NULL);
- config_cached = readGpSegConfig(cached_buff, &total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 52);
- assert_true(config_cached[0].role == GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY);
- assert_true(config_cached[0].preferred_role == GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY);
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_NOTINSYNC);
- assert_string_equal(config_cached[0].datadir, "datadir2");
- pfree(cached_buff);
- pfree(config_cached);
-
- /* disable read from cache and check */
- disable_segment_cache();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 1);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 52);
- assert_true(config_cached[0].role == GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY);
- assert_true(config_cached[0].preferred_role == GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY);
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_NOTINSYNC);
- assert_string_equal(config_cached[0].datadir, "datadir2");
- pfree(config_cached);
- enable_segment_cache();
-
- /* clean up and check */
- clean_segments_with_cache();
- assert_false(isSegmentConfigsCached());
-
-}
-
-static void
-test_cdb_utils_segment_cache_update_segment_mode_status(void **state)
-{
- GpSegConfigEntry *config_cached = NULL;
- char * cached_buff = NULL;
- int total_dbs = 0;
-
- enable_segment_cache();
- expect_heap_open_and_close();
- expect_lock_acquire_and_release();
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 0);
- assert_true(config_cached == NULL);
-
- /* rewrite segment-1 and segment-2 */
- rewriteSegments("51 4 p p n u 10000 localhost localhost datadir1\n" \
- "52 4 m m s u 10001 localhost localhost datadir2\n", true);
-
- /* update segment mode and check cache have been updated */
- updateSegmentModeStatus(51, GP_SEGMENT_CONFIGURATION_MODE_NOTINSYNC, GP_SEGMENT_CONFIGURATION_STATUS_DOWN);
-
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(cached_buff != NULL);
- config_cached = readGpSegConfig(cached_buff, &total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 51);
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_NOTINSYNC);
- assert_true(config_cached[0].status == GP_SEGMENT_CONFIGURATION_STATUS_DOWN);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_int_equal(config_cached[1].dbid, 52);
- assert_true(config_cached[1].mode == GP_SEGMENT_CONFIGURATION_MODE_INSYNC);
- assert_true(config_cached[1].status == GP_SEGMENT_CONFIGURATION_STATUS_UP);
- assert_string_equal(config_cached[1].datadir, "datadir2");
- pfree(cached_buff);
- pfree(config_cached);
-
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 51);
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_NOTINSYNC);
- assert_true(config_cached[0].status == GP_SEGMENT_CONFIGURATION_STATUS_DOWN);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_int_equal(config_cached[1].dbid, 52);
- assert_true(config_cached[1].mode == GP_SEGMENT_CONFIGURATION_MODE_INSYNC);
- assert_true(config_cached[1].status == GP_SEGMENT_CONFIGURATION_STATUS_UP);
- assert_string_equal(config_cached[1].datadir, "datadir2");
- pfree(config_cached);
-
- updateSegmentModeStatus(51, GP_SEGMENT_CONFIGURATION_MODE_INSYNC, GP_SEGMENT_CONFIGURATION_STATUS_UP);
- cached_buff = readSegmentConfigsCache(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(cached_buff != NULL);
- config_cached = readGpSegConfig(cached_buff, &total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 51);
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_INSYNC);
- assert_true(config_cached[0].status == GP_SEGMENT_CONFIGURATION_STATUS_UP);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_int_equal(config_cached[1].dbid, 52);
- assert_true(config_cached[1].mode == GP_SEGMENT_CONFIGURATION_MODE_INSYNC);
- assert_true(config_cached[1].status == GP_SEGMENT_CONFIGURATION_STATUS_UP);
- assert_string_equal(config_cached[1].datadir, "datadir2");
- pfree(cached_buff);
- pfree(config_cached);
-
- config_cached = readGpSegConfigFromETCDAllowNull(&total_dbs);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(total_dbs, 2);
- assert_true(config_cached != NULL);
- assert_int_equal(config_cached[0].dbid, 51);
- assert_true(config_cached[0].mode == GP_SEGMENT_CONFIGURATION_MODE_INSYNC);
- assert_true(config_cached[0].status == GP_SEGMENT_CONFIGURATION_STATUS_UP);
- assert_string_equal(config_cached[0].datadir, "datadir1");
- assert_int_equal(config_cached[1].dbid, 52);
- assert_true(config_cached[1].mode == GP_SEGMENT_CONFIGURATION_MODE_INSYNC);
- assert_true(config_cached[1].status == GP_SEGMENT_CONFIGURATION_STATUS_UP);
- assert_string_equal(config_cached[1].datadir, "datadir2");
- pfree(config_cached);
-
- clean_segments_with_cache();
- assert_false(isSegmentConfigsCached());
-}
-
-
-int
-main(int argc, char* argv[])
-{
- int rc;
- cmockery_parse_arguments(argc, argv);
-
- disable_segment_cache();
- const UnitTest tests[] = {
- /* test_cdb_utils_init_cache must be first test case
- * other tests will used segment configuration cache which need init in test_cdb_utils_init_cache
- */
- unit_test_setup_teardown(test_cdb_utils_init_cache, SetupDataStructures, TeardownDataStructures),
- unit_test_setup_teardown(test_cdb_utils_segment_ops, SetupDataStructures, TeardownDataStructures),
- unit_test_setup_teardown(test_cdb_utils_segment_cache_add_segment, SetupDataStructures, TeardownDataStructures),
- unit_test_setup_teardown(test_cdb_utils_segment_cache_del_segment, SetupDataStructures, TeardownDataStructures),
- unit_test_setup_teardown(test_cdb_utils_segment_cache_activate_standby, SetupDataStructures, TeardownDataStructures),
- unit_test_setup_teardown(test_cdb_utils_segment_cache_update_segment_mode_status, SetupDataStructures, TeardownDataStructures)
- };
- rc = run_tests(tests);
-
- /* clean memory at last */
- MemoryContextReset(testMemoryContext);
- testMemoryContext = NULL;
- TopMemoryContext = NULL;
-
- /* release cache buffer */
- if (cache_mem)
- free(cache_mem);
-
- return rc;
-}
-#else
-
-int
-main(int argc, char* argv[])
-{
- return 0;
-}
-#endif
\ No newline at end of file
diff --git a/src/backend/utils/etcd_lib/test/Makefile b/src/backend/utils/etcd_lib/test/Makefile
deleted file mode 100755
index 6b8b0c6..0000000
--- a/src/backend/utils/etcd_lib/test/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-subdir=src/backend/utils/etcd_lib
-top_builddir=../../../../..
-include $(top_builddir)/src/Makefile.global
-
-TARGETS=etcdlib
-
-include $(top_srcdir)/src/backend/mock.mk
-LDFLAGS := -luuid $(LDFLAGS)
-CFLAGS := -o0 $(CFLAGS)
-
-etcdlib.t: $(MOCK_DIR)/backend/utils/error/elog_mock.o \
- $(MOCK_DIR)/backend/access/hash/hashpage_mock.o \
- $(MOCK_DIR)/backend/utils/fmgr/fmgr_mock.o \
- $(MOCK_DIR)/backend/storage/ipc/shmem_mock.o \
- $(MOCK_DIR)/backend/storage/lmgr/lwlock_mock.o
diff --git a/src/backend/utils/etcd_lib/test/etcdlib_test.c b/src/backend/utils/etcd_lib/test/etcdlib_test.c
deleted file mode 100644
index 43e2d2d..0000000
--- a/src/backend/utils/etcd_lib/test/etcdlib_test.c
+++ /dev/null
@@ -1,673 +0,0 @@
-/**
- * Test program for testing the etcdlib.
- * Prerequisite is that etcdlib is started on localhost on default port (2379)
- * tested with etcd 2.3.7
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <pthread.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <uuid/uuid.h>
-
-#include "postgres.h"
-#include "cmockery.h"
-#include "utils/etcd.h"
-#include "lib/stringinfo.h"
-#include "nodes/nodes.h"
-#include "utils/memutils.h"
-#include "common/etcdutils.h"
-
-#ifndef USE_INTERNAL_FTS
-
-static etcdlib_t *etcdlib;
-static MemoryContext testMemoryContext = NULL;
-static pthread_mutex_t lease_lock = PTHREAD_MUTEX_INITIALIZER;
-
-#define SIMPLEKEY "simplekey"
-#define SIMPLEVALUE "testvalue"
-#define DIRECTORYKEY "/cbdb/fts/default/e3cb5400-9589-918d-c178-82d500deac6e/7bc05356-67f9-49fe-804e-12fe30b093ef/fts_dump_file_key"
-#define SIMPLELOCK "simplelock"
-#define LEASETIMEOUT 12
-#define ETCD_TEST_HOST "192.168.180.86"
-#define ETCD_TEST_PORT 2379
-#define ETCD_TEST_SINGLE_ENDPOINTS_NUM 1
-#define ETCD_TEST_MULTI_ENDPOINTS_NUM 3
-#define UUID_LEN 37
-#define ETCD_LOCK_LEN 256
-#define ETCD_LOCK_KEY "fts_ha_lock"
-#define METADATA_DIR_PREFIX "/cbdb/fts"
-#define NAMESPACE "default"
-
-/*
- * * Mock PG_RE_THROW, because we are not using real elog.o.
- * * The closest mockery is to call siglongjmp().
- * */
-#undef PG_RE_THROW
-#define PG_RE_THROW() siglongjmp(*PG_exception_stack, 1)
-
-static char test_endpoint_list[ETCD_TEST_MULTI_ENDPOINTS_NUM][GP_ETCD_HOSTNAME_LEN] = {"192.168.180.86", "192.168.180.87", "192.168.180.88"};
-static char test_failover_endpoint_list[ETCD_TEST_MULTI_ENDPOINTS_NUM+1][GP_ETCD_HOSTNAME_LEN] = {"127.0.0.1", "192.168.180.86", "192.168.180.87", "192.168.180.88"};
-
-static void
-_errfinish_impl()
-{
- PG_RE_THROW();
-}
-
-#define EXPECT_EREPORT(LOG_LEVEL) \
- if (LOG_LEVEL < ERROR )\
- { \
- expect_value(errstart, elevel, (LOG_LEVEL)); \
- expect_any(errstart, domain); \
- will_return(errstart, false); \
- } \
- else \
- { \
- expect_value(errstart_cold, elevel, (LOG_LEVEL)); \
- expect_any(errstart_cold, domain); \
- will_return_with_sideeffect(errstart_cold, false, &_errfinish_impl, NULL); \
- } \
-
-static etcdlib_endpoint_t etcd_endpoints[GP_ETCD_ENDPOINTS_NUM] = {0};
-static etcdlib_endpoint_t etcd_multi_endpoints[GP_ETCD_ENDPOINTS_NUM] = {0};
-static etcdlib_endpoint_t etcd_failover_endpoints[GP_ETCD_ENDPOINTS_NUM] = {0};
-static int etcd_endpoints_num = 0;
-static char *fts_dump_file_key = NULL;
-
-static char*
-generateLockName() {
- uuid_t uid_account;
- char uuid_account[UUID_LEN];
- char lock_name[ETCD_LOCK_LEN];
- memset(lock_name, 0, ETCD_LOCK_LEN);
- uuid_generate(uid_account);
- uuid_unparse(uid_account, uuid_account);
-
- uuid_t uid_cluster;
- char uuid_cluster[UUID_LEN];
- uuid_generate(uid_cluster);
- uuid_unparse(uid_cluster, uuid_cluster);
-
- memset(lock_name, 0, sizeof(char)*ETCD_LOCK_LEN);
- snprintf(lock_name, ETCD_LOCK_LEN, "%s/%s/%s/%s/%s",
- METADATA_DIR_PREFIX, NAMESPACE, uuid_account, uuid_cluster, ETCD_LOCK_KEY);
-
- printf("generateLockName lock key: %s\n", lock_name);
- return strdup(lock_name);
-}
-
-static void
-simpleWriteTest() {
- int res = 0;
- char*value = NULL;
-
- res = etcdlib_set(etcdlib, SIMPLEKEY, SIMPLEVALUE, 0, false);
- assert_int_equal(res, 0);
-
- res = etcdlib_get(etcdlib, SIMPLEKEY, &value, NULL);
- assert_int_equal(res, 0);
- assert_true(value != NULL);
- assert_string_equal(value, SIMPLEVALUE);
-
- res = etcdlib_del(etcdlib, SIMPLEKEY);
- assert_int_equal(res, 0);
-
- // should not get
- res = etcdlib_get(etcdlib, SIMPLEKEY, &value, NULL);
- assert_int_not_equal(res, 0);
-
- if (value)
- pfree(value);
-}
-
-static void
-directroyWriteTest() {
- int res = 0;
- char*value = NULL;
-
- res = etcdlib_set(etcdlib, DIRECTORYKEY, SIMPLEVALUE, 0, false);
- assert_int_equal(res, 0);
-
- res = etcdlib_get(etcdlib, DIRECTORYKEY, &value, NULL);
- assert_int_equal(res, 0);
- assert_true(value != NULL);
- assert_string_equal(value, SIMPLEVALUE);
-
- res = etcdlib_del(etcdlib, DIRECTORYKEY);
- assert_int_equal(res, 0);
-
- /* should not get */
- res = etcdlib_get(etcdlib, DIRECTORYKEY, &value, NULL);
- assert_int_not_equal(res, 0);
-
- if (value)
- pfree(value);
-}
-
-int
-simpleLeaseTest() {
- int res = 0;
- long long lease = 0;
- char*value = NULL;
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_set(etcdlib, SIMPLEKEY, SIMPLEVALUE, lease, false);
- assert_int_equal(res, 0);
-
- res = etcdlib_get(etcdlib, SIMPLEKEY, &value, NULL);
- assert_int_equal(res, 0);
-
- if (value && strcmp(value, SIMPLEVALUE)) {
- printf("etcdlib test error: expected testvalue got %s\n", value);
- assert_true(false);
- }
-
- sleep(LEASETIMEOUT + 5);
-
- res = etcdlib_get(etcdlib, SIMPLEKEY, &value, NULL);
- assert_int_not_equal(res, 0);
-
- if (value)
- pfree(value);
- return res;
- }
-
-int
-simpleLockTest() {
- int res = 0;
- char*lock_key = NULL;
- long long lease = 0;
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, SIMPLELOCK, lease, &lock_key);
- assert_int_equal(res, 0);
-
- sleep(LEASETIMEOUT/2);
-
- res = etcdlib_unlock(etcdlib, lock_key);
- assert_int_equal(res, 0);
-
- if (lock_key)
- pfree(lock_key);
- return res;
-}
-
-int
-simpleCheckLeaderTest() {
- int res = 0;
- bool isLeader = false;
- bool failover_result = false;
-
- res = etcdlib_get_leader(etcdlib, &isLeader);
- assert_int_equal(res, 0);
-
- if (isLeader) {
- printf("simpleCheckLeaderTest already found leader node.\n");
- assert_int_equal(isLeader, true);
- } else {
- printf("simpleCheckLeaderTest already not found leader node, try failover.\n");
- failover_result = test_etcd_failover(&etcdlib);
- assert_true(failover_result);
- }
-
- return res;
-}
-
-int
-metaLockTest() {
- int res = 0;
- char* lock_key = NULL;
- long long lease = 0;
- char *lock_name = generateLockName();
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- assert_int_equal(res, 0);
-
- sleep(LEASETIMEOUT/2);
-
- res = etcdlib_unlock(etcdlib, lock_key);
- assert_int_equal(res, 0);
-
- if (lock_key)
- pfree(lock_key);
- return res;
-}
-
-int
-metaTimeoutLockTest() {
- int res = 0;
- char* lock_key = NULL;
- long long lease = 0;
- char *lock_name = generateLockName();
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- assert_int_equal(res, 0);
-
- sleep(LEASETIMEOUT*2);
-
- lease = 0;
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- assert_int_equal(res, 0);
-
- if (lock_key)
- pfree(lock_key);
- return res;
-}
-
-static void*
-etcdLockRenewLease(char *lock_name) {
- int rc = 0;
- int rc_lock = 0;
- long long lease = 0;
- int res;
- char* lock_key = NULL;
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- assert_int_equal(res, 0);
-
- printf("etcdLockRenewLease successfully retrived lock.\n");
-
- int loop = 0;
- while(loop <= 2*LEASETIMEOUT) {
- pthread_mutex_lock(&lease_lock);
- res = etcdlib_renew_lease(etcdlib, lease);
- pthread_mutex_unlock(&lease_lock);
- assert_int_equal(res, 0);
- loop++;
- sleep(1);
- }
-
- res = etcdlib_unlock(etcdlib, lock_key);
- assert_int_equal(res, 0);
-
- if (lock_key)
- pfree(lock_key);
-}
-
-static void*
-etcdLockRenewTryLock(char *lock_name) {
- int rc = 0;
- int rc_lock = 0;
- long long lease = 0;
- int res;
- char* lock_key = NULL;
-
- sleep(2);
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- pthread_mutex_lock(&lease_lock);
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- pthread_mutex_unlock(&lease_lock);
- assert_int_not_equal(res, 0);
-
- printf("etcdLockRenewTryLock try lock failed as expected.\n");
-
- sleep(LEASETIMEOUT + 5);
-
- lease = 0;
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- pthread_mutex_lock(&lease_lock);
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- pthread_mutex_unlock(&lease_lock);
- assert_int_not_equal(res, 0);
-
- printf("etcdLockRenewTryLock try lock failed again as expected.\n");
-
- if (lock_key)
- pfree(lock_key);
-
-}
-
-int
-metaRenewLockTest() {
- char *lock_name = generateLockName();
- pthread_t thread1;
- pthread_t thread2;
- int status = pthread_create(&thread1, NULL, etcdLockRenewLease, (void *)lock_name);
- status = pthread_create(&thread2, NULL, etcdLockRenewTryLock, (void *)lock_name);
- pthread_join(thread1, NULL);
- pthread_join(thread2, NULL);
-}
-
-static void*
-etcdLockFirst(char *lock_name) {
- int rc = 0;
- int rc_lock = 0;
- long long lease = 0;
- int res;
- char* lock_key = NULL;
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT*600);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- assert_int_equal(res, 0);
-
- printf("etcdLockFirst successfully retrived lock.\n");
- sleep(LEASETIMEOUT);
-
- res = etcdlib_unlock(etcdlib, lock_key);
- assert_int_equal(res, 0);
-
- if (lock_key)
- pfree(lock_key);
-}
-
-static void*
-etcdLockFirstTimeout(char *lock_name) {
- int rc = 0;
- int rc_lock = 0;
- long long lease = 0;
- int res;
- char* lock_key = NULL;
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- assert_int_equal(res, 0);
-
- if (lock_key)
- pfree(lock_key);
-}
-
-static void*
-etcdLockSecond(char *lock_name) {
- int rc = 0;
- int rc_lock = 0;
- long long lease = 0;
- int res;
- char* lock_key = NULL;
-
- sleep(2);
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- assert_int_not_equal(res, 0);
-
- printf("etcdLockSecond try lock failed as expected.\n");
-
- sleep(LEASETIMEOUT + 5);
-
- lease = 0;
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
- assert_int_equal(res, 0);
- assert_int_not_equal(lease, 0);
-
- res = etcdlib_lock(etcdlib, lock_name, lease, &lock_key);
- assert_int_equal(res, 0);
-
- printf("etcdLockSecond successfully retrived lock.\n");
- sleep(1);
-
- res = etcdlib_unlock(etcdlib, lock_key);
- assert_int_equal(res, 0);
-
- if (lock_key)
- pfree(lock_key);
-}
-
-void
-metaConcurrentLockTest() {
- int status = 0;
- char *lock_name = generateLockName();
- pthread_t thread1;
- pthread_t thread2;
- status = pthread_create(&thread1, NULL, etcdLockFirst, (void *)lock_name);
- status = pthread_create(&thread2, NULL, etcdLockSecond, (void *)lock_name);
- pthread_join(thread1, NULL);
- pthread_join(thread2, NULL);
-}
-
-void
-metaConcurrentLockTimeoutTest() {
- int status = 0;
- char *lock_name = generateLockName();
- pthread_t thread1;
- pthread_t thread2;
- status = pthread_create(&thread1, NULL, etcdLockFirstTimeout, (void *)lock_name);
- status = pthread_create(&thread2, NULL, etcdLockSecond, (void *)lock_name);
- pthread_join(thread1, NULL);
- pthread_join(thread2, NULL);
-}
-
-/* temporarilyt disable this case cause the etcdlib watch functionality is currently used, should be added back once necessarily.
-void* waitForChange(void*arg) {
- int *idx = (int*)arg;
- char *action = NULL;
- char *prevValue = NULL;
- char *value = NULL;
- char *rkey = NULL;
- long long modifiedIndex;
-
- printf("Watching for index %d\n", *idx);
-
- if(etcdlib_watch(etcdlib, "hier/ar", *idx, &action, &prevValue, &value, &rkey, &modifiedIndex) == 0){
- printf(" New value from watch : [%s]%s => %s\n", rkey, prevValue, value);
- if(action != NULL) free(action);
- if(prevValue != NULL) free(prevValue);
- if(rkey != NULL) free(rkey);
- if(value != NULL) free(value);
- }
-
- *idx = modifiedIndex+1;
-
- action = NULL;
- prevValue = NULL;
- value = NULL;
- rkey = NULL;
-
- if(etcdlib_watch(etcdlib, "hier/ar", *idx, &action, &prevValue, &value, &rkey, &modifiedIndex) == 0){
- printf(" New value from watch : [%s]%s => %s\n", rkey, prevValue, value);
- if(action != NULL) free(action);
- if(prevValue != NULL) free(prevValue);
- if(rkey != NULL) free(rkey);
- }
-
- return value;
-}
-
-int waitforchangetest() {
- int res = 0;
- char*value = NULL;
-
- etcdlib_set(etcdlib, "hier/ar/chi/cal", "testvalue1", 5, false);
-
- int index;
- etcdlib_get(etcdlib, "hier/ar/chi/cal", &value, &index);
- free(value);
- pthread_t waitThread;
- index++;
- pthread_create(&waitThread, NULL, waitForChange, &index);
- sleep(1);
- etcdlib_set(etcdlib, "hier/ar/chi/cal", "testvalue2", 5, false);
- sleep(1);
- etcdlib_set(etcdlib, "hier/ar/chi/cal", "testvalue3", 5, false);
- void *resVal = NULL;
- printf("joining\n");
- pthread_join(waitThread, &resVal);
- if(resVal == NULL || strcmp((char*)resVal,"testvalue3" ) != 0) {
- printf("etcdtest::waitforchange1 expected 'testvalue3', got '%s'\n", (char*)resVal);
- res = -1;
- }
- free(resVal);
- return res;
-}
-*/
-
-static void
-test_init_single_endpoints() {
- etcd_endpoints[0].etcd_host = (char *)malloc(sizeof(char)*GP_ETCD_HOSTNAME_LEN);
- strncpy(etcd_endpoints[0].etcd_host, ETCD_TEST_HOST, GP_ETCD_HOSTNAME_LEN);
- etcd_endpoints[0].etcd_port = ETCD_TEST_PORT;
-}
-
-static void
-test_init_multi_endpoints() {
- for (int i = 0; i < ETCD_TEST_MULTI_ENDPOINTS_NUM; i++) {
- etcd_multi_endpoints[i].etcd_host = (char *)malloc(sizeof(char)*GP_ETCD_HOSTNAME_LEN);
- strncpy(etcd_multi_endpoints[i].etcd_host, test_endpoint_list[i], GP_ETCD_HOSTNAME_LEN);
- etcd_multi_endpoints[i].etcd_port = ETCD_TEST_PORT;
- }
-}
-
-static void
-test_init_failover_endpoints() {
- for (int i = 0; i < ETCD_TEST_MULTI_ENDPOINTS_NUM+1; i++) {
- etcd_failover_endpoints[i].etcd_host = (char *)malloc(sizeof(char)*GP_ETCD_HOSTNAME_LEN);
- strncpy(etcd_failover_endpoints[i].etcd_host, test_failover_endpoint_list[i], GP_ETCD_HOSTNAME_LEN);
- etcd_failover_endpoints[i].etcd_port = ETCD_TEST_PORT;
- }
-}
-
-static void
-test_init_endpoints() {
- test_init_single_endpoints();
- test_init_multi_endpoints();
- test_init_failover_endpoints();
-}
-
-
-static void
-test_etcd_write_test_function(void **state)
-{
- etcdlib_endpoint_t *petcd_endpoints = etcd_endpoints;
- etcdlib = etcdlib_create(petcd_endpoints, ETCD_TEST_SINGLE_ENDPOINTS_NUM, 0);
- simpleWriteTest();
- directroyWriteTest();
- simpleLeaseTest();
- etcdlib_destroy(etcdlib);
-}
-
-static void
-test_etcd_lock_test_function(void **state)
-{
- etcdlib_endpoint_t *petcd_endpoints = etcd_endpoints;
- etcdlib = etcdlib_create(petcd_endpoints, ETCD_TEST_SINGLE_ENDPOINTS_NUM, 0);
- simpleLockTest();
- metaLockTest();
- metaTimeoutLockTest();
- metaRenewLockTest();
- metaConcurrentLockTest();
- metaConcurrentLockTimeoutTest();
- etcdlib_destroy(etcdlib);
-}
-
-static void
-test_etcd_simple_failover_test_function(void **state)
-{
- etcdlib_endpoint_t *petcd_endpoints = etcd_multi_endpoints;
- etcdlib = etcdlib_create(petcd_endpoints, ETCD_TEST_MULTI_ENDPOINTS_NUM, 0);
- simpleCheckLeaderTest();
- etcdlib_destroy(etcdlib);
-}
-
-static void
-test_etcd_failure_failover_test_function(void **state)
-{
- int res = 0;
- long long lease = 0;
- char*value = NULL;
- etcdlib_endpoint_t *petcd_endpoints = etcd_failover_endpoints;
- etcdlib = etcdlib_create(petcd_endpoints, ETCD_TEST_MULTI_ENDPOINTS_NUM+1, 0);
-
- res = etcdlib_grant_lease(etcdlib, &lease, LEASETIMEOUT);
-
- assert_int_equal(res, 0);
- etcdlib_destroy(etcdlib);
-}
-
-static void
-SetupDataStructures(void **state)
-{
- if (NULL == TopMemoryContext)
- {
- assert_true(NULL == testMemoryContext);
- MemoryContextInit();
-
- testMemoryContext = AllocSetContextCreate(TopMemoryContext,
- "Test Context",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
-
- MemoryContextSwitchTo(testMemoryContext);
- }
-
- assert_true(NULL != testMemoryContext &&
- CurrentMemoryContext == testMemoryContext);
-}
-
-/*
- * Cleans up memory by reseting testMemoryContext
- */
-static void
-TeardownDataStructures(void **state)
-{
- assert_true(NULL != testMemoryContext &&
- CurrentMemoryContext == testMemoryContext);
- MemoryContextReset(testMemoryContext);
-}
-
-int
-main (int argc, char* argv[]) {
- cmockery_parse_arguments(argc, argv);
-
- test_init_endpoints();
-
- const UnitTest tests[] = {
- unit_test_setup_teardown(test_etcd_write_test_function, SetupDataStructures, TeardownDataStructures),
- unit_test_setup_teardown(test_etcd_lock_test_function, SetupDataStructures, TeardownDataStructures),
- unit_test_setup_teardown(test_etcd_simple_failover_test_function, SetupDataStructures, TeardownDataStructures),
- unit_test_setup_teardown(test_etcd_failure_failover_test_function, SetupDataStructures, TeardownDataStructures)
- };
- return run_tests(tests);
-}
-
-#else
-
-int
-main(int argc, char* argv[])
-{
- return 0;
-}
-#endif
\ No newline at end of file
diff --git a/src/bin/Makefile b/src/bin/Makefile
index 8baea7d..582d3f5 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -15,7 +15,6 @@
unittest-check:
$(MAKE) -C pg_dump/test check
- $(MAKE) -C gpfts/test check
SUBDIRS = \
initdb \
diff --git a/src/bin/gpfts/test/Makefile b/src/bin/gpfts/test/Makefile
deleted file mode 100755
index 74a63d6..0000000
--- a/src/bin/gpfts/test/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-subdir=src/bin/gpfts
-top_builddir=../../../..
-etcdlib_obj=$(top_builddir)/src/backend/utils/etcd_lib/etcd.o
-include $(top_builddir)/src/Makefile.global
-
-
-TARGETS=gpfts
-
-override CPPFLAGS+= -I$(top_srcdir)/src/interfaces/libpq
-override CPPFLAGS+= -I$(top_srcdir)/src/bin/gpfts
-
-include $(top_srcdir)/src/Makefile.mock
-LDFLAGS := -luuid $(LDFLAGS)
-
-gpfts.t: gp_fts_test.o $(CMOCKERY_OBJS) ../fts_etcd.o $(etcdlib_obj) $(top_srcdir)/src/fe_utils/log.o
- $(CC) $^ $(libpq_pgport) $(LDFLAGS) $(rpath) $(LIBS) $(libpq) -o $@
diff --git a/src/bin/gpfts/test/gp_fts_test.c b/src/bin/gpfts/test/gp_fts_test.c
deleted file mode 100644
index 4d6a64c..0000000
--- a/src/bin/gpfts/test/gp_fts_test.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * gp_fts_test.c
- * unit test for separated fts damone testing
- *
- *
- * Portions Copyright (c) 2022-2023, Greenplum Inc.
- *
- *-------------------------------------------------------------------------
- */
-
-#include "postgres_fe.h"
-#ifndef USE_INTERNAL_FTS
-#include "utils/etcd.h"
-#include "lib/stringinfo.h"
-#include "nodes/nodes.h"
-#include "utils/memutils.h"
-#include "cmockery.h"
-#include "fts_etcd.h"
-#include "fe_utils/log.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <pthread.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <uuid/uuid.h>
-
-#define SIMPLELOCK "ftslock"
-#define SIMPLEHOSTKEY "ftshost"
-#define TEST_HOSTNAME "hashdata-fts-0"
-#define TEST_NAMESPACE "default"
-#define UUID_LEN 37
-#define ETCD_LOCK_LEN 256
-
-static char test_single_endpoints[] = GP_ETCD_TEST_SINGLE_ENDPOINTS;
-static char test_multi_endpoints[] = GP_ETCD_TEST_MULTI_ENDPOINTS;
-static char test_failover_endpoints[] = GP_ETCD_TEST_FAILOVER_ENDPOINTS;
-const char *progname = NULL;
-
-static void
-FTSGetLockTest(char *lock_name) {
- char *fts_hostname = TEST_HOSTNAME;
- char *lock = NULL;
- long long lease = 0;
- bool res = getFTSLockFromETCD(lock_name, &lock, &lease, FTS_HA_LOCK_LEASE_TIMEOUT_DEFAULT, fts_hostname, SIMPLEHOSTKEY);
- assert_true(res);
- assert_int_not_equal(lease, 0);
-}
-
-static void
-FTSRenewLockLeaseTest(char *lock_name) {
- char *fts_hostname = TEST_HOSTNAME;
- char *lock = NULL;
- long long lease = 0;
- bool res = getFTSLockFromETCD(lock_name, &lock, &lease, FTS_HA_LOCK_LEASE_TIMEOUT_DEFAULT, fts_hostname, SIMPLEHOSTKEY);
- assert_true(res);
- assert_int_not_equal(lease, 0);
- int ret = renewFTSLeaseFromETCD(lease, FTS_HA_LOCK_LEASE_TIMEOUT_DEFAULT);
- assert_int_equal(ret, 0);
-}
-
-static void
-test_fts_lock_function(void **state)
-{
- char lock_name[ETCD_LOCK_LEN];
- memset(lock_name, 0, ETCD_LOCK_LEN);
-
- uuid_t uid_account;
- char uuid_account[UUID_LEN];
- uuid_generate(uid_account);
- uuid_unparse(uid_account, uuid_account);
-
- uuid_t uid_cluster;
- char uuid_cluster[UUID_LEN];
- uuid_generate(uid_cluster);
- uuid_unparse(uid_cluster, uuid_cluster);
-
- snprintf(lock_name, sizeof(lock_name), "/%s/%s/%s", uuid_account, uuid_cluster, SIMPLELOCK);
-
- bool res = initETCD(test_single_endpoints, TEST_NAMESPACE, uuid_account, uuid_cluster);
- assert_true(res);
- FTSGetLockTest(lock_name);
- destoryETCD();
-}
-
-static void
-test_fts_lock_multi_function(void **state)
-{
- char lock_name[ETCD_LOCK_LEN];
- memset(lock_name, 0, ETCD_LOCK_LEN);
-
- uuid_t uid_account;
- char uuid_account[UUID_LEN];
- uuid_generate(uid_account);
- uuid_unparse(uid_account, uuid_account);
-
- uuid_t uid_cluster;
- char uuid_cluster[UUID_LEN];
- uuid_generate(uid_cluster);
- uuid_unparse(uid_cluster, uuid_cluster);
-
- snprintf(lock_name, sizeof(lock_name), "/%s/%s/%s", uuid_account, uuid_cluster, SIMPLELOCK);
-
- bool res = initETCD(test_multi_endpoints, TEST_NAMESPACE, uuid_account, uuid_cluster);
- assert_true(res);
- FTSGetLockTest(lock_name);
- destoryETCD();
-}
-
-
-static void
-test_fts_lock_function_failover_endpoints(void **state)
-{
- char lock_name[ETCD_LOCK_LEN];
- memset(lock_name, 0, ETCD_LOCK_LEN);
-
- uuid_t uid_account;
- char uuid_account[UUID_LEN];
- uuid_generate(uid_account);
- uuid_unparse(uid_account, uuid_account);
-
- uuid_t uid_cluster;
- char uuid_cluster[UUID_LEN];
- uuid_generate(uid_cluster);
- uuid_unparse(uid_cluster, uuid_cluster);
-
- snprintf(lock_name, sizeof(lock_name), "/%s/%s/%s", uuid_account, uuid_cluster, SIMPLELOCK);
-
- bool res = initETCD(test_failover_endpoints, TEST_NAMESPACE, uuid_account, uuid_cluster);
- assert_true(res);
- FTSGetLockTest(lock_name);
- destoryETCD();
-}
-
-static void
-test_fts_lock_lease_function(void **state)
-{
- char lock_name[ETCD_LOCK_LEN];
- memset(lock_name, 0, ETCD_LOCK_LEN);
-
- uuid_t uid_account;
- char uuid_account[UUID_LEN];
- uuid_generate(uid_account);
- uuid_unparse(uid_account, uuid_account);
-
- uuid_t uid_cluster;
- char uuid_cluster[UUID_LEN];
- uuid_generate(uid_cluster);
- uuid_unparse(uid_cluster, uuid_cluster);
-
- snprintf(lock_name, sizeof(lock_name), "/%s/%s/%s", uuid_account, uuid_cluster, SIMPLELOCK);
-
- bool res = initETCD(test_single_endpoints, TEST_NAMESPACE, uuid_account, uuid_cluster);
- assert_true(res);
- FTSRenewLockLeaseTest(lock_name);
-
- destoryETCD();
-}
-
-int main (int argc, char* argv[]) {
- progname = get_progname(argv[0]);
-
- cmockery_parse_arguments(argc, argv);
-
- const UnitTest tests[] = {
- unit_test(test_fts_lock_function),
- unit_test(test_fts_lock_multi_function),
- unit_test(test_fts_lock_function_failover_endpoints),
- unit_test(test_fts_lock_lease_function)
- };
- return run_tests(tests);
- return 0;
-}
-#else
-int
-main(int argc, char* argv[])
-{
- return 0;
-}
-#endif
diff --git a/src/include/common/etcdutils.h b/src/include/common/etcdutils.h
index 599179d..f18e458 100644
--- a/src/include/common/etcdutils.h
+++ b/src/include/common/etcdutils.h
@@ -28,9 +28,6 @@
#define GP_ETCD_CLUSTER_ID_DEFAULT "00000000-0000-0000-0000-000000000000"
#define GP_ETCD_ENDPOINTS_DEFAULT "localhost:2379"
#define GP_CBDB_DEPLOY "onpromise"
-#define GP_ETCD_TEST_SINGLE_ENDPOINTS "192.168.180.86:2379"
-#define GP_ETCD_TEST_MULTI_ENDPOINTS "192.168.180.86:2379,192.168.180.87:2379,192.168.180.88:2379"
-#define GP_ETCD_TEST_FAILOVER_ENDPOINTS "127.0.0.1:2379,192.168.180.86:2379,192.168.180.87:2379,192.168.180.88:2379"
typedef struct etcdlib_endpoint {
char *etcd_host;