KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > test > TestAll


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.test;
6
7 import java.sql.SQLException JavaDoc;
8 import java.util.Properties JavaDoc;
9
10 import org.h2.server.TcpServer;
11 import org.h2.test.jdbc.*;
12 import org.h2.test.db.*;
13 import org.h2.test.server.TestNestedLoop;
14 import org.h2.test.synth.TestBtreeIndex;
15 import org.h2.test.synth.TestCrashAPI;
16 import org.h2.test.synth.TestHaltApp;
17 import org.h2.test.synth.TestJoin;
18 import org.h2.test.synth.TestKill;
19 import org.h2.test.synth.TestMulti;
20 import org.h2.test.synth.TestRandomSQL;
21 import org.h2.test.synth.TestSynth;
22 import org.h2.test.unit.TestBitField;
23 import org.h2.test.unit.TestCache;
24 import org.h2.test.unit.TestCompress;
25 import org.h2.test.unit.TestDataPage;
26 import org.h2.test.unit.TestExit;
27 import org.h2.test.unit.TestFileLock;
28 import org.h2.test.unit.TestIntArray;
29 import org.h2.test.unit.TestIntIntHashMap;
30 import org.h2.test.unit.TestOverflow;
31 import org.h2.test.unit.TestPattern;
32 import org.h2.test.unit.TestReader;
33 import org.h2.test.unit.TestSampleApps;
34 import org.h2.test.unit.TestScriptReader;
35 import org.h2.test.unit.TestSecurity;
36 import org.h2.test.unit.TestStreams;
37 import org.h2.test.unit.TestStringCache;
38 import org.h2.test.unit.TestStringUtils;
39 import org.h2.test.unit.TestTools;
40 import org.h2.test.unit.TestValueHashMap;
41 import org.h2.tools.DeleteDbFiles;
42 import org.h2.tools.Server;
43 import org.h2.util.StringUtils;
44
45 /**
46  * @author Thomas
47  */

