KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > store > MaxLogNumberRecovery


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

21
22 package org.apache.derbyTesting.functionTests.tests.store;
23 import java.sql.Connection JavaDoc;
24 import java.sql.SQLException JavaDoc;
25 import org.apache.derby.tools.ij;
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 /*
29  * This class tests recovery logic with large log file id's and the error
30  * handling logic when Max possible log file limit is reached. MaxLogNumber.java
31  * test does the setup, so it should be run before this test.
32  * In Non debug mode, this tests just acts as a plain log recovery test.
33  *
34  * @author <a HREF="mailto:suresh.thalamati@gmail.com">Suresh Thalamati</a>
35  * @version 1.0
36  * @see MaxLogNumber
37  */

38
39 public class MaxLogNumberRecovery extends MaxLogNumber {
40
41     MaxLogNumberRecovery() {
42         super();
43     }
44     
45     private void runTest(Connection JavaDoc conn) throws SQLException JavaDoc {
46         logMessage("Begin MaxLogNumberRecovery Test");
47         verifyData(conn, 100);
48         boolean hitMaxLogLimitError = false;
49         try{
50             insert(conn, 110, COMMIT, 11);
51             update(conn, 110, ROLLBACK, 5);
52             update(conn, 110, NOACTION, 5);
53             verifyData(conn, 210);
54             if (SanityManager.DEBUG)
55             {
56                 // do lot of inserts in debug mode ,
57
// so that actuall reach the max log file number
58
// limit
59
insert(conn, 11000, COMMIT, 5);
60             }
61         } catch(SQLException JavaDoc se) {
62             
63             SQLException JavaDoc ose = se;
64             while (se != null) {
65                 if ("XSLAK".equals(se.getSQLState())) {
66                     hitMaxLogLimitError = true;
67                     break;
68                 }
69                 se = se.getNextException();
70             }
71             if(!hitMaxLogLimitError)
72                 throw ose;
73         }
74
75         if (SanityManager.DEBUG)
76         {
77             // In the debug build mode , this test should hit the max log limit while
78
// doing above DML.
79
if(!hitMaxLogLimitError)
80                 logMessage("Expected: ERROR XSLAK:" +
81                            "Database has exceeded largest log file" +
82                            "number 8,589,934,591.");
83         }
84
85         logMessage("End MaxLogNumberRecovery Test");
86     }
87
88     
89     public static void main(String JavaDoc[] argv) throws Throwable JavaDoc {
90         
91         MaxLogNumberRecovery test = new MaxLogNumberRecovery();
92         ij.getPropertyArg(argv);
93         Connection JavaDoc conn = ij.startJBMS();
94         conn.setAutoCommit(false);
95
96         try {
97             test.runTest(conn);
98         }
99         catch (SQLException JavaDoc sqle) {
100             org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(
101                 System.out, sqle);
102             sqle.printStackTrace(System.out);
103         }
104     }
105 }
106
Popular Tags