1 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 ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.InputStreamReader ; 26 import java.io.OutputStream ; 27 import java.net.URL ; 28 import java.sql.Connection ; 29 import java.sql.PreparedStatement ; 30 import java.sql.SQLException ; 31 32 33 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 49 public void test() throws EtlExecutorException { 50 getConnection("sqlsupport"); 51 AbstractTestCase.testURLHandler = new TestURLHandler() { 52 public InputStream getInputStream(final URL u) { 53 return new RepeatingInputStream(SQL, 50000); 54 } 55 56 public OutputStream getOutputStream(final URL u) { 57 throw new UnsupportedOperationException (); 58 } 59 60 public int getContentLength(final URL u) { 61 return 50000 * SQL.length; 62 } 63 }; 64 65 EtlExecutor se = newEtlExecutor(); 66 se.execute(); 67 } 68 69 78 public void testCompare() throws EtlExecutorException, SQLException , IOException { 79 final int n = 20000; 80 Connection con = getConnection("sqlsupport"); 81 AbstractTestCase.testURLHandler = new TestURLHandler() { 82 public InputStream getInputStream(final URL u) { 83 return new RepeatingInputStream(SQL2, n); 84 } 85 86 public OutputStream getOutputStream(final URL u) { 87 throw new UnsupportedOperationException (); 88 } 89 90 public int getContentLength(final URL 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 RepeatingInputStream ris = new RepeatingInputStream("update test set id=?\n".getBytes(), n); 103 BufferedReader br = new BufferedReader (new InputStreamReader (ris)); 104 ti = System.currentTimeMillis(); 105 for (String s; (s = br.readLine()) != null;) { 106 PreparedStatement 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 127 public void testBulkUpdates() throws EtlExecutorException { 128 getConnection("sqlsupport"); 130 AbstractTestCase.testURLHandler = new TestURLHandler() { 131 public InputStream getInputStream(final URL u) { 132 return new RepeatingInputStream(SQL3, 50000); 133 } 134 135 public OutputStream getOutputStream(final URL u) { 136 throw new UnsupportedOperationException (); 137 } 138 139 public int getContentLength(final URL 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 args[]) throws EtlExecutorException { 150 SQLSupportPerfTest t = new SQLSupportPerfTest(); 151 t.test(); 152 } 153 154 } 155 | Popular Tags |