This has following fixes.
[csql.git] / test / dbapi / Connection / isotest12.c
blobfd99b12a08e5d1487e66278d77988ae9acba62e3
1 #include "common.h"
2 //READ_UNCOMMITTED isolation testing
3 // T1 and T2 both doing select for same tuple
5 void* runTest1(void *p);
6 void* runTest2(void *p);
7 int main()
10 Connection conn;
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; }
17 rv = conn.startTransaction();
18 if (rv != OK) {printf ("Unable to start trans\n"); return 1; }
19 rv = insert(dbMgr, 100, false);
20 if (rv != OK) { printf("Unable to insert\n"); return 2; }
21 conn.commit();
22 printf("Tuple inserted\n");
24 pthread_t thr[2];
25 int *status1, *status2;
26 pthread_create (&thr[0], NULL, &runTest1, NULL);
27 pthread_create (&thr[1], NULL, &runTest2, NULL);
28 printf("All threads started\n");
30 pthread_join(thr[0], (void**)&status1);
31 pthread_join(thr[1], (void**)&status2);
32 ret = 0;
33 if (*status1 != 0 || *status2 != 0) ret = 1;
34 dbMgr->dropTable("t1");
35 conn.close();
36 return ret;
38 void* runTest1(void *message)
40 Connection conn;
41 DbRetVal rv = conn.open("root", "manager");
42 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
43 DatabaseManager *dbMgr = conn.getDatabaseManager();
44 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
45 rv = conn.startTransaction(READ_UNCOMMITTED);
46 if (rv != OK) return NULL;
47 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
48 int *retval = new int();
49 *retval = 0;
50 rv = select(dbMgr, 100, true);
51 if (rv != OK) { printf("Test Failed:first thread failed to select\n"); *retval = 1; }
53 conn.commit();
54 rv = conn.close();
55 pthread_exit(retval);
57 void* runTest2(void *message)
59 Connection conn;
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_UNCOMMITTED);
65 if (rv != OK) return NULL;
66 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
68 int *retval = new int();
69 *retval = 0;
70 rv = select(dbMgr, 100, false);
71 if (rv != OK) { printf("Test Failed:second thread failed to select\n"); *retval = 1; }
72 conn.commit();
73 conn.close();
74 pthread_exit(retval);