summaryrefslogtreecommitdiff
path: root/src/gtm/test/test_scenario.c
blob: f7d938d97895775e3d06ae2e70f609f1e0c67795 (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
81
82
83
84
85
86
/*
 * 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 "gtm/register.h"

#include "test_common.h"

pthread_key_t     threadinfo_key;

void
setUp()
{
	sprintf(connect_string, "host=localhost port=6666 node_name=one remote_type=%d",
		GTM_NODE_GTM);
	
	conn = PQconnectGTM(connect_string);

	_ASSERT( conn!=NULL );
}

void
tearDown()
{
	GTMPQfinish(conn);
}

void
test01()
{
	GlobalTransactionId gxid;
	int rc;
	char host[1024];

	printf("\n=== test01:node_register ===\n");

	setUp();

	node_get_local_addr(conn, host, sizeof(host));

	/*
	 * starting
	 */
	rc = node_register_internal(conn, GTM_NODE_GTM, host, 6667, "One zero two", "/tmp/pgxc/data/gtm_standby", NODE_DISCONNECTED);
	_ASSERT(rc == 0);
	rc = node_unregister(conn, GTM_NODE_GTM, "One zero two");
	_ASSERT(rc == 0);

	rc = node_register_internal(conn, GTM_NODE_GTM, host, 6667, "One zero two", "/tmp/pgxc/data/gtm_standby", NODE_CONNECTED);
	_ASSERT(rc == 0);

	sleep(10);

	gxid = begin_transaction(conn, GTM_ISOLATION_SERIALIZABLE, timestamp);
	_ASSERT( gxid!=InvalidGlobalTransactionId );

	rc = prepare_transaction(conn, gxid);
	_ASSERT( rc!=-1 );

	rc = abort_transaction(conn, gxid);
	_ASSERT( rc!=-1 );

	sleep(10);

	/*
	 * closing
	 */
	rc = node_unregister(conn, GTM_NODE_GTM, "One zero two");
	_ASSERT( rc==0 );

	tearDown();
}

int
main(int argc, char *argv[])
{
	test01();

	return 0;
}