2 //READ_REPEATABLE isolation testing
4 // -------------------------
8 // T1 should fail to get read lock
9 void* runTest1(void *p
);
10 void* runTest2(void *p
);
13 int selectDone
=0, updateDone
=0, select2Done
=0;
18 DbRetVal rv
= conn
.open("root", "manager");
19 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return 1; }
20 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
21 int ret
= createTable(dbMgr
);
22 if (ret
!= 0) { return 1; }
24 rv
= conn
.startTransaction();
25 if (rv
!= OK
) {printf ("Unable to start trans\n"); return 1; }
26 rv
= insert(dbMgr
, 100, false);
27 if (rv
!= OK
) { printf("Unable to insert\n"); return 2; }
29 printf("Tuple inserted\n");
32 int *status1
, *status2
;
33 pthread_create (&thr
[0], NULL
, &runTest1
, NULL
);
34 pthread_create (&thr
[1], NULL
, &runTest2
, NULL
);
35 printf("All threads started\n");
37 pthread_join(thr
[0], (void**)&status1
);
38 pthread_join(thr
[1], (void**)&status2
);
40 if (*status1
!= 0 || *status2
!= 0) ret
= 1;
41 dbMgr
->dropTable("t1");
43 if (p1RetVal
) { delete p1RetVal
; p1RetVal
= NULL
; }
44 if (p2RetVal
) { delete p2RetVal
; p2RetVal
= NULL
; }
47 void* runTest1(void *message
)
50 DbRetVal rv
= conn
.open("root", "manager");
51 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
52 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
53 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
54 rv
= conn
.startTransaction(READ_REPEATABLE
);
55 if (rv
!= OK
) return NULL
;
56 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
59 rv
= select(dbMgr
, 100, true);
60 if (rv
!= OK
) { printf("Test Failed:first thread first read failed \n"); *p1RetVal
= 1; }
62 while (updateDone
!=1) ::sleep(1);
63 rv
= select(dbMgr
, 100, true, false);
64 if (rv
!= OK
) { printf("Test Failed:first thread second read failed %d \n", rv
); *p1RetVal
= 1; }
68 pthread_exit(p1RetVal
);
70 void* runTest2(void *message
)
73 DbRetVal rv
= conn
.open("root", "manager");
74 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
75 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
76 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
77 rv
= conn
.startTransaction(READ_REPEATABLE
);
78 if (rv
!= OK
) return NULL
;
79 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
80 while (selectDone
!=1) ::sleep(1);
83 rv
= update(dbMgr
, 100, true);
84 if (rv
!= OK
) { printf("Test Passed:second thread did not update\n"); *p2RetVal
= 0; }
85 if (rv
== OK
) { printf("Test Failed:second thread updated\n"); *p2RetVal
= 1; }
87 while(select2Done
!=1) ::sleep(1);
90 pthread_exit(p2RetVal
);