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.jdbc;
007:
008: import java.sql.Connection;
009: import java.sql.DatabaseMetaData;
010: import java.sql.PreparedStatement;
011: import java.sql.ResultSet;
012: import java.sql.Statement;
013:
014: import org.h2.constant.SysProperties;
015: import org.h2.test.TestBase;
016:
017: /**
018: * Tests the server by creating many JDBC objects (result sets and so on).
019: */
020: public class TestManyJdbcObjects extends TestBase {
021:
022: public void test() throws Exception {
023: testNestedResultSets();
024: testManyConnections();
025: testOneConnectionPrepare();
026: }
027:
028: private void testNestedResultSets() throws Exception {
029: if (!config.networked) {
030: return;
031: }
032: deleteDb("manyObjects");
033: Connection conn = getConnection("manyObjects");
034: DatabaseMetaData meta = conn.getMetaData();
035: ResultSet rsTables = meta.getColumns(null, null, null, null);
036: while (rsTables.next()) {
037: meta.getExportedKeys(null, null, null);
038: meta.getImportedKeys(null, null, null);
039: }
040: conn.close();
041: }
042:
043: private void testManyConnections() throws Exception {
044: if (!config.networked || config.memory) {
045: return;
046: }
047: // SERVER_CACHED_OBJECTS = 1000: connections = 20 (1250)
048: // SERVER_CACHED_OBJECTS = 500: connections = 40
049: // SERVER_CACHED_OBJECTS = 50: connections = 120
050: deleteDb("manyObjects");
051: SysProperties.runFinalize = false;
052: int connCount = getSize(4, 40);
053: Connection[] conn = new Connection[connCount];
054: for (int i = 0; i < connCount; i++) {
055: conn[i] = getConnection("manyObjects");
056: }
057: int len = getSize(50, 500);
058: for (int j = 0; j < len; j++) {
059: if ((j % 10) == 0) {
060: trace("j=" + j);
061: }
062: for (int i = 0; i < connCount; i++) {
063: conn[i].getMetaData().getSchemas().close();
064: }
065: }
066: for (int i = 0; i < connCount; i++) {
067: conn[i].close();
068: }
069: SysProperties.runFinalize = true;
070: }
071:
072: private void testOneConnectionPrepare() throws Exception {
073: deleteDb("manyObjects");
074: SysProperties.runFinalize = false;
075: Connection conn = getConnection("manyObjects");
076: PreparedStatement prep;
077: Statement stat;
078: int size = getSize(10, 1000);
079: for (int i = 0; i < size; i++) {
080: conn.getMetaData();
081: }
082: for (int i = 0; i < size; i++) {
083: conn.createStatement();
084: }
085: stat = conn.createStatement();
086: stat
087: .execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
088: stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
089: for (int i = 0; i < size; i++) {
090: stat.executeQuery("SELECT * FROM TEST WHERE 1=0");
091: }
092: for (int i = 0; i < size; i++) {
093: stat.executeQuery("SELECT * FROM TEST");
094: }
095: for (int i = 0; i < size; i++) {
096: conn.prepareStatement("SELECT * FROM TEST");
097: }
098: prep = conn.prepareStatement("SELECT * FROM TEST WHERE 1=0");
099: for (int i = 0; i < size; i++) {
100: prep.executeQuery();
101: }
102: prep = conn.prepareStatement("SELECT * FROM TEST");
103: for (int i = 0; i < size; i++) {
104: prep.executeQuery();
105: }
106: SysProperties.runFinalize = true;
107: conn.close();
108: }
109:
110: }
|