2 //READ_COMMITTED isolation testing
3 // T1 and T2 both doing select for same tuple
5 void* runTest1(void *p
);
6 void* runTest2(void *p
);
13 DbRetVal rv
= conn
.open("root", "manager");
14 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return 1; }
15 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
16 int ret
= createTable(dbMgr
);
17 if (ret
!= 0) { return 1; }
19 rv
= conn
.startTransaction();
20 if (rv
!= OK
) {printf ("Unable to start trans\n"); return 1; }
21 rv
= insert(dbMgr
, 100, false);
22 if (rv
!= OK
) { printf("Unable to insert\n"); return 2; }
24 printf("Tuple inserted\n");
27 int *status1
, *status2
;
28 pthread_create (&thr
[0], NULL
, &runTest1
, NULL
);
29 pthread_create (&thr
[1], NULL
, &runTest2
, NULL
);
30 printf("All threads started\n");
32 pthread_join(thr
[0], (void**)&status1
);
33 pthread_join(thr
[1], (void**)&status2
);
35 if (*status1
!= 0 || *status2
!= 0) ret
= 1;
36 dbMgr
->dropTable("t1");
38 if (p1RetVal
) { delete p1RetVal
; p1RetVal
= NULL
; }
39 if (p2RetVal
) { delete p2RetVal
; p2RetVal
= NULL
; }
42 void* runTest1(void *message
)
45 DbRetVal rv
= conn
.open("root", "manager");
46 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
47 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
48 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
50 rv
= conn
.startTransaction(READ_COMMITTED
);
52 rv
= conn
.startTransaction();
54 if (rv
!= OK
) return NULL
;
55 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
58 rv
= select(dbMgr
, 100, true);
59 if (rv
!= OK
) { printf("Test Failed:first thread failed to select\n"); *p1RetVal
= 1; }
63 pthread_exit(p1RetVal
);
65 void* runTest2(void *message
)
69 DbRetVal rv
= conn
.open("root", "manager");
70 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
71 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
72 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
74 rv
= conn
.startTransaction(READ_COMMITTED
);
76 rv
= conn
.startTransaction();
79 if (rv
!= OK
) return NULL
;
80 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
84 rv
= select(dbMgr
, 100, false);
85 if (rv
!= OK
) { printf("Test Failed:second thread failed to select\n"); *p2RetVal
= 1; }
88 pthread_exit(p2RetVal
);