Source Code Cross Referenced for ShutDownDBWhenNSShutsDownTest.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » derbynet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derbyTesting.functionTests.tests.derbynet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * Derby - Class ShutDownDBWhenNSShutsDownTest
004:         *
005:         * Licensed to the Apache Software Foundation (ASF) under one or more
006:         * contributor license agreements.  See the NOTICE file distributed with
007:         * this work for additional information regarding copyright ownership.
008:         * The ASF licenses this file to You under the Apache License, Version 2.0
009:         * (the "License"); you may not use this file except in compliance with
010:         * the License.  You may obtain a copy of the License at
011:         *
012:         *    http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
017:         * either express or implied. See the License for the specific
018:         * language governing permissions and limitations under the License.
019:         */
020:
021:        package org.apache.derbyTesting.functionTests.tests.derbynet;
022:
023:        import java.util.Properties;
024:        import org.apache.derbyTesting.functionTests.util.TestUtil;
025:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
026:        import org.apache.derbyTesting.junit.BaseTestCase;
027:        import org.apache.derby.drda.NetworkServerControl;
028:
029:        import junit.framework.*;
030:        import java.sql.*;
031:        import java.io.PrintWriter;
032:        import java.io.File;
033:        import java.security.AccessController;
034:
035:        /**
036:         * Derby-1274 - Network Server should shutdown the databases it has booted when
037:         * started from the command line.
038:         *
039:         * Tests that the network server will shutdown the databases it has booted when
040:         * started from the command line and that it will not shut down the databases
041:         * when started from the API.
042:         */
043:        public class ShutDownDBWhenNSShutsDownTest extends BaseJDBCTestCase {
044:
045:            NetworkServerControl server = null;
046:
047:            /**
048:             * Creates a new instance of ShutDownDBWhenNSShutsDownTest
049:             */
050:            public ShutDownDBWhenNSShutsDownTest(String name) {
051:                super (name);
052:            }
053:
054:            /**
055:             * Test that the NetworkServer shuts down the databases it has booted when
056:             * started from the command line, and that it does not shut down the
057:             * databases it has booted when started from the API.
058:             */
059:            public void testDatabasesShutDownWhenNSShutdown() throws Exception {
060:                server = new NetworkServerControl();
061:                // The server was started from the command line when the test was
062:                // started. Check that the database will be shut down when the server
063:                // is shut down.
064:                shutdownServerCheckDBShutDown(true);
065:
066:                // Start the server form the API and test that the databases will not
067:                // be shutdown when the server is shutdown
068:                server.start(null);
069:
070:                // wait until the server accepts connections
071:                int i = 0;
072:                while (!pingServer() && i < 10) {
073:                    Thread.sleep(1000);
074:                    i++;
075:                }
076:
077:                // Check that the databases will not be shutdown when the server is
078:                // shut down.
079:                shutdownServerCheckDBShutDown(false);
080:            }
081:
082:            /**
083:             * Checks whether the server shuts down causes the databases it has booted
084:             * to be shut down.
085:             *
086:             * Creates a database and shuts down the server. If the server was started
087:             * from the command line the database should be shut down. If the server
088:             * was started from the api the database should not be shut down.
089:             *
090:             * If the database has been shut down the db.lck file should not exist.
091:             *
092:             * @param dbShutDown Indicates whether the database should have been shut
093:             * down.
094:             */
095:            private void shutdownServerCheckDBShutDown(boolean dbShutDown)
096:                    throws Exception {
097:                // connect to database
098:                createDatabase();
099:
100:                // shut down the server
101:                shutdownServer();
102:
103:                // check if db.lck exists
104:                String fileName = getSystemProperty("derby.system.home")
105:                        + java.io.File.separator + "wombat"
106:                        + java.io.File.separator + "db.lck";
107:
108:                boolean fileNotFound = false;
109:                int i = 0;
110:                do {
111:                    Thread.sleep(500);
112:                    fileNotFound = !fileExists(fileName);
113:                    i++;
114:                } while (fileNotFound != dbShutDown && i < 120);
115:
116:                assertEquals("Database is shut down", dbShutDown, fileNotFound);
117:            }
118:
119:            private boolean fileExists(final String fileName) throws Exception {
120:                Boolean b = (Boolean) AccessController
121:                        .doPrivileged(new java.security.PrivilegedAction() {
122:                            public Object run() {
123:                                File file = new File(fileName);
124:                                return new Boolean(file.exists());
125:                            }
126:                        });
127:
128:                return b.booleanValue();
129:            }
130:
131:            private boolean pingServer() {
132:                try {
133:                    server.ping();
134:                } catch (Exception e) {
135:                    return false;
136:                }
137:                return true;
138:            }
139:
140:            private void createDatabase() throws SQLException {
141:                Connection conn = getConnection();
142:                conn.setAutoCommit(false);
143:                Statement st = conn.createStatement();
144:                st.execute("CREATE TABLE T1 (a int)");
145:                st.execute("INSERT INTO T1 VALUES (1), (2), (3), (4), (5)");
146:                st.execute("DROP TABLE T1");
147:                conn.commit();
148:                conn.close();
149:            }
150:
151:            private void shutdownServer() throws Exception {
152:                server.shutdown();
153:            }
154:
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.