test cases for trie index
[csql.git] / test / dbapi / Connection / isotest23.c
blobb9f20906c2489519e93550b759b2f7e1ee378e33
1 #include "common.h"
2 //READ_REPEATABLE Isolation testing
3 //T1 doing insert and T2 doing select for same tuple
4 int insertDone =0,selectDone=0;
5 void* runTest1(void *p);
6 void* runTest2(void *p);
7 int *p1RetVal = NULL;
8 int *p2RetVal = NULL;
9 int main()
12 Connection conn;
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; }
23 conn.commit();
24 printf("Tuple inserted\n");
26 pthread_t thr[2];
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);
34 ret = 0;
35 if (*status1 != 0 || *status2 != 0) ret = 1;
36 dbMgr->dropTable("t1");
37 conn.close();
38 if (p1RetVal) { delete p1RetVal; p1RetVal = NULL; }
39 if (p2RetVal) { delete p2RetVal; p2RetVal = NULL; }
40 return ret;
42 void* runTest1(void *message)
44 Connection conn;
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;}
49 rv = conn.startTransaction(READ_REPEATABLE);
50 if (rv != OK) return NULL;
51 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
52 p1RetVal = new int();
53 *p1RetVal = 0;
54 rv = insert(dbMgr, 200, true);
55 if (rv != OK) { printf("Test Failed:first thread failed to insert\n"); *p1RetVal = 1; }
56 insertDone =1;
57 while(selectDone !=1) ::sleep(1);
58 conn.commit();
59 rv = conn.close();
60 pthread_exit(p1RetVal);
62 void* runTest2(void *message)
64 Connection conn;
65 DbRetVal rv = conn.open("root", "manager");
66 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
67 DatabaseManager *dbMgr = conn.getDatabaseManager();
68 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
69 rv = conn.startTransaction(READ_REPEATABLE);
70 if (rv != OK) return NULL;
71 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
72 while (insertDone != 1) ::sleep(1);
73 p2RetVal = new int();
74 *p2RetVal = 0;
75 rv = select(dbMgr, 200, false);
76 if (rv != OK) { printf("Test Passed:second thread could not select\n"); *p2RetVal = 0; }
77 if (rv == OK) { printf("Test Failed:second thread could select\n"); *p2RetVal = 1; }
78 selectDone = 1;
79 conn.commit();
80 conn.close();
81 pthread_exit(p2RetVal);