Addding test cases for connection and datatype module.
[csql.git] / test / performance / DMLThreadTest.c
blob790ea609d0f390769c691ce80d414418abc8fbf7
1 #include<CSql.h>
2 #include<NanoTimer.h>
3 #define THREADS 2
4 void* runTest(void *p);
5 int main()
8 Connection conn;
9 DbRetVal rv = conn.open("praba", "manager");
10 if (rv != OK)
12 printf("Error during connection %d\n", rv);
13 return -1;
15 DatabaseManager *dbMgr = conn.getDatabaseManager();
16 if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
17 TableDef tabDef;
18 tabDef.addField("f1", typeInt, 0, NULL, true, true);
19 tabDef.addField("f2", typeString, 196);
20 rv = dbMgr->createTable("t1", tabDef);
21 if (rv != OK) { printf("Table creation failed\n"); return -1; }
22 printf("Table created\n");
23 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
24 strcpy(idxInfo->tableName, "t1");
25 idxInfo->list.append("f1");
26 idxInfo->indType = hashIndex;
27 rv = dbMgr->createIndex("indx1", idxInfo);
28 if (rv != OK) { printf("Index creation failed\n"); return -1; }
29 printf("Index created %d %lu\n", os::getpid(), os::getthrid());
31 pthread_t thr[THREADS];
32 int message[THREADS];
33 int status;
34 for (int i=0; i <THREADS; i++) {
35 message[i] = i;
36 pthread_create (&thr[i], NULL,
37 &runTest, (void *) &message[i]);
38 //&runTest, NULL);
40 printf("All threads started\n");
41 for (int i=0; i <THREADS; i++) {
42 pthread_join(thr[i], (void**)&status);
44 //dbMgr->dropTable("t1");
45 conn.close();
46 return 0;
48 void* runTest(void *message)
50 Connection conn;
51 DbRetVal rv = conn.open("praba", "manager");
52 if (rv != OK)
54 printf("Error during connection %d\n", rv);
55 return NULL;
57 DatabaseManager *dbMgr = conn.getDatabaseManager();
58 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
59 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
60 Table *table = dbMgr->openTable("t1");
61 if (table == NULL) { printf("Unable to open table\n"); return NULL; }
62 int id = 0;
63 char name[196] = "PRABAKARAN";
64 table->bindFld("f1", &id);
65 table->bindFld("f2", name);
66 char *tuple;
67 int ret;
68 int i;
69 int icount =0;
70 NanoTimer timer;
71 int val = *(int*)message;
72 // int val = 0;
73 //printf("PRABA::val in this thread %d is %d\n", val, os::getthrid());
74 printf("PRABA::val in this thread %d is %lu\n", val, ::pthread_self());
75 if (val == 0) sleep(1);
76 for(i = val * 10; i< (val *10) +10; i++)
78 timer.start();
79 rv = conn.startTransaction();
80 if (rv != OK) exit(1);
81 id= i;
82 strcpy(name, "PRABAKARAN0123456750590");
83 printf("%d %lu \n ", i, os::getthrid());
84 ret = table->insertTuple();
85 if (ret != 0) break;
86 icount++;
87 conn.commit();
88 timer.stop();
90 char msgBuf[1024];
91 sprintf(msgBuf,"Total rows inserted %d %lld %lld %lld\n",icount, timer.min(), timer.max(), timer.avg());
92 os::write(1,msgBuf,strlen(msgBuf));
93 dbMgr->closeTable(table);
94 rv = conn.close();
95 printf("connc closed %d for Thread and pid is %d %lu\n", rv, os::getpid(), os::getthrid());
96 return NULL;