2 //READ_UNCOMMITTED isolation testing
3 //T1 doing select and T2 doing update for same tuple
6 void* runTest1(void *p
);
7 void* runTest2(void *p
);
15 DbRetVal rv
= conn
.open("root", "manager");
16 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return 1; }
17 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
18 int ret
= createTable(dbMgr
);
19 if (ret
!= 0) { return 1; }
21 rv
= conn
.startTransaction();
22 if (rv
!= OK
) {printf ("Unable to start trans\n"); return 1; }
23 rv
= insert(dbMgr
, 100, false);
24 if (rv
!= OK
) { printf("Unable to insert\n"); return 2; }
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
);
37 if (*status1
!= 0 || *status2
!= 0) ret
= 1;
38 dbMgr
->dropTable("t1");
40 if (p1RetVal
) { delete p1RetVal
; p1RetVal
= NULL
; }
41 if (p2RetVal
) { delete p2RetVal
; p2RetVal
= NULL
; }
45 void* runTest1(void *message
)
48 DbRetVal rv
= conn
.open("root", "manager");
49 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
50 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
51 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
52 rv
= conn
.startTransaction(READ_UNCOMMITTED
);
53 if (rv
!= OK
) return NULL
;
54 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
57 rv
= select(dbMgr
, 100, true);
58 if (rv
!= OK
) { printf("Test Failed:first thread failed to select\n"); *p1RetVal
= 1; }
62 pthread_exit(p1RetVal
);
64 void* runTest2(void *message
)
67 DbRetVal rv
= conn
.open("root", "manager");
68 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
69 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
70 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
71 rv
= conn
.startTransaction(READ_UNCOMMITTED
);
72 if (rv
!= OK
) return NULL
;
73 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
77 rv
= update(dbMgr
, 100, false);
78 if (rv
!= OK
) { printf("Test Failed:second thread failed to update\n"); *p2RetVal
= 1; }
81 pthread_exit(p2RetVal
);