summaryrefslogtreecommitdiff
path: root/src/gtm/test/test_common.c
blob: 022e4f0554a5965919efb151b65007acedc565cb (plain)
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
#include "test_common.h"

pthread_key_t     threadinfo_key;

GTM_ThreadID      TopMostThreadID;

GTM_Conn *conn = NULL;
GTM_Conn *conn2 = NULL;
GTM_Timestamp *timestamp = NULL;
char connect_string[100];

void
print_nodeinfo(GTM_PGXCNodeInfo d)
{
	client_log(("type=%d, nodename=%s, proxyname=%s, ipaddress=%s, port=%d, datafolder=%s, status=%d\n",
		    d.type,
		    d.nodename,
		    d.proxyname,
		    d.ipaddress,
		    d.port,
		    d.datafolder,
		    d.status));
}


/*
 * Connect to active GTM.
 */
void
connect1()
{
	sprintf(connect_string, "host=localhost port=6666 node_name=one_zero_one remote_type=%d",
		GTM_NODE_GTM);
	
	conn = PQconnectGTM(connect_string);
	if (conn == NULL)
	{
		client_log(("Error in connection\n"));
		exit(1);
	}
	client_log(("PGconnectGTM() ok.\n"));
}

/*
 * Connect to standby GTM.
 */
void
connect2()
{
	sprintf(connect_string, "host=localhost port=6667 node_name=one_zero_two remote_type=%d",
		GTM_NODE_GTM);
	
	conn = PQconnectGTM(connect_string);
	if (conn == NULL)
	{
		client_log(("Error in connection\n"));
		exit(1);
	}
	client_log(("PGconnectGTM() ok.\n"));
}


/*
 * Get a word count with using grep command in a log file.
 */
int
grep_count(const char *file, const char *key)
{
	FILE *fp;
	int count;
	char cmd[1024];

	snprintf(cmd, sizeof(cmd), "grep -c '%s' %s", key, file);

	fp = popen(cmd, "r");
	fscanf(fp, "%d", &count);
	pclose(fp);

	return count;
}