2 //READ_COMMITTED isolation testing
3 //T1 doing Delete and T2 doing insert for same tuple
5 void* runTest1(void *p
);
6 void* runTest2(void *p
);
12 AbsSqlConnection
*conn
= createConnection();
13 DbRetVal rv
= conn
->connect("root", "manager");
14 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return 1; }
15 AbsSqlStatement
*stmt
= createStatement();
16 stmt
->setConnection(conn
);
18 char statement
[1024]="create table t1 (f1 int, f2 char(196), primary key(f1));";
19 int ret
= executeDdlQuery(conn
, stmt
, statement
);
20 if (ret
!= 0) { return 1; }
21 rv
= conn
->beginTrans(READ_COMMITTED
);
22 if (rv
!= OK
) return 2;
23 rv
= insert(stmt
, 100, false);
24 if (rv
!= OK
) { printf("Error in inserting the record\n"); return 3; }
26 printf("Tuple inserted\n");
29 int *status1
, *status2
;
30 pthread_create (&thr
[0], NULL
, &runTest1
, NULL
);
31 pthread_create (&thr
[1], NULL
, &runTest2
, NULL
);
32 printf("All threads started\n");
34 pthread_join(thr
[0], (void**)&status1
);
35 pthread_join(thr
[1], (void**)&status2
);
36 strcpy(statement
, "drop table t1;");
37 ret
= executeDdlQuery(conn
, stmt
, statement
);
38 if (ret
!= 0) { return 3; }
40 stmt
->free(); delete stmt
; delete conn
;
41 if (*status1
!= 0 || *status2
!= 0) return 4;
42 if (p1RetVal
) { delete p1RetVal
; p1RetVal
= NULL
; }
43 if (p2RetVal
) { delete p2RetVal
; p2RetVal
= NULL
; }
47 void* runTest1(void *message
)
49 AbsSqlConnection
*conn
= createConnection();
50 DbRetVal rv
= conn
->connect("root", "manager");
51 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
52 AbsSqlStatement
*stmt
= createStatement();
53 stmt
->setConnection(conn
);
55 rv
= conn
->beginTrans(READ_UNCOMMITTED
);
57 rv
= conn
->beginTrans(READ_REPEATABLE
);
59 rv
= conn
->beginTrans(READ_COMMITTED
);
61 if (rv
!= OK
) return NULL
;
62 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
66 rv
= remove(stmt
, 100, true);
67 if (rv
!= OK
) { printf("Test Failed:first thread failed to delete\n"); *p1RetVal
= 1; }
70 stmt
->free(); delete stmt
; delete conn
;
71 printf("conn closed %d for Thread and pid is %d %lu\n", rv
, os::getpid(), os::getthrid());
72 pthread_exit(p1RetVal
);
75 void* runTest2(void *message
)
77 AbsSqlConnection
*conn
= createConnection();
78 DbRetVal rv
= conn
->connect("root", "manager");
79 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
80 AbsSqlStatement
*stmt
= createStatement();
81 stmt
->setConnection(conn
);
83 rv
= conn
->beginTrans(READ_UNCOMMITTED
);
85 rv
= conn
->beginTrans(READ_REPEATABLE
);
87 rv
= conn
->beginTrans(READ_COMMITTED
);
89 if (rv
!= OK
) return NULL
;
90 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
93 rv
= insert(stmt
, 100, false);
95 printf("Test Failed:second thread inserts.\n");
99 rv
= conn
->disconnect();
100 stmt
->free(); delete stmt
; delete conn
;
101 printf("conn closed %d for Thread and pid is %d %lu\n", rv
, os::getpid(), os::getthrid());
102 pthread_exit(p2RetVal
);