2 //READ_REPEATABLE isolation testing
3 //T1 doing update and T2 doing delete for same tuple
6 void* runTest1(void *p
);
7 void* runTest2(void *p
);
12 DbRetVal rv
= conn
.open("root", "manager");
13 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return 1; }
14 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
15 int ret
= createTable(dbMgr
);
16 if (ret
!= 0) { return 1; }
18 rv
= conn
.startTransaction();
19 if (rv
!= OK
) {printf ("Unable to start trans\n"); return 1; }
20 rv
= insert(dbMgr
, 100, false);
21 if (rv
!= OK
) { printf("Unable to insert\n"); return 2; }
23 printf("Tuple inserted\n");
26 int *status1
, *status2
;
27 pthread_create (&thr
[0], NULL
, &runTest1
, NULL
);
28 pthread_create (&thr
[1], NULL
, &runTest2
, NULL
);
29 printf("All threads started\n");
31 pthread_join(thr
[0], (void**)&status1
);
32 pthread_join(thr
[1], (void**)&status2
);
34 if (*status1
!= 0 || *status2
!= 0) ret
= 1;
35 dbMgr
->dropTable("t1");
39 void* runTest1(void *message
)
42 DbRetVal rv
= conn
.open("root", "manager");
43 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
44 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
45 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
46 rv
= conn
.startTransaction(READ_REPEATABLE
);
47 if (rv
!= OK
) return NULL
;
48 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
49 int *retval
= new int();
51 rv
= update(dbMgr
, 100, true);
52 if (rv
!= OK
) { printf("Test Failed:first thread failed to update\n"); *retval
= 1; }
57 void* runTest2(void *message
)
60 DbRetVal rv
= conn
.open("root", "manager");
61 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
62 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
63 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
64 rv
= conn
.startTransaction(READ_REPEATABLE
);
65 if (rv
!= OK
) return NULL
;
66 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
68 int *retval
= new int();
70 rv
= remove(dbMgr
, 100, false);
71 if (rv
== OK
) { printf("Test Failed:second thread deleted\n"); *retval
= 1; }