This has following fixes.
[csql.git] / test / dbapi / Connection / isotest21.c
blob1f541ba429aeceb0cc3d2b6a035720d5768672a8
1 #include "common.h"
2 //READ_REPEATABLE 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 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 pthread_t thr[2];
18 int *status1, *status2;
19 pthread_create (&thr[0], NULL, &runTest1, NULL);
20 pthread_create (&thr[1], NULL, &runTest2, NULL);
21 printf("All threads started\n");
23 pthread_join(thr[0], (void**)&status1);
24 pthread_join(thr[1], (void**)&status2);
25 dbMgr->dropTable("t1");
26 conn.close();
27 if (*status1 != 0 || *status2 != 0) return 1;
28 return 0;
30 void* runTest1(void *message)
32 Connection conn;
33 DbRetVal rv = conn.open("root", "manager");
34 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
35 DatabaseManager *dbMgr = conn.getDatabaseManager();
36 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
37 rv = conn.startTransaction(READ_REPEATABLE);
38 if (rv != OK) return NULL;
39 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
40 int *retval = new int();
41 *retval = 0;
43 rv = insert(dbMgr, 100, true);
44 if (rv != OK) { printf("Test Failed:first thread failed to insert\n"); *retval = 1; }
46 conn.commit();
47 rv = conn.close();
48 printf("conn closed %d for Thread and pid is %d %lu\n", rv, os::getpid(), os::getthrid());
49 pthread_exit(retval);
51 void* runTest2(void *message)
53 Connection conn;
54 DbRetVal rv = conn.open("root", "manager");
55 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
56 DatabaseManager *dbMgr = conn.getDatabaseManager();
57 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
58 rv = conn.startTransaction(READ_REPEATABLE);
59 if (rv != OK) return NULL;
60 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
62 int *retval = new int();
63 *retval = 0;
65 rv = insert(dbMgr, 100, false);
66 if (rv == OK) { printf("Test Failed:second thread inserted\n"); *retval = 1; }
68 conn.commit();
69 rv = conn.close();
70 printf("conn closed %d for Thread and pid is %d %lu\n", rv, os::getpid(), os::getthrid());
71 pthread_exit(retval);