提交 1eb06b85 编写于 作者: J Jesse Zhang 提交者: Adam Berlin

pg_indent

上级 12366063
...@@ -46,37 +46,38 @@ connectToSix() ...@@ -46,37 +46,38 @@ connectToSix()
typedef struct UserData typedef struct UserData
{ {
int id; int id;
char *name; char *name;
} User; } User;
static bool 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 && expected_user->id == actual_user->id &&
strncmp(expected_user->name, actual_user->name, strlen(expected_user->name)) == 0 strncmp(expected_user->name, actual_user->name, strlen(expected_user->name)) == 0
); ;
} }
typedef struct Rows { typedef struct Rows
int size; {
User rows[10]; int size;
} Rows; User rows[10];
} Rows;
static void 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) for (int j = 0; j < expected_rows->size; ++j)
{ {
found = false; 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) 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)) if (users_match(expected_user, current_user))
{ {
...@@ -90,24 +91,28 @@ assert_rows_contain_user(const Rows *expected_rows, const Rows *rows) ...@@ -90,24 +91,28 @@ assert_rows_contain_user(const Rows *expected_rows, const Rows *rows)
} }
static void static void
extract_user_rows(PGresult *result, Rows *rows) extract_user_rows(PGresult *result, Rows * rows)
{ {
int number_of_rows = PQntuples(result); int number_of_rows = PQntuples(result);
int i;
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 *user = &rows->rows[i];
user->id = atoi(PQgetvalue(result, i, PQfnumber(result, "id")));
user->name = PQgetvalue(result, i, PQfnumber(result, "name")); user->id = atoi(PQgetvalue(result, i, i_id));
user->name = PQgetvalue(result, i, i_name);
} }
rows->size = number_of_rows; rows->size = number_of_rows;
} }
static void static void
createHeapTableWithDataInFiveCluster(void) createHeapTableWithDataInFiveCluster(void)
{ {
PGconn *connection = connectToFive(); PGconn *connection = connectToFive();
executeQuery(connection, "create schema five_to_six_upgrade;"); executeQuery(connection, "create schema five_to_six_upgrade;");
executeQuery(connection, "set search_path to 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);"); executeQuery(connection, "create table users (id integer, name text) distributed by (id);");
...@@ -119,20 +124,29 @@ createHeapTableWithDataInFiveCluster(void) ...@@ -119,20 +124,29 @@ createHeapTableWithDataInFiveCluster(void)
PQfinish(connection); PQfinish(connection);
} }
static void static void
heapTableShouldHaveDataUpgradedToSixCluster() heapTableShouldHaveDataUpgradedToSixCluster()
{ {
PGconn *connection = connectToSix(); PGconn *connection = connectToSix();
executeQuery(connection, "set search_path to five_to_six_upgrade;"); 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); extract_user_rows(result, &rows);
assert_int_equal(3, rows.size); 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); assert_rows_contain_user(&expected_users, &rows);
PQfinish(connection); PQfinish(connection);
...@@ -142,94 +156,96 @@ static void ...@@ -142,94 +156,96 @@ static void
assertNumberOfHardLinks(struct stat *fileInformation, int expectedNumberOfHardLinks) assertNumberOfHardLinks(struct stat *fileInformation, int expectedNumberOfHardLinks)
{ {
assert_int_equal( assert_int_equal(
fileInformation->st_nlink, fileInformation->st_nlink,
expectedNumberOfHardLinks); expectedNumberOfHardLinks);
} }
static void static void
assertRelfilenodeHardLinked( assertRelfilenodeHardLinked(
char *segment_path, char *segment_path,
int databaseOid, int databaseOid,
int relfilenodeNumber int relfilenodeNumber
) )
{ {
char path[2000]; char path[2000];
sprintf( sprintf(
path, path,
"./gpdb6-data/%s/base/%d/%d", "./gpdb6-data/%s/base/%d/%d",
segment_path, segment_path,
databaseOid, databaseOid,
relfilenodeNumber); relfilenodeNumber);
struct stat fileInformation; struct stat fileInformation;
stat(path, &fileInformation); stat(path, &fileInformation);
/* /*
* The file should have two hard links to * The file should have two hard links to
*/ */
assertNumberOfHardLinks( assertNumberOfHardLinks(
&fileInformation, &fileInformation,
2); 2);
} }
static void static void
assertMasterHasTableLinked(int databaseOid, int relfilenodeNumber) assertMasterHasTableLinked(int databaseOid, int relfilenodeNumber)
{ {
char *segment_path = "qddir/demoDataDir-1"; char *segment_path = "qddir/demoDataDir-1";
assertRelfilenodeHardLinked( assertRelfilenodeHardLinked(
segment_path, segment_path,
databaseOid, databaseOid,
relfilenodeNumber); relfilenodeNumber);
} }
static void static void
assertContentId0HasTableLinked(int databaseOid, int relfilenodeNumber) assertContentId0HasTableLinked(int databaseOid, int relfilenodeNumber)
{ {
char *segment_path = "dbfast1/demoDataDir0"; char *segment_path = "dbfast1/demoDataDir0";
assertRelfilenodeHardLinked( assertRelfilenodeHardLinked(
segment_path, segment_path,
databaseOid, databaseOid,
relfilenodeNumber); relfilenodeNumber);
} }
static void static void
assertContentId1HasTableLinked(int databaseOid, int relfilenodeNumber) assertContentId1HasTableLinked(int databaseOid, int relfilenodeNumber)
{ {
char *segment_path = "dbfast2/demoDataDir1"; char *segment_path = "dbfast2/demoDataDir1";
assertRelfilenodeHardLinked( assertRelfilenodeHardLinked(
segment_path, segment_path,
databaseOid, databaseOid,
relfilenodeNumber); relfilenodeNumber);
} }
static void static void
assertContentId2HasTableLinked(int databaseOid, int relfilenodeNumber) assertContentId2HasTableLinked(int databaseOid, int relfilenodeNumber)
{ {
char *segment_path = "dbfast3/demoDataDir2"; char *segment_path = "dbfast3/demoDataDir2";
assertRelfilenodeHardLinked( assertRelfilenodeHardLinked(
segment_path, segment_path,
databaseOid, databaseOid,
relfilenodeNumber); relfilenodeNumber);
} }
static void static void
heapTableShouldBeHardLinked(void) heapTableShouldBeHardLinked(void)
{ {
int rowNumber; int rowNumber;
int databaseOid; int databaseOid;
int relfilenodeNumber; int relfilenodeNumber;
PGconn *connection = connectToSix();
PGconn *connection = connectToSix();
executeQuery(connection, "set search_path to five_to_six_upgrade;"); 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; rowNumber = 0;
databaseOid = atoi(PQgetvalue(result, rowNumber, 0)); databaseOid = atoi(PQgetvalue(result, rowNumber, 0));
relfilenodeNumber = atoi(PQgetvalue(result, rowNumber, 1)); relfilenodeNumber = atoi(PQgetvalue(result, rowNumber, 1));
...@@ -247,8 +263,8 @@ anAdministratorPerformsAnUpgrade() ...@@ -247,8 +263,8 @@ anAdministratorPerformsAnUpgrade()
performUpgrade(); performUpgrade();
} }
static void static void
given(void (* arrangeFunction)(void)) given(void (*arrangeFunction) (void))
{ {
startGpdbFiveCluster(); startGpdbFiveCluster();
arrangeFunction(); arrangeFunction();
...@@ -256,7 +272,7 @@ given(void (* arrangeFunction)(void)) ...@@ -256,7 +272,7 @@ given(void (* arrangeFunction)(void))
} }
static void static void
then(void (* assertionFunction)(void)) then(void (*assertionFunction) (void))
{ {
startGpdbSixCluster(); startGpdbSixCluster();
assertionFunction(); assertionFunction();
...@@ -264,13 +280,13 @@ then(void (* assertionFunction)(void)) ...@@ -264,13 +280,13 @@ then(void (* assertionFunction)(void))
} }
static void static void
when(void (* actFunction)(void)) when(void (*actFunction) (void))
{ {
actFunction(); actFunction();
} }
static void static void
and(void (* assertionFunction)(void)) and(void (*assertionFunction) (void))
{ {
/* and has the same behavior as then */ /* and has the same behavior as then */
then(assertionFunction); then(assertionFunction);
...@@ -290,7 +306,7 @@ main(int argc, char *argv[]) ...@@ -290,7 +306,7 @@ main(int argc, char *argv[])
{ {
cmockery_parse_arguments(argc, 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) unit_test_setup_teardown(test_a_heap_table_with_data_can_be_upgraded, setup, teardown)
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册