KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > SQLSupportPerfTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella;
17
18 import scriptella.execution.EtlExecutor;
19 import scriptella.execution.EtlExecutorException;
20 import scriptella.util.RepeatingInputStream;
21
22 import java.io.BufferedReader JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.InputStreamReader JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.sql.Connection JavaDoc;
29 import java.sql.PreparedStatement JavaDoc;
30 import java.sql.SQLException JavaDoc;
31
32
33 /**
34  * TODO: Add documentation
35  *
36  * @author Fyodor Kupolov
37  * @version 1.0
38  */

39 public class SQLSupportPerfTest extends DBTestCase {
40     private static final byte SQL[] = "update ${'test'} set id=?{property};rollback;".getBytes();
41     private static final byte SQL2[] = "update test set id=?{property};".getBytes();
42     private static final byte SQL3[] = "update test set id=12345;".getBytes();
43
44     /**
45      * History:
46      * 04.11.2006 - Duron 1.7Mhz - 1400 ms
47      * 11.09.2006 - Duron 1.7Mhz - 1578 ms
48      */

49     public void test() throws EtlExecutorException {
50         getConnection("sqlsupport");
51         AbstractTestCase.testURLHandler = new TestURLHandler() {
52             public InputStream getInputStream(final URL JavaDoc u) {
53                 return new RepeatingInputStream(SQL, 50000);
54             }
55
56             public OutputStream JavaDoc getOutputStream(final URL JavaDoc u) {
57                 throw new UnsupportedOperationException JavaDoc();
58             }
59
60             public int getContentLength(final URL JavaDoc u) {
61                 return 50000 * SQL.length;
62             }
63         };
64
65         EtlExecutor se = newEtlExecutor();
66         se.execute();
67     }
68
69     /**
70      * History:
71      * 04.11.2006 - Duron 1.7Mhz - 2300 ms
72      * 11.09.2006 - Duron 1.7Mhz - 2578 ms
73      *
74      * @throws EtlExecutorException
75      * @throws SQLException
76      * @throws IOException
77      */

78     public void testCompare() throws EtlExecutorException, SQLException JavaDoc, IOException JavaDoc {
79         final int n = 20000;
80         Connection JavaDoc con = getConnection("sqlsupport");
81         AbstractTestCase.testURLHandler = new TestURLHandler() {
82             public InputStream getInputStream(final URL JavaDoc u) {
83                 return new RepeatingInputStream(SQL2, n);
84             }
85
86             public OutputStream JavaDoc getOutputStream(final URL JavaDoc u) {
87                 throw new UnsupportedOperationException JavaDoc();
88             }
89
90             public int getContentLength(final URL JavaDoc u) {
91
92                 return n * SQL.length;
93             }
94         };
95
96         EtlExecutor se = newEtlExecutor();
97         long ti = System.currentTimeMillis();
98         se.execute();
99         ti = System.currentTimeMillis() - ti;
100         System.out.println("ti = " + ti);
101         //Now let's test direct HSQL connection
102
RepeatingInputStream ris = new RepeatingInputStream("update test set id=?\n".getBytes(), n);
103         BufferedReader JavaDoc br = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(ris));
104         ti = System.currentTimeMillis();
105         for (String JavaDoc s; (s = br.readLine()) != null;) {
106             PreparedStatement JavaDoc ps = con.prepareStatement(s);
107             ps.setObject(1, 1);
108             ps.execute();
109             ps.close();
110         }
111         con.commit();
112         ti = System.currentTimeMillis() - ti;
113         System.out.println("ti hsql = " + ti);
114
115
116     }
117
118
119     /**
120      * History:
121      * 19.01.2007 - Duron 1.7Mhz - 330 ms
122      *
123      * @throws EtlExecutorException
124      * @throws SQLException
125      * @throws IOException
126      */

127     public void testBulkUpdates() throws EtlExecutorException {
128         //50000 identical statements
129
getConnection("sqlsupport");
130         AbstractTestCase.testURLHandler = new TestURLHandler() {
131             public InputStream getInputStream(final URL JavaDoc u) {
132                 return new RepeatingInputStream(SQL3, 50000);
133             }
134
135             public OutputStream JavaDoc getOutputStream(final URL JavaDoc u) {
136                 throw new UnsupportedOperationException JavaDoc();
137             }
138
139             public int getContentLength(final URL JavaDoc u) {
140                 return 50000 * SQL3.length;
141             }
142         };
143
144         EtlExecutor se = newEtlExecutor();
145         se.execute();
146     }
147
148
149     public static void main(final String JavaDoc args[]) throws EtlExecutorException {
150         SQLSupportPerfTest t = new SQLSupportPerfTest();
151         t.test();
152     }
153
154 }
155
Popular Tags