001: /*
002: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003: * (license2)
004: * Initial Developer: H2 Group
005: */
006: package org.h2.test;
007:
008: import java.sql.SQLException;
009: import java.util.Properties;
010:
011: import org.h2.server.TcpServer;
012: import org.h2.store.fs.FileSystemDisk;
013: import org.h2.test.db.TestAutoRecompile;
014: import org.h2.test.db.TestBackup;
015: import org.h2.test.db.TestBigDb;
016: import org.h2.test.db.TestBigResult;
017: import org.h2.test.db.TestCases;
018: import org.h2.test.db.TestCheckpoint;
019: import org.h2.test.db.TestCluster;
020: import org.h2.test.db.TestCompatibility;
021: import org.h2.test.db.TestCsv;
022: import org.h2.test.db.TestEncryptedDb;
023: import org.h2.test.db.TestExclusive;
024: import org.h2.test.db.TestFullText;
025: import org.h2.test.db.TestFunctions;
026: import org.h2.test.db.TestIndex;
027: import org.h2.test.db.TestLinkedTable;
028: import org.h2.test.db.TestListener;
029: import org.h2.test.db.TestLob;
030: import org.h2.test.db.TestLogFile;
031: import org.h2.test.db.TestMemoryUsage;
032: import org.h2.test.db.TestMultiConn;
033: import org.h2.test.db.TestMultiDimension;
034: import org.h2.test.db.TestMultiThread;
035: import org.h2.test.db.TestOpenClose;
036: import org.h2.test.db.TestOptimizations;
037: import org.h2.test.db.TestPowerOff;
038: import org.h2.test.db.TestReadOnly;
039: import org.h2.test.db.TestRights;
040: import org.h2.test.db.TestRunscript;
041: import org.h2.test.db.TestSQLInjection;
042: import org.h2.test.db.TestScript;
043: import org.h2.test.db.TestScriptSimple;
044: import org.h2.test.db.TestSequence;
045: import org.h2.test.db.TestSessionsLocks;
046: import org.h2.test.db.TestSpaceReuse;
047: import org.h2.test.db.TestSpeed;
048: import org.h2.test.db.TestTempTables;
049: import org.h2.test.db.TestTransaction;
050: import org.h2.test.db.TestTriggersConstraints;
051: import org.h2.test.db.TestTwoPhaseCommit;
052: import org.h2.test.db.TestView;
053: import org.h2.test.jdbc.TestBatchUpdates;
054: import org.h2.test.jdbc.TestCallableStatement;
055: import org.h2.test.jdbc.TestCancel;
056: import org.h2.test.jdbc.TestDatabaseEventListener;
057: import org.h2.test.jdbc.TestManyJdbcObjects;
058: import org.h2.test.jdbc.TestMetaData;
059: import org.h2.test.jdbc.TestNativeSQL;
060: import org.h2.test.jdbc.TestPreparedStatement;
061: import org.h2.test.jdbc.TestResultSet;
062: import org.h2.test.jdbc.TestStatement;
063: import org.h2.test.jdbc.TestTransactionIsolation;
064: import org.h2.test.jdbc.TestUpdatableResultSet;
065: import org.h2.test.jdbc.TestZloty;
066: import org.h2.test.jdbcx.TestDataSource;
067: import org.h2.test.jdbcx.TestXA;
068: import org.h2.test.jdbcx.TestXASimple;
069: import org.h2.test.mvcc.TestMvcc1;
070: import org.h2.test.mvcc.TestMvcc2;
071: import org.h2.test.mvcc.TestMvcc3;
072: import org.h2.test.server.TestNestedLoop;
073: import org.h2.test.server.TestPgServer;
074: import org.h2.test.server.TestWeb;
075: import org.h2.test.synth.TestBtreeIndex;
076: import org.h2.test.synth.TestCrashAPI;
077: import org.h2.test.synth.TestHaltApp;
078: import org.h2.test.synth.TestJoin;
079: import org.h2.test.synth.TestKill;
080: import org.h2.test.synth.TestKillRestart;
081: import org.h2.test.synth.TestKillRestartMulti;
082: import org.h2.test.synth.TestRandomSQL;
083: import org.h2.test.synth.TestTimer;
084: import org.h2.test.synth.sql.TestSynth;
085: import org.h2.test.synth.thread.TestMulti;
086: import org.h2.test.unit.SelfDestructor;
087: import org.h2.test.unit.TestBitField;
088: import org.h2.test.unit.TestCache;
089: import org.h2.test.unit.TestCompress;
090: import org.h2.test.unit.TestDataPage;
091: import org.h2.test.unit.TestDate;
092: import org.h2.test.unit.TestExit;
093: import org.h2.test.unit.TestFile;
094: import org.h2.test.unit.TestFileLock;
095: import org.h2.test.unit.TestFileSystem;
096: import org.h2.test.unit.TestFtp;
097: import org.h2.test.unit.TestIntArray;
098: import org.h2.test.unit.TestIntIntHashMap;
099: import org.h2.test.unit.TestMultiThreadedKernel;
100: import org.h2.test.unit.TestOverflow;
101: import org.h2.test.unit.TestPattern;
102: import org.h2.test.unit.TestReader;
103: import org.h2.test.unit.TestRecovery;
104: import org.h2.test.unit.TestSampleApps;
105: import org.h2.test.unit.TestScriptReader;
106: import org.h2.test.unit.TestSecurity;
107: import org.h2.test.unit.TestStreams;
108: import org.h2.test.unit.TestStringCache;
109: import org.h2.test.unit.TestStringUtils;
110: import org.h2.test.unit.TestTools;
111: import org.h2.test.unit.TestValue;
112: import org.h2.test.unit.TestValueHashMap;
113: import org.h2.test.unit.TestValueMemory;
114: import org.h2.tools.DeleteDbFiles;
115: import org.h2.tools.Server;
116: import org.h2.util.StringUtils;
117:
118: /**
119: * The main test application. JUnit is not used because loops are easier to
120: * write in regular java applications (most tests are ran multiple times using
121: * different settings).
122: */
123: public class TestAll {
124:
125: /*
126:
127: Random test:
128:
129: cd bin
130: del *.db
131: start cmd /k "java -cp .;%H2DRIVERS% org.h2.test.TestAll join >testJoin.txt"
132: start cmd /k "java -cp . org.h2.test.TestAll synth >testSynth.txt"
133: start cmd /k "java -cp . org.h2.test.TestAll all >testAll.txt"
134: start cmd /k "java -cp . org.h2.test.TestAll random >testRandom.txt"
135: start cmd /k "java -cp . org.h2.test.TestAll btree >testBtree.txt"
136: start cmd /k "java -cp . org.h2.test.TestAll halt >testHalt.txt"
137: java -cp . org.h2.test.TestAll crash >testCrash.txt
138:
139: java org.h2.test.TestAll timer
140:
141: */
142:
143: public boolean smallLog, big, networked, memory, ssl, textStorage,
144: diskUndo, diskResult, deleteIndex, traceSystemOut;
145: public boolean codeCoverage, mvcc, endless;
146: public int logMode = 1, traceLevelFile, throttle;
147: public String cipher;
148:
149: public boolean traceTest, stopOnError;
150: public boolean jdk14 = true;
151:
152: private Server server;
153: public boolean cache2Q;
154:
155: public static void main(String[] args) throws Exception {
156: SelfDestructor.startCountdown(6 * 60);
157: long time = System.currentTimeMillis();
158: TestAll test = new TestAll();
159: test.printSystem();
160:
161: /*
162:
163: new TestCrashAPI().init(test).testCase(2046453618);
164:
165: Allow to set all passwords as parameters
166: Remove Parser.readString()
167:
168: more tests with disk based select distinct; order by:
169: select distinct x from system_range(1, 200000);
170: DROP TABLE TEST;
171: CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255), VALUE DECIMAL(10,2));
172: INSERT INTO TEST VALUES(1,'Apples',1.20),
173: (2,'Oranges',2.05),
174: (3,'Cherries',5.10),
175: (4,'Apples',1.50),
176: (5,'Apples',1.10),
177: (6,'Oranges',1.80),
178: (7,'Bananas',2.50),
179: (8,NULL,3.10),
180: (9,NULL,-10.0);
181: SELECT DISTINCT NAME FROM TEST;
182:
183: CREATE TABLE p(d DATE);
184: INSERT INTO p VALUES('0000-01-01');
185: INSERT INTO p VALUES('0001-01-01');
186:
187: out of memory problem:
188: java -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m
189: -cp bin/h2.jar org.h2.tools.Server -log true
190: jdbc:h2:test;CACHE_SIZE=10000
191: drop all objects;
192: CREATE TABLE test (field1 number(10) not null, field2 number(8));
193: @LOOP 1000000 insert into test values(?, ?);
194: create index idx_number1 on test(field1);
195: The table 'test' contains a little over 100.000.000 records.
196:
197: Read HenPlus features
198: http://henplus.sourceforge.net/
199:
200: better document DataSource usage in an own section in the Tutorial.
201: Including Pooling if possible
202: link to or include
203: http://www.source-code.biz/snippets/java/8.htm
204:
205: add regular javadocs to the homepage
206:
207: the database should be kept open for a longer time when using the server mode
208:
209: add link to new in use, links
210:
211: Javadocs: for each tool, add a copy & paste sample in the class level
212:
213: Add google site search to web page
214:
215: merge query and result frames
216: in-place auto-complete
217:
218: scheduler: what if invoke takes more than...
219: scheduler: log at startup next 5
220: scheduler: add an a cron functionality
221:
222: test with:
223: - large varchar columns (40 KB)
224: - not closing the database
225:
226: read uncommitted and multi-threaded mode at the same time is dangerous
227:
228: add @author
229:
230: test multi-threaded kernel fulltext
231:
232: fix or disable the linear hash index
233:
234: Can sometimes not delete log file? need test case
235:
236: Add where required // TODO: change in version 1.1
237:
238: History:
239:
240: Roadmap:
241:
242:
243: */
244:
245: if (args.length > 0) {
246: if ("crash".equals(args[0])) {
247: test.endless = true;
248: new TestCrashAPI().runTest(test);
249: } else if ("synth".equals(args[0])) {
250: new TestSynth().runTest(test);
251: } else if ("kill".equals(args[0])) {
252: new TestKill().runTest(test);
253: } else if ("random".equals(args[0])) {
254: test.endless = true;
255: new TestRandomSQL().runTest(test);
256: } else if ("join".equals(args[0])) {
257: new TestJoin().runTest(test);
258: } else if ("btree".equals(args[0])) {
259: new TestBtreeIndex().runTest(test);
260: } else if ("all".equals(args[0])) {
261: test.testEverything();
262: } else if ("codeCoverage".equals(args[0])) {
263: test.codeCoverage = true;
264: test.runTests();
265: } else if ("multiThread".equals(args[0])) {
266: new TestMulti().runTest(test);
267: } else if ("halt".equals(args[0])) {
268: new TestHaltApp().runTest(test);
269: } else if ("timer".equals(args[0])) {
270: new TestTimer().runTest(test);
271: }
272: } else {
273: test.runTests();
274: }
275: System.out.println("done ("
276: + (System.currentTimeMillis() - time) + " ms)");
277: }
278:
279: /**
280: * Run all tests in all possible combinations.
281: */
282: private void testEverything() throws Exception {
283: for (int c = 0; c < 3; c++) {
284: if (c == 0) {
285: cipher = null;
286: } else if (c == 1) {
287: cipher = "XTEA";
288: } else {
289: cipher = "AES";
290: }
291: for (int a = 0; a < 256; a++) {
292: smallLog = (a & 1) != 0;
293: big = (a & 2) != 0;
294: networked = (a & 4) != 0;
295: memory = (a & 8) != 0;
296: ssl = (a & 16) != 0;
297: textStorage = (a & 32) != 0;
298: diskResult = (a & 64) != 0;
299: deleteIndex = (a & 128) != 0;
300: for (logMode = 0; logMode < 3; logMode++) {
301: traceLevelFile = logMode;
302: test();
303: }
304: }
305: }
306: }
307:
308: /**
309: * Run the tests with a number of different settings.
310: */
311: private void runTests() throws Exception {
312:
313: smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
314: traceLevelFile = throttle = 0;
315: logMode = 1;
316: cipher = null;
317: test();
318:
319: smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
320: traceLevelFile = throttle = 0;
321: logMode = 1;
322: cipher = null;
323: mvcc = false;
324: cache2Q = false;
325: test();
326:
327: diskUndo = false;
328: smallLog = false;
329: big = false;
330: networked = true;
331: memory = true;
332: ssl = false;
333: textStorage = true;
334: diskResult = deleteIndex = traceSystemOut = false;
335: traceLevelFile = throttle = 0;
336: logMode = 1;
337: cipher = null;
338: mvcc = false;
339: cache2Q = false;
340: test();
341:
342: big = false;
343: smallLog = false;
344: networked = false;
345: memory = false;
346: ssl = false;
347: textStorage = false;
348: diskResult = false;
349: deleteIndex = false;
350: traceSystemOut = false;
351: logMode = 2;
352: traceLevelFile = 0;
353: throttle = 0;
354: cipher = null;
355: mvcc = false;
356: cache2Q = false;
357: test();
358:
359: diskUndo = true;
360: smallLog = false;
361: big = networked = memory = ssl = false;
362: textStorage = true;
363: diskResult = true;
364: deleteIndex = true;
365: traceSystemOut = false;
366: logMode = 1;
367: traceLevelFile = 3;
368: throttle = 1;
369: cipher = "XTEA";
370: mvcc = false;
371: cache2Q = false;
372: test();
373:
374: diskUndo = false;
375: big = true;
376: smallLog = false;
377: networked = false;
378: memory = false;
379: ssl = false;
380: textStorage = false;
381: diskResult = false;
382: deleteIndex = false;
383: traceSystemOut = false;
384: logMode = 1;
385: traceLevelFile = 1;
386: throttle = 0;
387: cipher = null;
388: mvcc = false;
389: cache2Q = false;
390: test();
391:
392: big = true;
393: smallLog = true;
394: networked = true;
395: memory = false;
396: ssl = true;
397: textStorage = false;
398: diskResult = false;
399: deleteIndex = false;
400: traceSystemOut = false;
401: logMode = 2;
402: traceLevelFile = 2;
403: throttle = 0;
404: cipher = null;
405: mvcc = false;
406: cache2Q = true;
407: test();
408:
409: big = true;
410: smallLog = false;
411: networked = true;
412: memory = false;
413: ssl = false;
414: textStorage = false;
415: diskResult = false;
416: deleteIndex = false;
417: traceSystemOut = false;
418: logMode = 0;
419: traceLevelFile = 0;
420: throttle = 0;
421: cipher = "AES";
422: mvcc = false;
423: cache2Q = false;
424: test();
425:
426: smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
427: traceLevelFile = throttle = 0;
428: logMode = 1;
429: cipher = null;
430: mvcc = true;
431: cache2Q = false;
432: test();
433:
434: memory = true;
435: test();
436: }
437:
438: /**
439: * Run all tests with the current settings.
440: */
441: private void test() throws Exception {
442: System.out.println();
443: System.out.println("Test big:" + big + " net:" + networked
444: + " cipher:" + cipher + " memory:" + memory + " log:"
445: + logMode + " diskResult:" + diskResult + " mvcc:"
446: + mvcc + " deleteIndex:" + deleteIndex);
447: beforeTest();
448:
449: // db
450:
451: new TestScriptSimple().runTest(this );
452: new TestScript().runTest(this );
453: new TestAutoRecompile().runTest(this );
454: new TestBackup().runTest(this );
455: new TestBigDb().runTest(this );
456: new TestBigResult().runTest(this );
457: new TestCases().runTest(this );
458: new TestCheckpoint().runTest(this );
459: new TestCluster().runTest(this );
460: new TestCompatibility().runTest(this );
461: new TestCsv().runTest(this );
462: new TestEncryptedDb().runTest(this );
463: new TestExclusive().runTest(this );
464: new TestFullText().runTest(this );
465: new TestFunctions().runTest(this );
466: new TestIndex().runTest(this );
467: new TestLinkedTable().runTest(this );
468: new TestListener().runTest(this );
469: new TestLob().runTest(this );
470: new TestLogFile().runTest(this );
471: new TestMemoryUsage().runTest(this );
472: new TestMultiConn().runTest(this );
473: new TestMultiDimension().runTest(this );
474: new TestMultiThread().runTest(this );
475: new TestOpenClose().runTest(this );
476: new TestOptimizations().runTest(this );
477: new TestPowerOff().runTest(this );
478: new TestReadOnly().runTest(this );
479: new TestRights().runTest(this );
480: new TestRunscript().runTest(this );
481: new TestSQLInjection().runTest(this );
482: new TestSessionsLocks().runTest(this );
483: new TestSequence().runTest(this );
484: new TestSpaceReuse().runTest(this );
485: new TestSpeed().runTest(this );
486: new TestTempTables().runTest(this );
487: new TestTransaction().runTest(this );
488: new TestTriggersConstraints().runTest(this );
489: new TestTwoPhaseCommit().runTest(this );
490: new TestView().runTest(this );
491:
492: // jdbc
493: new TestBatchUpdates().runTest(this );
494: new TestCallableStatement().runTest(this );
495: new TestCancel().runTest(this );
496: new TestDatabaseEventListener().runTest(this );
497: new TestManyJdbcObjects().runTest(this );
498: new TestMetaData().runTest(this );
499: new TestNativeSQL().runTest(this );
500: new TestPreparedStatement().runTest(this );
501: new TestResultSet().runTest(this );
502: new TestStatement().runTest(this );
503: new TestTransactionIsolation().runTest(this );
504: new TestUpdatableResultSet().runTest(this );
505: new TestZloty().runTest(this );
506:
507: // jdbcx
508: new TestDataSource().runTest(this );
509: new TestXA().runTest(this );
510: new TestXASimple().runTest(this );
511:
512: // server
513: new TestNestedLoop().runTest(this );
514: new TestWeb().runTest(this );
515: new TestPgServer().runTest(this );
516:
517: // mvcc
518: new TestMvcc1().runTest(this );
519: new TestMvcc2().runTest(this );
520: new TestMvcc3().runTest(this );
521:
522: // synth
523: new TestCrashAPI().runTest(this );
524: new TestRandomSQL().runTest(this );
525: new TestKillRestart().runTest(this );
526: new TestKillRestartMulti().runTest(this );
527:
528: // unit
529: new TestBitField().runTest(this );
530: new TestCache().runTest(this );
531: new TestCompress().runTest(this );
532: new TestDataPage().runTest(this );
533: new TestDate().runTest(this );
534: new TestExit().runTest(this );
535: new TestFile().runTest(this );
536: new TestFileLock().runTest(this );
537: new TestFtp().runTest(this );
538: new TestFileSystem().runTest(this );
539: new TestIntArray().runTest(this );
540: new TestIntIntHashMap().runTest(this );
541: new TestMultiThreadedKernel().runTest(this );
542: new TestOverflow().runTest(this );
543: new TestPattern().runTest(this );
544: new TestReader().runTest(this );
545: new TestRecovery().runTest(this );
546: new TestSampleApps().runTest(this );
547: new TestScriptReader().runTest(this );
548: runTest("org.h2.test.unit.TestServlet");
549: new TestSecurity().runTest(this );
550: new TestStreams().runTest(this );
551: new TestStringCache().runTest(this );
552: new TestStringUtils().runTest(this );
553: new TestTools().runTest(this );
554: new TestValue().runTest(this );
555: new TestValueHashMap().runTest(this );
556: new TestValueMemory().runTest(this );
557: new TestFile().runTest(this );
558: new TestFileLock().runTest(this );
559: new TestFtp().runTest(this );
560: new TestFileSystem().runTest(this );
561: new TestIntArray().runTest(this );
562: new TestIntIntHashMap().runTest(this );
563: new TestMultiThreadedKernel().runTest(this );
564: new TestOverflow().runTest(this );
565: new TestPattern().runTest(this );
566: new TestReader().runTest(this );
567: new TestRecovery().runTest(this );
568: new TestSampleApps().runTest(this );
569: new TestScriptReader().runTest(this );
570: runTest("org.h2.test.unit.TestServlet");
571: new TestSecurity().runTest(this );
572: new TestStreams().runTest(this );
573: new TestStringCache().runTest(this );
574: new TestStringUtils().runTest(this );
575: new TestTools().runTest(this );
576: new TestValue().runTest(this );
577: new TestValueHashMap().runTest(this );
578: new TestValueMemory().runTest(this );
579:
580: afterTest();
581: }
582:
583: private void runTest(String className) {
584: try {
585: Class clazz = Class.forName(className);
586: TestBase test = (TestBase) clazz.newInstance();
587: test.runTest(this );
588: } catch (Exception e) {
589: // ignore
590: TestBase.printlnWithTime(0, className + " class not found");
591: } catch (NoClassDefFoundError e) {
592: // ignore
593: TestBase.printlnWithTime(0, className + " class not found");
594: }
595: }
596:
597: public void beforeTest() throws SQLException {
598: DeleteDbFiles.execute(TestBase.baseDir, null, true);
599: FileSystemDisk.getInstance().deleteRecursive("trace.db");
600: if (networked) {
601: TcpServer.logInternalErrors = true;
602: String[] args = ssl ? new String[] { "-tcpSSL", "true",
603: "-tcpPort", "9192" } : new String[] { "-tcpPort",
604: "9192" };
605: server = Server.createTcpServer(args);
606: try {
607: server.start();
608: } catch (SQLException e) {
609: System.out
610: .println("FAIL: can not start server (may already be running)");
611: server = null;
612: }
613: }
614: }
615:
616: public void afterTest() throws SQLException {
617: FileSystemDisk.getInstance().deleteRecursive("trace.db");
618: if (networked && server != null) {
619: server.stop();
620: }
621: DeleteDbFiles.execute(TestBase.baseDir, null, true);
622: }
623:
624: private void printSystem() {
625: Properties prop = System.getProperties();
626: System.out.println("Java: "
627: + prop.getProperty("java.runtime.version") + ", "
628: + prop.getProperty("java.vm.name") + ", "
629: + prop.getProperty("java.vendor"));
630: System.out.println("Env: "
631: + prop.getProperty("os.name")
632: + ", "
633: + prop.getProperty("os.arch")
634: + ", "
635: + prop.getProperty("os.version")
636: + ", "
637: + prop.getProperty("sun.os.patch.level")
638: + ", "
639: + prop.getProperty("file.separator")
640: + " "
641: + prop.getProperty("path.separator")
642: + " "
643: + StringUtils.javaEncode(prop
644: .getProperty("line.separator")) + " "
645: + prop.getProperty("user.country") + " "
646: + prop.getProperty("user.language") + " "
647: + prop.getProperty("user.variant") + " "
648: + prop.getProperty("file.encoding"));
649: }
650: }
|