KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > perf > StartupExistingDBTest


1 /*
2  
3    Derby - Class org.apache.derbyTesting.functionTests.test.perf.StartupTest
4  
5    Licensed to the Apache Software Foundation (ASF) under one
6    or more contributor license agreements. See the NOTICE file
7    distributed with this work for additional information
8    regarding copyright ownership. The ASF licenses this file
9    to you under the Apache License, Version 2.0 (the
10    "License"); you may not use this file except in compliance
11    with the License. You may obtain a copy of the License at
12  
13      http://www.apache.org/licenses/LICENSE-2.0
14  
15    Unless required by applicable law or agreed to in writing,
16    software distributed under the License is distributed on an
17    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18    KIND, either express or implied. See the License for the
19    specific language governing permissions and limitations
20    under the License.
21  */

22
23 package org.apache.derbyTesting.functionTests.tests.perf;
24
25 import org.apache.derbyTesting.functionTests.util.JarUtil;
26 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
27
28 import java.sql.*;
29
30 /**
31  * This test test the timing of starting up Derby. It tries to divide the
32  * total time up into reasonable chunks. It's written as a JUnit test but
33  * really can't be automated because the timings are so dependent upon
34  * the exact hardware, operating system and software environment the test
35  * is running in. I just use JUnit because of the convenient framework
36  * it gives me...
37  */

38 public class StartupExistingDBTest extends BaseJDBCTestCase {
39     public StartupExistingDBTest(String JavaDoc name) {
40         super(name);
41     }
42     
43     
44     
45     public void testExistingDB() throws Exception JavaDoc {
46         JarUtil.unjar("existingDb.jar", null);
47         
48         long startTime = System.currentTimeMillis();
49         System.out.println("Testing startup with an EXISTING database... " +
50             "All measurements are in milliseconds.");
51         
52         // Load the driver
53
Class JavaDoc driver = Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
54         long currentTime = System.currentTimeMillis();
55         System.out.println("Loading driver: " + (currentTime - startTime));
56
57         // Use an existing DB. This is copied over by the harness
58
startTime = System.currentTimeMillis();
59         Connection conn =
60             DriverManager.getConnection("jdbc:derby:../existingDb");
61         currentTime = System.currentTimeMillis();
62         System.out.println("Open connection with existing database: "
63             + (currentTime - startTime));
64
65         // Create a table
66
startTime = System.currentTimeMillis();
67         Statement stmt = conn.createStatement();
68         stmt.execute("CREATE TABLE test_table(id integer primary key, " +
69             "last_name varchar(80), first_name varchar(80), " +
70             "mi char(1), address varchar(100), city varchar(80))");
71         currentTime = System.currentTimeMillis();
72         System.out.println("Creating a table: "
73             + (currentTime - startTime));
74     }
75 }
76
Popular Tags