Removing large file for data load. Modified README to generate mysql and psql input...
[csql.git] / test / dbapi / Connection / isotest16.c
blobeed76dfde22448deaee795a31777cc2773615e43
1 #include "common.h"
2 //READ_UNCOMMITTED
3 //T1 doing delete and T2 doing insert for same tuple
4 //Insert should fail
5 int deleteDone=0, allDone=0;
6 void* runTest1(void *p);
7 void* runTest2(void *p);
8 int *p1RetVal = NULL;
9 int *p2RetVal = NULL;
10 int main()
13 Connection conn;
14 DbRetVal rv = conn.open("root", "manager");
15 if (rv != OK) { printf("Error during connection %d\n", rv); return 1; }
16 DatabaseManager *dbMgr = conn.getDatabaseManager();
17 int ret = createTable(dbMgr);
18 if (ret != 0) { return 1; }
20 rv = conn.startTransaction();
21 if (rv != OK) {printf ("Unable to start trans\n"); return 1; }
22 rv = insert(dbMgr, 100, false);
23 if (rv != OK) { printf("Unable to insert\n"); return 2; }
24 conn.commit();
25 printf("Tuple inserted\n");
27 pthread_t thr[2];
28 int *status1, *status2;
29 pthread_create (&thr[0], NULL, &runTest1, NULL);
30 pthread_create (&thr[1], NULL, &runTest2, NULL);
31 printf("All threads started\n");
33 pthread_join(thr[0], (void**)&status1);
34 pthread_join(thr[1], (void**)&status2);
35 ret = 0;
36 if (*status1 != 0 || *status2 != 0) ret = 1;
37 dbMgr->dropTable("t1");
38 conn.close();
39 if (p1RetVal) { delete p1RetVal; p1RetVal = NULL; }
40 if (p2RetVal) { delete p2RetVal; p2RetVal = NULL; }
41 return ret;
43 void* runTest1(void *message)
45 Connection conn;
46 DbRetVal rv = conn.open("root", "manager");
47 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
48 DatabaseManager *dbMgr = conn.getDatabaseManager();
49 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
50 rv = conn.startTransaction(READ_UNCOMMITTED);
51 if (rv != OK) return NULL;
52 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
53 p1RetVal = new int();
54 *p1RetVal = 0;
55 rv = remove(dbMgr, 100, true);
56 if (rv != OK) { printf("Test Failed:first thread failed to delete\n"); *p1RetVal = 1; }
57 deleteDone = 1;
58 while (allDone !=1) ::sleep(1);
59 conn.commit();
60 rv = conn.close();
61 pthread_exit(p1RetVal);
63 void* runTest2(void *message)
65 Connection conn;
66 DbRetVal rv = conn.open("root", "manager");
67 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
68 DatabaseManager *dbMgr = conn.getDatabaseManager();
69 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
70 rv = conn.startTransaction(READ_UNCOMMITTED);
71 if (rv != OK) return NULL;
72 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
73 while (deleteDone != 1) {::sleep(1); }
74 p2RetVal = new int();
75 *p2RetVal = 0;
76 rv = insert(dbMgr, 100, false);
77 if (rv == OK) { printf("Test Failed:second thread inserted\n"); *p2RetVal = 1; }
78 allDone =1;
79 conn.commit();
80 conn.close();
81 pthread_exit(p2RetVal);