2 //READ_COMMITTED isolation testing
3 //T1 doing update and T2 doing delete for same tuple
6 void* runTest1(void *p
);
7 void* runTest2(void *p
);
14 DbRetVal rv
= conn
.open("root", "manager");
15 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return 1; }
16 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
17 int ret
= createTable(dbMgr
);
18 if (ret
!= 0) { return 1; }
20 rv
= conn
.startTransaction();
21 if (rv
!= OK
) {printf ("Unable to start trans\n"); return 1; }
22 rv
= insert(dbMgr
, 100, false);
23 if (rv
!= OK
) { printf("Unable to insert\n"); return 2; }
25 printf("Tuple inserted\n");
28 int *status1
, *status2
;
29 pthread_create (&thr
[0], NULL
, &runTest1
, NULL
);
30 pthread_create (&thr
[1], NULL
, &runTest2
, NULL
);
31 printf("All threads started\n");
33 pthread_join(thr
[0], (void**)&status1
);
34 pthread_join(thr
[1], (void**)&status2
);
36 if (*status1
!= 0 || *status2
!= 0) ret
= 1;
37 dbMgr
->dropTable("t1");
39 if (p1RetVal
) { delete p1RetVal
; p1RetVal
= NULL
; }
40 if (p2RetVal
) { delete p2RetVal
; p2RetVal
= NULL
; }
43 void* runTest1(void *message
)
46 DbRetVal rv
= conn
.open("root", "manager");
47 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
48 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
49 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
51 rv
= conn
.startTransaction(READ_COMMITTED
);
53 rv
= conn
.startTransaction();
56 if (rv
!= OK
) return NULL
;
57 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
60 rv
= update(dbMgr
, 100, true);
61 if (rv
!= OK
) { printf("Test Failed:first thread failed to update\n"); *p1RetVal
= 1; }
65 pthread_exit(p1RetVal
);
67 void* runTest2(void *message
)
71 DbRetVal rv
= conn
.open("root", "manager");
72 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
73 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
74 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
76 rv
= conn
.startTransaction(READ_COMMITTED
);
78 rv
= conn
.startTransaction();
81 if (rv
!= OK
) return NULL
;
82 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
86 rv
= remove(dbMgr
, 100, false);
87 if (rv
== OK
) { printf("Test Failed:second thread deleted\n"); *p2RetVal
= 1; }
90 pthread_exit(p2RetVal
);