KickJava   Java API By Example, From Geeks To Geeks.

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


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.junit.BaseJDBCTestCase;
26
27 import java.sql.*;
28
29 /**
30  * This test test the timing of starting up Derby. It tries to divide the
31  * total time up into reasonable chunks. It's written as a JUnit test but
32  * really can't be automated because the timings are so dependent upon
33  * the exact hardware, operating system and software environment the test
34  * is running in. I just use JUnit because of the convenient framework
35  * it gives me...
36  */

37 public class StartupNewDBTest extends BaseJDBCTestCase {
38     public StartupNewDBTest(String JavaDoc name) {
39         super(name);
40     }
41     
42     public void testNewDB() throws Exception JavaDoc {
43         long startTime = System.currentTimeMillis();
44         System.out.println("Testing startup with a NEW database... " +
45             "All measurements are in milliseconds.");
46         
47         // Load the driver
48
Class JavaDoc driver = Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
49         long currentTime = System.currentTimeMillis();
50         System.out.println("Loading driver: " + (currentTime - startTime));
51         
52         // Create a database
53
startTime = System.currentTimeMillis();
54         Connection conn =
55             DriverManager.getConnection("jdbc:derby:newdb;create=true");
56         currentTime = System.currentTimeMillis();
57         System.out.println("Open connection with creating new database: "
58             + (currentTime - startTime));
59                 
60         // Create a table
61
startTime = System.currentTimeMillis();
62         Statement stmt = conn.createStatement();
63         stmt.execute("CREATE TABLE test_table(id integer primary key, " +
64             "last_name varchar(80), first_name varchar(80), " +
65             "mi char(1), address varchar(100), city varchar(80))");
66         currentTime = System.currentTimeMillis();
67         System.out.println("Creating a table: "
68             + (currentTime - startTime));
69     }
70 }
71
Popular Tags