2 //READ_REPEATABLE isolation testing
3 //T1 and T2 both inserting, T2 will fail saying unique key constraint
5 void* runTest1(void *p
);
6 void* runTest2(void *p
);
11 DbRetVal rv
= conn
.open("root", "manager");
12 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return 1; }
13 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
14 int ret
= createTable(dbMgr
);
15 if (ret
!= 0) { return 1; }
18 int *status1
, *status2
;
19 pthread_create (&thr
[0], NULL
, &runTest1
, NULL
);
20 pthread_create (&thr
[1], NULL
, &runTest2
, NULL
);
21 printf("All threads started\n");
23 pthread_join(thr
[0], (void**)&status1
);
24 pthread_join(thr
[1], (void**)&status2
);
25 dbMgr
->dropTable("t1");
27 if (*status1
!= 0 || *status2
!= 0) return 1;
30 void* runTest1(void *message
)
33 DbRetVal rv
= conn
.open("root", "manager");
34 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
35 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
36 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
37 rv
= conn
.startTransaction(READ_REPEATABLE
);
38 if (rv
!= OK
) return NULL
;
39 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
40 int *retval
= new int();
43 rv
= insert(dbMgr
, 100, true);
44 if (rv
!= OK
) { printf("Test Failed:first thread failed to insert\n"); *retval
= 1; }
48 printf("conn closed %d for Thread and pid is %d %lu\n", rv
, os::getpid(), os::getthrid());
51 void* runTest2(void *message
)
54 DbRetVal rv
= conn
.open("root", "manager");
55 if (rv
!= OK
) { printf("Error during connection %d\n", rv
); return NULL
; }
56 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
57 if (dbMgr
== NULL
) { printf("Auth failed\n"); return NULL
;}
58 rv
= conn
.startTransaction(READ_REPEATABLE
);
59 if (rv
!= OK
) return NULL
;
60 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
62 int *retval
= new int();
65 rv
= insert(dbMgr
, 100, false);
66 if (rv
== OK
) { printf("Test Failed:second thread inserted\n"); *retval
= 1; }
70 printf("conn closed %d for Thread and pid is %d %lu\n", rv
, os::getpid(), os::getthrid());