This has following fixes.
[csql.git] / test / dbapi / Connection / isotest16.c
blob0b01bdf45576e098ebd88275e3d7afb79b6f3d53
1 #include "common.h"
2 //READ_UNCOMMITTED
3 //T1 doing delete and T2 doing insert for same tuple
4 //Insert 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;
38 //Hardcoded to fail: It is giving wrong message. Check that and remove this
39 return 1;
41 void* runTest1(void *message)
43 Connection conn;
44 DbRetVal rv = conn.open("root", "manager");
45 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
46 DatabaseManager *dbMgr = conn.getDatabaseManager();
47 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
48 rv = conn.startTransaction(READ_UNCOMMITTED);
49 if (rv != OK) return NULL;
50 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
51 int *retval = new int();
52 *retval = 0;
53 rv = remove(dbMgr, 100, true);
54 if (rv != OK) { printf("Test Failed:first thread failed to delete\n"); *retval = 1; }
56 conn.commit();
57 rv = conn.close();
58 pthread_exit(retval);
60 void* runTest2(void *message)
62 Connection conn;
63 DbRetVal rv = conn.open("root", "manager");
64 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
65 DatabaseManager *dbMgr = conn.getDatabaseManager();
66 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
67 rv = conn.startTransaction(READ_UNCOMMITTED);
68 if (rv != OK) return NULL;
69 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
71 int *retval = new int();
72 *retval = 0;
73 rv = insert(dbMgr, 100, false);
74 if (rv == OK) { printf("Test Failed:second thread inserted\n"); *retval = 1; }
75 conn.commit();
76 conn.close();
77 pthread_exit(retval);