1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*
* Copyright (c) 2010-2012 Postgres-XC Development Group
*/
#include <sys/types.h>
#include <unistd.h>
#include "gtm/libpq-fe.h"
#include "gtm/gtm_c.h"
#include "gtm/gtm_client.h"
#include "test_common.h"
pthread_key_t threadinfo_key;
void
setUp()
{
system("./stop.sh > /dev/null");
system("./clean.sh > /dev/null");
system("./start.sh > /dev/null");
}
void
tearDown()
{
GTMPQfinish(conn);
}
void
test_standby_01()
{
GlobalTransactionId gxid;
int rc;
SETUP();
system("killall -9 gtm_standby");
sprintf(connect_string, "host=localhost port=6666 node_name=one_zero_one remote_type=%d",
GTM_NODE_GTM);
conn = PQconnectGTM(connect_string);
_ASSERT( conn!=NULL );
_ASSERT( grep_count(LOG_ACTIVE, "Failed to establish a connection with GTM standby")==1 );
_ASSERT( grep_count(LOG_ACTIVE, "Calling report_xcwatch_gtm_failure()...")==1 );
TEARDOWN();
}
void
test_standby_02()
{
GlobalTransactionId gxid;
int rc;
SETUP();
connect1();
_ASSERT( conn!=NULL );
gxid = begin_transaction(conn, GTM_ISOLATION_SERIALIZABLE, timestamp);
_ASSERT( gxid != InvalidGlobalTransactionId );
_ASSERT( grep_count(LOG_ACTIVE, "Sending transaction id 3")==1 );
_ASSERT( grep_count(LOG_STANDBY, "Sending transaction id 3")==1 );
system("killall -9 gtm_standby");
rc = commit_transaction(conn, gxid);
_ASSERT( rc>=0 );
_ASSERT( grep_count(LOG_ACTIVE, "Committing transaction id 3")==1 );
_ASSERT( grep_count(LOG_ACTIVE, "communication error with standby.")==1 );
_ASSERT( grep_count(LOG_ACTIVE, "Calling report_xcwatch_gtm_failure()...")==1 );
_ASSERT( grep_count(LOG_STANDBY, "Committing transaction id 3")==0 );
TEARDOWN();
}
void
test_standby_03()
{
GlobalTransactionId gxid;
int rc;
SETUP();
connect1();
_ASSERT( conn!=NULL );
system("./status_a.sh > status");
_ASSERT( grep_count("status", "active: 1")==1 );
system("./status_s.sh > status");
_ASSERT( grep_count("status", "active: 0")==1 );
TEARDOWN();
}
void
test_standby_04()
{
GlobalTransactionId gxid;
int rc;
SETUP();
connect1();
_ASSERT( conn!=NULL );
system("./status_a.sh > status");
_ASSERT( grep_count("status", "active: 1")==1 );
system("./status_s.sh > status");
_ASSERT( grep_count("status", "active: 0")==1 );
system("killall -9 gtm");
system("./promote.sh");
GTMPQfinish(conn);
connect2();
_ASSERT( conn!=NULL );
system("./status_s.sh > status");
_ASSERT( grep_count("status", "active: 1")==1 );
TEARDOWN();
}
int
main(int argc, char *argv[])
{
test_standby_01();
test_standby_02();
test_standby_03(); /* get status */
test_standby_04(); /* promote */
return 0;
}
|