2 //READ_COMMITTED isolation testing
3 //T1 doing Select and T2 doing delete for same tuple
6 void* runTest1(void *p
);
7 void* runTest2(void *p
);
13 AbsSqlConnection
*conn
= createConnection();
14 DbRetVal rv
= conn
->connect("root", "manager");
15 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return 1; }
16 AbsSqlStatement
*stmt
= createStatement();
17 stmt
->setConnection(conn
);
19 char statement
[1024]="create table t1 (f1 int, f2 char(196), primary key(f1));";
20 int ret
= executeDdlQuery(conn
, stmt
, statement
);
21 if (ret
!= 0) { return 1; }
22 rv
= conn
->beginTrans(READ_COMMITTED
);
23 if (rv
!= OK
) return 2;
24 rv
= insert(stmt
, 100, false);
25 if (rv
!= OK
) { printf("Error in inserting the record\n"); return 3; }
27 printf("Tuple inserted\n");
30 int *status1
, *status2
;
31 pthread_create (&thr
[0], NULL
, &runTest1
, NULL
);
32 pthread_create (&thr
[1], NULL
, &runTest2
, NULL
);
33 printf("All threads started\n");
35 pthread_join(thr
[0], (void**)&status1
);
36 pthread_join(thr
[1], (void**)&status2
);
37 strcpy(statement
, "drop table t1;");
38 ret
= executeDdlQuery(conn
, stmt
, statement
);
39 if (ret
!= 0) { return 3; }
41 stmt
->free(); delete stmt
; delete conn
;
42 if (*status1
!= 0 || *status2
!= 0) return 4;
43 if (p1RetVal
) { delete p1RetVal
; p1RetVal
= NULL
; }
44 if (p2RetVal
) { delete p2RetVal
; p2RetVal
= NULL
; }
48 void* runTest1(void *message
)
50 AbsSqlConnection
*conn
= createConnection();
51 DbRetVal rv
= conn
->connect("root", "manager");
52 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
53 AbsSqlStatement
*stmt
= createStatement();
54 stmt
->setConnection(conn
);
56 rv
= conn
->beginTrans(READ_UNCOMMITTED
);
58 rv
= conn
->beginTrans(READ_REPEATABLE
);
60 rv
= conn
->beginTrans(READ_COMMITTED
);
62 if (rv
!= OK
) return NULL
;
63 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
67 rv
= select(stmt
, 100, true);
68 if (rv
!= OK
) { printf("Test Failed:first thread failed to select\n"); *p1RetVal
= 1; }
71 stmt
->free(); delete stmt
; delete conn
;
72 printf("conn closed %d for Thread and pid is %d %lu\n", rv
, os::getpid(), os::getthrid());
73 pthread_exit(p1RetVal
);
76 void* runTest2(void *message
)
78 AbsSqlConnection
*conn
= createConnection();
79 DbRetVal rv
= conn
->connect("root", "manager");
80 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
81 AbsSqlStatement
*stmt
= createStatement();
82 stmt
->setConnection(conn
);
84 rv
= conn
->beginTrans(READ_UNCOMMITTED
);
86 rv
= conn
->beginTrans(READ_REPEATABLE
);
88 rv
= conn
->beginTrans(READ_COMMITTED
);
90 if (rv
!= OK
) return NULL
;
91 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
94 rv
= remove(stmt
, 100, false);
97 printf("Test Failed:second thread failed to remove.\n");
100 printf("Test Failed:second thread removes.\n");
103 printf("Test Failed:second thread failed to remove.\n");
108 rv
= conn
->disconnect();
109 stmt
->free(); delete stmt
; delete conn
;
110 printf("conn closed %d for Thread and pid is %d %lu\n", rv
, os::getpid(), os::getthrid());
111 pthread_exit(p2RetVal
);