summaryrefslogtreecommitdiff
path: root/src/gtm/test2/test_txn4.c
blob: fb55f237c2480eda404ce718617bf94e7405a1c7 (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
87
/*
 * 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()
{
	connect1();
}

void
tearDown()
{
	GTMPQfinish(conn);
}

void
test_txn4_01()
{
	GlobalTransactionId gxid;
	int rc;

	SETUP();

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

	rc = prepare_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	rc = commit_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	_ASSERT( grep_count(LOG_STANDBY, "Sending transaction id 3")==1 );
	_ASSERT( grep_count(LOG_STANDBY, "Preparing transaction id 3")==1 );
	_ASSERT( grep_count(LOG_STANDBY, "Committing transaction id 3")==1 );

	TEARDOWN();
}

void
test_txn4_02()
{
	GlobalTransactionId gxid;
	int rc;

	SETUP();

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

	rc = prepare_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	rc = abort_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	_ASSERT( grep_count(LOG_STANDBY, "Sending transaction id 4")==1 );
	_ASSERT( grep_count(LOG_STANDBY, "Preparing transaction id 4")==1 );
	_ASSERT( grep_count(LOG_STANDBY, "Cancelling transaction id 4")==1 );

	TEARDOWN();
}

int
main(int argc, char *argv[])
{
	system("./stop.sh");
	system("./clean.sh");
	system("./start.sh");

	test_txn4_01();
	test_txn4_02();

	return 0;
}