diff --git a/contrib/pg_upgrade/test/integration/greenplum_five_to_greenplum_six_upgrade_test.c b/contrib/pg_upgrade/test/integration/greenplum_five_to_greenplum_six_upgrade_test.c index 258f97191e7235d79b591ceefc7ae6995c4b4837..2af517d255d033e2773bbf87500637ec9b1d6688 100644 --- a/contrib/pg_upgrade/test/integration/greenplum_five_to_greenplum_six_upgrade_test.c +++ b/contrib/pg_upgrade/test/integration/greenplum_five_to_greenplum_six_upgrade_test.c @@ -46,37 +46,38 @@ connectToSix() typedef struct UserData { - int id; - char *name; -} User; + int id; + char *name; +} User; static bool -users_match(const User *expected_user, const User *actual_user) +users_match(const User * expected_user, const User * actual_user) { - return ( + return expected_user->id == actual_user->id && strncmp(expected_user->name, actual_user->name, strlen(expected_user->name)) == 0 - ); + ; } -typedef struct Rows { - int size; - User rows[10]; -} Rows; +typedef struct Rows +{ + int size; + User rows[10]; +} Rows; static void -assert_rows_contain_user(const Rows *expected_rows, const Rows *rows) +assert_rows_contain_user(const Rows * expected_rows, const Rows * rows) { - bool found = false; + bool found = false; for (int j = 0; j < expected_rows->size; ++j) { found = false; - const User *expected_user = &expected_rows->rows[j]; + const User *expected_user = &expected_rows->rows[j]; for (int i = 0; i < rows->size; ++i) { - const User *current_user = &rows->rows[i]; + const User *current_user = &rows->rows[i]; if (users_match(expected_user, current_user)) { @@ -90,24 +91,28 @@ assert_rows_contain_user(const Rows *expected_rows, const Rows *rows) } static void -extract_user_rows(PGresult *result, Rows *rows) +extract_user_rows(PGresult *result, Rows * rows) { - int number_of_rows = PQntuples(result); - int i; + int number_of_rows = PQntuples(result); + + const int i_id = PQfnumber(result, "id"); + const int i_name = PQfnumber(result, "name"); - for (i = 0; i < number_of_rows; i++) + for (int i = 0; i < number_of_rows; i++) { - User *user = &rows->rows[i]; - user->id = atoi(PQgetvalue(result, i, PQfnumber(result, "id"))); - user->name = PQgetvalue(result, i, PQfnumber(result, "name")); + User *user = &rows->rows[i]; + + user->id = atoi(PQgetvalue(result, i, i_id)); + user->name = PQgetvalue(result, i, i_name); } rows->size = number_of_rows; } -static void +static void createHeapTableWithDataInFiveCluster(void) { - PGconn *connection = connectToFive(); + PGconn *connection = connectToFive(); + executeQuery(connection, "create schema five_to_six_upgrade;"); executeQuery(connection, "set search_path to five_to_six_upgrade"); executeQuery(connection, "create table users (id integer, name text) distributed by (id);"); @@ -119,20 +124,29 @@ createHeapTableWithDataInFiveCluster(void) PQfinish(connection); } -static void +static void heapTableShouldHaveDataUpgradedToSixCluster() { - PGconn *connection = connectToSix(); + PGconn *connection = connectToSix(); + executeQuery(connection, "set search_path to five_to_six_upgrade;"); - PGresult *result = executeQuery(connection, "select * from users;"); + PGresult *result = executeQuery(connection, "select * from users;"); - Rows rows = {}; + Rows rows = {}; extract_user_rows(result, &rows); assert_int_equal(3, rows.size); - const Rows expected_users = {.size = 3, .rows = {{.id=1, .name="Jane"}, {.id=2, .name = "John"}, {.id=3, .name="Joe"}}}; + const Rows expected_users = { + .size = 3, + .rows = { + {.id = 1,.name = "Jane"}, + {.id = 2,.name = "John"}, + {.id = 3,.name = "Joe"} + } + }; + assert_rows_contain_user(&expected_users, &rows); PQfinish(connection); @@ -142,94 +156,96 @@ static void assertNumberOfHardLinks(struct stat *fileInformation, int expectedNumberOfHardLinks) { assert_int_equal( - fileInformation->st_nlink, - expectedNumberOfHardLinks); + fileInformation->st_nlink, + expectedNumberOfHardLinks); } static void assertRelfilenodeHardLinked( - char *segment_path, - int databaseOid, - int relfilenodeNumber - ) + char *segment_path, + int databaseOid, + int relfilenodeNumber +) { - char path[2000]; + char path[2000]; sprintf( - path, - "./gpdb6-data/%s/base/%d/%d", - segment_path, - databaseOid, - relfilenodeNumber); + path, + "./gpdb6-data/%s/base/%d/%d", + segment_path, + databaseOid, + relfilenodeNumber); struct stat fileInformation; stat(path, &fileInformation); /* - * The file should have two hard links to + * The file should have two hard links to */ assertNumberOfHardLinks( - &fileInformation, - 2); + &fileInformation, + 2); } -static void +static void assertMasterHasTableLinked(int databaseOid, int relfilenodeNumber) { - char *segment_path = "qddir/demoDataDir-1"; + char *segment_path = "qddir/demoDataDir-1"; assertRelfilenodeHardLinked( - segment_path, - databaseOid, - relfilenodeNumber); + segment_path, + databaseOid, + relfilenodeNumber); } static void assertContentId0HasTableLinked(int databaseOid, int relfilenodeNumber) { - char *segment_path = "dbfast1/demoDataDir0"; + char *segment_path = "dbfast1/demoDataDir0"; assertRelfilenodeHardLinked( - segment_path, - databaseOid, - relfilenodeNumber); + segment_path, + databaseOid, + relfilenodeNumber); } static void assertContentId1HasTableLinked(int databaseOid, int relfilenodeNumber) { - char *segment_path = "dbfast2/demoDataDir1"; + char *segment_path = "dbfast2/demoDataDir1"; assertRelfilenodeHardLinked( - segment_path, - databaseOid, - relfilenodeNumber); + segment_path, + databaseOid, + relfilenodeNumber); } static void assertContentId2HasTableLinked(int databaseOid, int relfilenodeNumber) { - char *segment_path = "dbfast3/demoDataDir2"; + char *segment_path = "dbfast3/demoDataDir2"; assertRelfilenodeHardLinked( - segment_path, - databaseOid, - relfilenodeNumber); + segment_path, + databaseOid, + relfilenodeNumber); } -static void +static void heapTableShouldBeHardLinked(void) { - int rowNumber; - int databaseOid; - int relfilenodeNumber; + int rowNumber; + int databaseOid; + int relfilenodeNumber; + + PGconn *connection = connectToSix(); - PGconn *connection = connectToSix(); executeQuery(connection, "set search_path to five_to_six_upgrade;"); - PGresult *result = executeQuery(connection, "select pg_database.oid, relfilenode from pg_class, pg_database where relname = 'users' and datname = current_database();"); + PGresult *result = executeQuery(connection, "select pg_database.oid, relfilenode from pg_class, pg_database where relname = 'users' and datname = current_database();"); + rowNumber = 0; databaseOid = atoi(PQgetvalue(result, rowNumber, 0)); relfilenodeNumber = atoi(PQgetvalue(result, rowNumber, 1)); @@ -247,8 +263,8 @@ anAdministratorPerformsAnUpgrade() performUpgrade(); } -static void -given(void (* arrangeFunction)(void)) +static void +given(void (*arrangeFunction) (void)) { startGpdbFiveCluster(); arrangeFunction(); @@ -256,7 +272,7 @@ given(void (* arrangeFunction)(void)) } static void -then(void (* assertionFunction)(void)) +then(void (*assertionFunction) (void)) { startGpdbSixCluster(); assertionFunction(); @@ -264,13 +280,13 @@ then(void (* assertionFunction)(void)) } static void -when(void (* actFunction)(void)) +when(void (*actFunction) (void)) { actFunction(); } -static void -and(void (* assertionFunction)(void)) +static void +and(void (*assertionFunction) (void)) { /* and has the same behavior as then */ then(assertionFunction); @@ -290,7 +306,7 @@ main(int argc, char *argv[]) { cmockery_parse_arguments(argc, argv); - const UnitTest tests[] = { + const UnitTest tests[] = { unit_test_setup_teardown(test_a_heap_table_with_data_can_be_upgraded, setup, teardown) };