adding test scripts
[csql.git] / test / performance / throughput / connect.java
blob3ac7dcb4a07e95ceddaeddd9db872986f1ecf4c7
1 /*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
7 /**
9 * @author bijaya
12 import java.sql.*;
14 public class connect implements Runnable
16 Connection con;
17 PreparedStatement stmt;
18 ResultSet rs;
19 Thread th;
20 int thid;
21 int totalrecord;
22 int type;
23 long timeTaken;
24 connect(int i,int ty ,int record)
26 System.out.println("thread "+ i);
27 thid=i;
28 totalrecord=record;
29 type=ty;
30 timeTaken=0;
31 th=new Thread(this);
32 th.start();
34 public static Connection getDBConn() throws Exception
36 Class.forName("csql.jdbc.JdbcSqlDriver");
37 Connection con = DriverManager.getConnection("jdbc:csql:", "root", "manager");
38 return con;
40 public void run()
42 if(0==type) insertTest();
43 else if(1==type) selectTest();
44 else if(2==type) updateTest();
45 else if(3==type) deleteTest();
46 else selectTest1();
49 public void insertTest()
51 try{
52 //Class.forName("csql.jdbc.JdbcSqlDriver");
53 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
54 con = getDBConn();
55 stmt = con.prepareStatement("insert into emp values (?, 'SECOND');");
56 long count = 0, recordCount=0;
57 int ret = 0;
58 long start = 0,end = 0,curr = 0;
59 long tot = 0;
60 for(int i=0; i<totalrecord; i++){
61 stmt.setInt(1, totalrecord*thid+i);
62 start = System.nanoTime();
63 try{
64 ret = stmt.executeUpdate();
65 }catch(Exception e1)
67 try{
68 System.out.println("Retry -1 Exception in Test=1: "+e1);
69 ret = stmt.executeUpdate();
70 }catch(Exception e)
72 System.out.println("Retry -2 Exception in Test=2: "+e);
73 ret = stmt.executeUpdate();
77 if(ret!=1) break;
78 end = System.nanoTime();
79 curr = end - start;
80 tot = tot + curr;
81 count++;
83 stmt.close();
84 timeTaken = tot;
85 long val = tot/totalrecord;
86 System.out.println("Thread id "+this.thid+" Total rec: "+count+" Avgtime :"+val);
87 System.out.println("Total Record Insert: "+count);
88 Thread.sleep(1000);
89 con.close();
90 }catch(Exception e) {
91 System.out.println("Exception in Test: "+e+"Thread NO"+thid);
92 e.printStackTrace();
96 public void selectTest()
98 try{
99 //Class.forName("csql.jdbc.JdbcSqlDriver");
100 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
101 con = getDBConn();
102 stmt = con.prepareStatement("select * from emp where f1=?");
103 Thread.sleep(1000);
104 long count = 0, recordCount=0;
105 int ret = 0;
106 long start = 0,end = 0,curr = 0;
107 long tot = 0;
108 for(int i=0; i<totalrecord; i++){
109 stmt.setInt(1, totalrecord*thid +i);
110 start = System.nanoTime();
111 try{
112 rs = stmt.executeQuery();
113 }catch(Exception e1)
115 try{
116 System.out.println("Retry-1"+ e1);
117 rs = stmt.executeQuery();
118 }catch(Exception e)
120 System.out.println("Retry-2"+ e1);
121 rs = stmt.executeQuery();
124 if(rs.next())
126 recordCount++;
129 end = System.nanoTime();
130 curr = end - start;
131 tot = tot + curr;
132 count++;
134 stmt.close();
135 timeTaken = tot;
136 long val = tot/totalrecord;
137 System.out.println("Thread id "+this.thid+"Total select "+recordCount+" Avgtime :"+val);
138 System.out.println("Total Record select "+recordCount + " " + tot + " "+ totalrecord);
139 con.close();
140 }catch(Exception e) {
141 System.out.println("Exception in Test: "+e+"Thread NO"+thid);
142 e.printStackTrace();
146 public void deleteTest()
149 try{
150 //Class.forName("csql.jdbc.JdbcSqlDriver");
151 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
152 con = getDBConn();
153 stmt = con.prepareStatement("delete from emp where f1=?");
154 long count = 0, recordCount=0;
155 int ret = 0;
157 Thread.sleep(2000);
158 long start = 0,end = 0,curr = 0;
159 long tot = 0;
160 for(int i=0; i<totalrecord; i++){
161 stmt.setInt(1, totalrecord*thid+i);
162 start = System.nanoTime();
163 try{
164 ret = stmt.executeUpdate();
165 }catch(Exception e1)
167 try{
168 ret = stmt.executeUpdate();
169 }catch(Exception e)
171 // System.out.println("Exception in Test=2: "+e);
172 ret = stmt.executeUpdate();
175 if(ret!=1) break;
176 end = System.nanoTime();
177 curr = end - start;
178 tot = tot + curr;
179 count++;
181 stmt.close();
182 long val = tot/totalrecord;
183 System.out.println("Total Record Delete: "+count);
184 con.close();
185 }catch(Exception e) {
186 System.out.println("Exception in Test: "+e+"Thread NO"+thid);
187 e.printStackTrace();
190 public void updateTest()
192 try{
193 //Class.forName("csql.jdbc.JdbcSqlDriver");
194 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
195 con = getDBConn();
196 stmt = con.prepareStatement("update emp set f2='india' where f1=?");
197 long count = 0, recordCount=0;
198 int ret = 0;
200 Thread.sleep(1000);
201 long start = 0,end = 0,curr = 0;
202 long tot = 0;
203 for(int i=0; i<totalrecord; i++){
204 stmt.setInt(1, totalrecord*thid+i);
205 start = System.nanoTime();
206 try{
207 ret = stmt.executeUpdate();
208 }catch(Exception e1)
210 try{
211 ret = stmt.executeUpdate();
212 }catch(Exception e)
214 //System.out.println("Exception in Test=2: "+e);
215 ret = stmt.executeUpdate();
218 if(ret!=1) break;
219 end = System.nanoTime();
220 curr = end - start;
221 tot = tot + curr;
222 count++;
224 stmt.close();
225 long val = tot/totalrecord;
226 System.out.println("Thread id "+this.thid+" Total rec Update: "+count+" Avgtime :"+val);
227 System.out.println("Total Record Update: "+count);
228 con.close();
229 }catch(Exception e) {
230 System.out.println("Exception in Test: "+e+"Thread NO"+thid);
231 e.printStackTrace();
235 public void selectTest1()
237 try{
238 //Class.forName("csql.jdbc.JdbcSqlDriver");
239 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
240 con = getDBConn();
241 stmt = con.prepareStatement("select * from emp where f1>=? and f1<?");
242 Thread.sleep(1000);
243 long count = 0, recordCount=0;
244 int ret = 0;
245 long start = 0,end = 0,curr = 0;
246 long tot = 0;
247 for(int i=0; i<totalrecord/100; i++){
248 stmt.setInt(1, totalrecord*thid +i);
249 stmt.setInt(2, totalrecord*thid +i+100);
250 start = System.nanoTime();
251 try{
252 rs = stmt.executeQuery();
253 }catch(Exception e1)
255 try{
256 rs = stmt.executeQuery();
257 }catch(Exception e)
259 rs = stmt.executeQuery();
262 while(rs.next())
264 recordCount++;
267 end = System.nanoTime();
268 curr = end - start;
269 tot = tot + curr;
270 count++;
272 stmt.close();
273 long val = tot/totalrecord;
274 System.out.println("Thread id "+this.thid+"Total select "+recordCount+" Avgtime :"+val);
275 System.out.println("Total Record select "+recordCount);
276 con.close();
277 }catch(Exception e) {
278 System.out.println("Exception in Test: "+e+"Thread NO"+thid);
279 e.printStackTrace();