This has following fixes.
[csql.git] / test / dbapi / Connection / isotest7.c
blob24af4aded1bef07d7d864818c126bcc9e7015d7a
1 #include "common.h"
2 //READ_COMMITTED isolation testing
3 //T1 doing update and T2 doing delete for same tuple
4 //delete should fail
6 void* runTest1(void *p);
7 void* runTest2(void *p);
8 int main()
11 Connection conn;
12 DbRetVal rv = conn.open("root", "manager");
13 if (rv != OK) { printf("Error during connection %d\n", rv); return 1; }
14 DatabaseManager *dbMgr = conn.getDatabaseManager();
15 int ret = createTable(dbMgr);
16 if (ret != 0) { return 1; }
18 rv = conn.startTransaction();
19 if (rv != OK) {printf ("Unable to start trans\n"); return 1; }
20 rv = insert(dbMgr, 100, false);
21 if (rv != OK) { printf("Unable to insert\n"); return 2; }
22 conn.commit();
23 printf("Tuple inserted\n");
25 pthread_t thr[2];
26 int *status1, *status2;
27 pthread_create (&thr[0], NULL, &runTest1, NULL);
28 pthread_create (&thr[1], NULL, &runTest2, NULL);
29 printf("All threads started\n");
31 pthread_join(thr[0], (void**)&status1);
32 pthread_join(thr[1], (void**)&status2);
33 ret = 0;
34 if (*status1 != 0 || *status2 != 0) ret = 1;
35 dbMgr->dropTable("t1");
36 conn.close();
37 return ret;
39 void* runTest1(void *message)
41 Connection conn;
42 DbRetVal rv = conn.open("root", "manager");
43 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
44 DatabaseManager *dbMgr = conn.getDatabaseManager();
45 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
46 #ifndef DEFAULT
47 rv = conn.startTransaction(READ_COMMITTED);
48 #else
49 rv = conn.startTransaction();
50 #endif
52 if (rv != OK) return NULL;
53 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
54 int *retval = new int();
55 *retval = 0;
56 rv = update(dbMgr, 100, true);
57 if (rv != OK) { printf("Test Failed:first thread failed to update\n"); *retval = 1; }
59 conn.commit();
60 rv = conn.close();
61 pthread_exit(retval);
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 #ifndef DEFAULT
71 rv = conn.startTransaction(READ_COMMITTED);
72 #else
73 rv = conn.startTransaction();
74 #endif
76 if (rv != OK) return NULL;
77 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
79 int *retval = new int();
80 *retval = 0;
81 rv = remove(dbMgr, 100, false);
82 if (rv == OK) { printf("Test Failed:second thread deleted\n"); *retval = 1; }
83 conn.commit();
84 conn.close();
85 pthread_exit(retval);