start only if sql server if turned on in csql.conf file
[csql.git] / test / dbapi / Connection / isotest1.c
blobbb2793e103efb9b2e1867d5d5b8c62e81f638159
1 #include "common.h"
2 //READ_COMMITTED 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);
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 pthread_t thr[2];
20 int *status1, *status2;
21 pthread_create (&thr[0], NULL, &runTest1, NULL);
22 pthread_create (&thr[1], NULL, &runTest2, NULL);
23 printf("All threads started\n");
25 pthread_join(thr[0], (void**)&status1);
26 pthread_join(thr[1], (void**)&status2);
27 dbMgr->dropTable("t1");
28 conn.close();
29 if (*status1 != 0 || *status2 != 0) return 1;
30 if (p1RetVal) { delete p1RetVal; p1RetVal = NULL; }
31 if (p2RetVal) { delete p2RetVal; p2RetVal = NULL; }
32 return 0;
34 void* runTest1(void *message)
36 Connection conn;
37 DbRetVal rv = conn.open("root", "manager");
38 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
39 DatabaseManager *dbMgr = conn.getDatabaseManager();
40 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
41 #ifndef DEFAULT
42 rv = conn.startTransaction(READ_COMMITTED);
43 #else
44 rv = conn.startTransaction();
45 #endif
46 if (rv != OK) return NULL;
47 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
48 p1RetVal = new int();
49 *p1RetVal = 0;
51 rv = insert(dbMgr, 100, true);
52 if (rv != OK) { printf("Test Failed:first thread failed to insert\n"); *p1RetVal = 1; }
54 conn.commit();
55 rv = conn.close();
56 printf("conn closed %d for Thread and pid is %d %lu\n", rv, os::getpid(), os::getthrid());
57 pthread_exit(p1RetVal);
59 void* runTest2(void *message)
61 Connection conn;
62 DbRetVal rv = conn.open("root", "manager");
63 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
64 DatabaseManager *dbMgr = conn.getDatabaseManager();
65 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
66 #ifndef DEFAULT
67 rv = conn.startTransaction(READ_COMMITTED);
68 #else
69 rv = conn.startTransaction();
70 #endif
71 if (rv != OK) return NULL;
72 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
74 p2RetVal = new int();
75 *p2RetVal = 0;
76 ::sleep(2);
77 rv = insert(dbMgr, 100, false);
78 if (rv == OK) { printf("Test Failed:second thread inserted\n"); *p2RetVal = 1; }
80 conn.commit();
81 rv = conn.close();
82 printf("conn closed %d for Thread and pid is %d %lu\n", rv, os::getpid(), os::getthrid());
83 pthread_exit(p2RetVal);