48 public class TestAll {
49
50 // Snippets to run test code:
51
// java -cp .;%H2DRIVERS% org.h2.test.TestAll
52
// java -Xrunhprof:cpu=samples,depth=8 org.h2.test.TestAll
53
// java -Xrunhprof:heap=sites,depth=8 org.h2.test.TestAll
54
// C:\Programme\Java\jdk1.6.beta\bin\java
55

56 /*
57
58 Random test:
59
60 cd bin
61 del *.db
62 start cmd /k "java -cp .;%H2DRIVERS% org.h2.test.TestAll join >testJoin.txt"
63 start cmd /k "java org.h2.test.TestAll crash >testCrash.txt"
64 start cmd /k "java org.h2.test.TestAll synth >testSynth.txt"
65 start cmd /k "java org.h2.test.TestAll all >testAll.txt"
66 start cmd /k "java org.h2.test.TestAll random >testRandom.txt"
67 start cmd /k "java org.h2.test.TestAll btree >testBtree.txt"
68
69 Test for hot spots:
70 java -agentlib:yjpagent=sampling,noj2ee,dir=C:\temp\Snapshots org.h2.test.bench.TestPerformance -init -db 1
71 java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2:test;TRACE_LEVEL_FILE=3;LOG=2;MAX_LOG_SIZE=1000;DATABASE_EVENT_LISTENER='org.h2.samples.ShowProgress' -user sa -script test.sql
72  */

73
74     public boolean smallLog, big, networked, memory, ssl, textStorage, diskUndo, diskResult, deleteIndex, traceSystemOut;
75     public boolean codeCoverage;
76     public int logMode = 1, traceLevelFile, throttle;
77     public String JavaDoc cipher;
78
79     public boolean traceTest, stopOnError;
80     public boolean jdk14 = true;
81
82     private Server server;
83
84     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
85         long time = System.currentTimeMillis();
86         TestAll test = new TestAll();
87         test.printSystem();
88         
89 // Hi i found one small nasty bug with h2 database. When i use prepared statement on tables that have primary key UUID DEFAULT random_UUID(), and when i call getGeneratedKeys() method I only get (long) 0 as result, instead of random_uuid.
90
// And if I use IDENTITY type for primary ket i get corect value from methord PreparedStatement.getGeneratedKeys(). Problem is with UUID and random_uuid() combination.
91

92         // NULL || 'X' should probably return null by default
93
// change default to read committed transaction isolation
94
// Hot backup (incremental backup, online backup): backup data, log, index? files
95
// Cluster: hot deploy (adding a node on runtime)
96
// system property for base directory (h2.baseDir)
97

98         // SELECT ... FROM TA, TB, TC WHERE TC.COL3 = TA.COL1 AND TC.COL3=TB.COL2 AND TC.COL4 = 1
99
// The query implies TA.COL1 = TB.COL2 but does not explicitly set this condition.
100
// "trace.db" is created in the current directory
101
// dataSource.setLogWriter() seems to have no effect?
102

103 // DROP TABLE TEST;
104
// CREATE TABLE TEST(C CHAR(10));
105
// INSERT INTO TEST VALUES('1');
106
// SELECT COUNT(*) FROM TEST WHERE C='1 ';
107
// -- PostgreSQL, HSQLDB, MySQL, Derby, MS SQL Server, Oracle: 1
108
// -- H2: 0
109
// SELECT LENGTH(C), LENGTH(C || 'x') FROM TEST;
110
// -- MySQL: 1, 1 (??)
111
// -- MS SQL Server: 1, 11 (SELECT LEN(C), LEN(C + 'x') FROM TEST)
112
// -- Oracle, Derby: 10, 11
113
// -- PostgreSQL, H2, HSQLDB: 1, 2
114

115         // auto-upgrade application:
116
// check if new version is available
117
// (option: digital signature)
118
// if yes download new version
119
// (option: http, https, ftp, network)
120
// backup database to SQL script
121
// (option: list of databases, use recovery mechanism)
122
// install new version
123

124         // ftp client
125
// task to download new version from another HTTP / HTTPS / FTP server
126
// multi-task
127

128         // test with PostgreSQL Version 8.2
129

130         // http://dev.helma.org/Wiki/RhinoLoader
131

132         // test with garbage at the end of the log file (must be consistently detected as such)
133
// test LIKE: compare against other databases
134
// TestRandomSQL is too random; most statements fails
135
// extend the random join test that compared the result against PostgreSQL
136
// long running test with the same database
137
// repeatable test with a very big database (making backups of the database files)
138

139         // the conversion is done automatically when the new engine connects.
140

141         if(args.length>0) {
142             if("crash".equals(args[0])) {
143                 new TestCrashAPI().runTest(test);
144             } else if("synth".equals(args[0])) {
145                 new TestSynth().runTest(test);
146             } else if("kill".equals(args[0])) {
147                 new TestKill().runTest(test);
148             } else if("random".equals(args[0])) {
149                 new TestRandomSQL().runTest(test);
150             } else if("join".equals(args[0])) {
151                 new TestJoin().runTest(test);
152             } else if("btree".equals(args[0])) {
153                 new TestBtreeIndex().runTest(test);
154             } else if("all".equals(args[0])) {
155                 test.testEverything();
156             } else if("codeCoverage".equals(args[0])) {
157                 test.testCodeCoverage();
158             } else if("multiThread".equals(args[0])) {
159                 new TestMulti().runTest(test);
160             } else if("halt".equals(args[0])) {
161                 new TestHaltApp().runTest(test);
162             }
163         } else {
164             test.runTests();
165         }
166         System.out.println("done ("+(System.currentTimeMillis()-time)+" ms)");
167     }
168
169     void runTests() throws Exception JavaDoc {
170         
171 // TODO test set lock_mode=0, 1; max_trace_file_size; modes; collation; assert
172
// TODO test shutdown immediately
173

174 // smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
175
// logMode = 1; traceLevelFile = throttle = 0;
176
// deleteIndex = textStorage = true;
177
// cipher = null;
178

179 // codeCoverage = true;
180

181 // memory = true;
182
// new TestSpeed().runTest(this);
183
// new TestSpeed().runTest(this);
184
// new TestSpeed().runTest(this);
185
// new TestSpeed().runTest(this);
186

187
188
189 // smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
190
// traceLevelFile = throttle = 0;
191
// big = true;
192
// memory = false;
193
//
194

195         testQuick();
196         testCombination();
197
198     }
199
200     void testCodeCoverage() throws Exception JavaDoc {
201         this.codeCoverage = true;
202         runTests();
203     }
204
205     void testQuick() throws Exception JavaDoc {
206         smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
207         traceLevelFile = throttle = 0;
208         logMode = 1;
209         cipher = null;
210         testAll();
211     }
212
213     void testEverything() throws Exception JavaDoc {
214         for(int c = 0; c < 3; c++) {
215             if(c == 0) {
216                 cipher = null;
217             } else if(c==1) {
218                 cipher = "XTEA";
219             } else {
220                 cipher = "AES";
221             }
222             for(int a = 0; a < 256; a++) {
223                 smallLog = (a & 1) != 0;
224                 big = (a & 2) != 0;
225                 networked = (a & 4) != 0;
226                 memory = (a & 8) != 0;
227                 ssl = (a & 16) != 0;
228                 textStorage = (a & 32) != 0;
229                 diskResult = (a & 64) != 0;
230                 deleteIndex = (a & 128) != 0;
231                 for(logMode = 0; logMode < 3; logMode++) {
232                     traceLevelFile = logMode;
233                     TestBase.printTime("cipher:" + cipher +" a:" +a+" logMode:"+logMode);
234                     testAll();
235                 }
236             }
237         }
238     }
239
240     void testCombination() throws Exception JavaDoc {
241         smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
242         traceLevelFile = throttle = 0;
243         logMode = 1;
244         cipher = null;
245         testAll();
246
247         diskUndo = false;
248         smallLog = false;
249         big = false;
250         networked = true;
251         memory = true;
252         ssl = false;
253         textStorage = true;
254         diskResult = deleteIndex = traceSystemOut = false;
255         traceLevelFile = throttle = 0;
256         logMode = 1;
257         cipher = null;
258         testAll();
259         
260         big = false;
261         smallLog = false;
262         networked = false;
263         memory = false;
264         ssl = false;
265         textStorage = false;
266         diskResult = false;
267         deleteIndex = false;
268         traceSystemOut = false;
269         logMode = 2;
270         traceLevelFile = 0;
271         throttle = 0;
272         cipher = null;
273         testAll();
274
275         diskUndo = true;
276         smallLog = false;
277         big = networked = memory = ssl = false;
278         textStorage = true;
279         diskResult = true;
280         deleteIndex = true;
281         traceSystemOut = false;
282         logMode = 1;
283         traceLevelFile = 3;
284         throttle = 1;
285         cipher = "XTEA";
286         testAll();
287
288         diskUndo = false;
289         big = true;
290         smallLog = false;
291         networked = false;
292         memory = false;
293         ssl = false;
294         textStorage = false;
295         diskResult = false;
296         deleteIndex = false;
297         traceSystemOut = false;
298         logMode = 1;
299         traceLevelFile = 1;
300         throttle = 0;
301         cipher = null;
302         testAll();
303
304         big = true;
305         smallLog = true;
306         networked = true;
307         memory = false;
308         ssl = true;
309         textStorage = false;
310         diskResult = false;
311         deleteIndex = false;
312         traceSystemOut = false;
313         logMode = 2;
314         traceLevelFile = 2;
315         throttle = 0;
316         cipher = null;
317         testAll();
318         
319         big = true;
320         smallLog = false;
321         networked = true;
322         memory = false;
323         ssl = false;
324         textStorage = false;
325         diskResult = false;
326         deleteIndex = false;
327         traceSystemOut = false;
328         logMode = 0;
329         traceLevelFile = 0;
330         throttle = 0;
331         cipher = "AES";
332         testAll();
333         
334     }
335
336     void testAll() throws Exception JavaDoc {
337         DeleteDbFiles.execute(TestBase.BASE_DIR, null, true);
338         testDatabase();
339         testUnit();
340         DeleteDbFiles.execute(TestBase.BASE_DIR, null, true);
341     }
342
343     void testUnit() {
344         new TestBitField().runTest(this);
345         new TestCompress().runTest(this);
346         new TestDataPage().runTest(this);
347         new TestExit().runTest(this);
348         new TestFileLock().runTest(this);
349         new TestIntArray().runTest(this);
350         new TestIntIntHashMap().runTest(this);
351         new TestOverflow().runTest(this);
352         new TestPattern().runTest(this);
353         new TestReader().runTest(this);
354         new TestSampleApps().runTest(this);
355         new TestScriptReader().runTest(this);
356         new TestSecurity().runTest(this);
357         new TestStreams().runTest(this);
358         new TestStringCache().runTest(this);
359         new TestStringUtils().runTest(this);
360         new TestTools().runTest(this);
361         new TestValueHashMap().runTest(this);
362     }
363
364     void testDatabase() throws Exception JavaDoc {
365         System.out.println("test big:"+big+" net:"+networked+" cipher:"+cipher+" memory:"+memory+" log:"+logMode+" diskResult:"+diskResult);
366         beforeTest();
367
368         // db
369
new TestScriptSimple().runTest(this);
370         new TestScript().runTest(this);
371         new TestAutoRecompile().runTest(this);
372         new TestBatchUpdates().runTest(this);
373         new TestBigDb().runTest(this);
374         new TestBigResult().runTest(this);
375         new TestCache().runTest(this);
376         new TestCases().runTest(this);
377         new TestCheckpoint().runTest(this);
378         new TestCluster().runTest(this);
379         new TestCompatibility().runTest(this);
380         new TestCsv().runTest(this);
381         new TestFunctions().runTest(this);
382         new TestIndex().runTest(this);
383         new TestLinkedTable().runTest(this);
384         new TestListener().runTest(this);
385         new TestLob().runTest(this);
386         new TestLogFile().runTest(this);
387         new TestMemoryUsage().runTest(this);
388         new TestMultiConn().runTest(this);
389         new TestMultiDimension().runTest(this);
390         new TestMultiThread().runTest(this);
391         new TestOpenClose().runTest(this);
392         new TestOptimizations().runTest(this);
393         new TestPowerOff().runTest(this);
394         new TestReadOnly().runTest(this);
395         new TestRights().runTest(this);
396         new TestRunscript().runTest(this);
397         new TestSQLInjection().runTest(this);
398         new TestSequence().runTest(this);
399         new TestSpaceReuse().runTest(this);
400         new TestSpeed().runTest(this);
401         new TestTempTables().runTest(this);
402         new TestTransaction().runTest(this);
403         new TestTriggersConstraints().runTest(this);
404         new TestTwoPhaseCommit().runTest(this);
405
406         // server
407
new TestNestedLoop().runTest(this);
408
409         // jdbc
410
new TestCancel().runTest(this);
411         new TestDataSource().runTest(this);
412         new TestManyJdbcObjects().runTest(this);
413         new TestMetaData().runTest(this);
414         new TestNativeSQL().runTest(this);
415         new TestPreparedStatement().runTest(this);
416         new TestResultSet().runTest(this);
417         new TestStatement().runTest(this);
418         new TestTransactionIsolation().runTest(this);
419         new TestUpdatableResultSet().runTest(this);
420         new TestZloty().runTest(this);
421
422         afterTest();
423     }
424
425     public void beforeTest() throws SQLException JavaDoc {
426         if(networked) {
427             TcpServer.LOG_INTERNAL_ERRORS = true;
428             String JavaDoc[] args = ssl ? new String JavaDoc[]{"-tcpSSL", "true"} : new String JavaDoc[0];
429             server = Server.createTcpServer(args);
430             try {
431                 server.start();
432             } catch(SQLException JavaDoc e) {
433                 System.out.println("FAIL: can not start server (may already be running)");
434                 server = null;
435             }
436         }
437     }
438
439     public void afterTest() {
440         if(networked && server != null) {
441             server.stop();
442         }
443     }
444
445     private void printSystem() {
446         Properties JavaDoc prop = System.getProperties();
447         System.out.println("Java: " +
448                 prop.getProperty("java.runtime.version") + ", " +
449                 prop.getProperty("java.vm.name")+", " +
450                 prop.getProperty("java.vendor"));
451         System.out.println("Env: " +
452                 prop.getProperty("os.name") + ", " +
453                 prop.getProperty("os.arch")+", "+
454                 prop.getProperty("os.version")+", "+
455                 prop.getProperty("sun.os.patch.level")+", "+
456                 prop.getProperty("file.separator")+" "+
457                 prop.getProperty("path.separator")+" "+
458                 StringUtils.javaEncode( prop.getProperty("line.separator"))+" "+
459                 prop.getProperty("user.country") + " " +
460                 prop.getProperty("user.language") + " " +
461                 prop.getProperty("user.variant")+" "+
462                 prop.getProperty("file.encoding"));
463     }
464 }
465
Popular Tags