Source Code Cross Referenced for DebugRecordTest.java in  » JMX » je » com » sleepycat » je » util » 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 » JMX » je » com.sleepycat.je.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2002,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: DebugRecordTest.java,v 1.41.2.3 2008/01/07 15:14:34 cwl Exp $
007:         */
008:
009:        package com.sleepycat.je.util;
010:
011:        import java.io.BufferedReader;
012:        import java.io.File;
013:        import java.io.FileReader;
014:        import java.io.IOException;
015:        import java.util.ArrayList;
016:        import java.util.List;
017:        import java.util.StringTokenizer;
018:        import java.util.logging.Level;
019:
020:        import junit.framework.TestCase;
021:
022:        import com.sleepycat.je.DatabaseException;
023:        import com.sleepycat.je.DbInternal;
024:        import com.sleepycat.je.EnvironmentConfig;
025:        import com.sleepycat.je.config.EnvironmentParams;
026:        import com.sleepycat.je.dbi.EnvironmentImpl;
027:        import com.sleepycat.je.log.LogEntryType;
028:        import com.sleepycat.je.log.FileManager;
029:        import com.sleepycat.je.log.SearchFileReader;
030:        import com.sleepycat.je.recovery.RecoveryInfo;
031:        import com.sleepycat.je.utilint.DbLsn;
032:        import com.sleepycat.je.utilint.Tracer;
033:
034:        public class DebugRecordTest extends TestCase {
035:            private File envHome;
036:            private EnvironmentImpl env;
037:
038:            public DebugRecordTest() {
039:                envHome = new File(System.getProperty(TestUtils.DEST_DIR));
040:                env = null;
041:            }
042:
043:            public void setUp() throws IOException {
044:
045:                TestUtils.removeFiles("Setup", envHome, FileManager.JE_SUFFIX);
046:                TestUtils.removeFiles(envHome, new InfoFileFilter());
047:            }
048:
049:            public void tearDown() throws IOException {
050:
051:                TestUtils.removeFiles("TearDown", envHome,
052:                        FileManager.JE_SUFFIX);
053:                TestUtils.removeFiles(envHome, new InfoFileFilter());
054:            }
055:
056:            public void testDebugLogging() throws DatabaseException,
057:                    IOException {
058:
059:                try {
060:                    // turn on the txt file and db log logging, turn off the console
061:                    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
062:                    envConfig.setConfigParam(EnvironmentParams.JE_LOGGING_FILE
063:                            .getName(), "true");
064:                    envConfig.setConfigParam(
065:                            EnvironmentParams.JE_LOGGING_CONSOLE.getName(),
066:                            "false");
067:                    envConfig.setConfigParam(EnvironmentParams.JE_LOGGING_LEVEL
068:                            .getName(), "CONFIG");
069:                    envConfig.setConfigParam(EnvironmentParams.JE_LOGGING_DBLOG
070:                            .getName(), "true");
071:                    envConfig.setConfigParam(EnvironmentParams.NODE_MAX
072:                            .getName(), "6");
073:                    envConfig.setAllowCreate(true);
074:                    /* Disable noisy UtilizationProfile database creation. */
075:                    DbInternal.setCreateUP(envConfig, false);
076:                    /* Don't run the cleaner without a UtilizationProfile. */
077:                    envConfig.setConfigParam(EnvironmentParams.ENV_RUN_CLEANER
078:                            .getName(), "false");
079:
080:                    env = new EnvironmentImpl(envHome, envConfig);
081:
082:                    List expectedRecords = new ArrayList();
083:
084:                    // Recovery itself will log two messages
085:                    RecoveryInfo info = new RecoveryInfo();
086:                    expectedRecords.add(new Tracer("Recovery w/no files."));
087:                    expectedRecords.add(new Tracer(
088:                            "Checkpoint 1: source=recovery"
089:                                    + " success=true nFullINFlushThisRun=0"
090:                                    + " nDeltaINFlushThisRun=0"));
091:                    expectedRecords.add(new Tracer("Recovery finished: "
092:                            + info.toString()));
093:
094:                    // Log a message
095:                    Tracer.trace(Level.INFO, env, "hi there");
096:                    expectedRecords.add(new Tracer("hi there"));
097:
098:                    // Log an exception
099:                    DatabaseException e = new DatabaseException(
100:                            "fake exception");
101:                    Tracer.trace(env, "DebugRecordTest", "testException",
102:                            "foo", e);
103:                    expectedRecords.add(new Tracer("foo\n"
104:                            + Tracer.getStackTrace(e)));
105:
106:                    // Log a split
107:                    // Flush the log to disk
108:                    env.getLogManager().flush();
109:                    env.getFileManager().clear();
110:                    env.closeLogger();
111:
112:                    // Verify
113:                    checkDatabaseLog(expectedRecords);
114:                    checkTextFile(expectedRecords);
115:
116:                } finally {
117:                    if (env != null) {
118:                        env.close();
119:                    }
120:                }
121:            }
122:
123:            /**
124:             * Check what's in the database log
125:             */
126:            private void checkDatabaseLog(List expectedList)
127:                    throws DatabaseException, IOException {
128:
129:                SearchFileReader searcher = new SearchFileReader(env, 1000,
130:                        true, DbLsn.NULL_LSN, DbLsn.NULL_LSN,
131:                        LogEntryType.LOG_TRACE);
132:
133:                int numSeen = 0;
134:                while (searcher.readNextEntry()) {
135:                    Tracer dRec = (Tracer) searcher.getLastObject();
136:                    assertEquals("Should see this as " + numSeen + " record: ",
137:                            ((Tracer) expectedList.get(numSeen)).getMessage(),
138:                            dRec.getMessage());
139:                    numSeen++;
140:                }
141:
142:                assertEquals("Should see this many debug records", expectedList
143:                        .size(), numSeen);
144:            }
145:
146:            /**
147:             * Check what's in the text file
148:             */
149:            private void checkTextFile(List expectedList) throws IOException {
150:
151:                FileReader fr = null;
152:                BufferedReader br = null;
153:                try {
154:                    String textFileName = envHome + File.separator
155:                            + "je.info.0";
156:                    fr = new FileReader(textFileName);
157:                    br = new BufferedReader(fr);
158:
159:                    String line = br.readLine();
160:                    int numSeen = 0;
161:
162:                    // Read the file, checking only lines that start with valid Levels
163:                    while (line != null) {
164:                        int firstColon = line.indexOf(':');
165:                        firstColon = firstColon > 0 ? firstColon : 0;
166:                        String possibleLevel = line.substring(0, firstColon);
167:                        try {
168:                            Level.parse(possibleLevel);
169:                            String expected = ((Tracer) expectedList
170:                                    .get(numSeen)).getMessage();
171:                            StringBuffer seen = new StringBuffer();
172:                            /*
173:                             * Assemble the log message by reading the right number
174:                             * of lines
175:                             */
176:                            StringTokenizer st = new StringTokenizer(expected,
177:                                    Character.toString('\n'), false);
178:
179:                            seen.append(line.substring(firstColon + 2));
180:                            for (int i = 1; i < st.countTokens(); i++) {
181:                                seen.append('\n');
182:                                String l = br.readLine();
183:                                seen.append(l);
184:                                if (i == (st.countTokens() - 1)) {
185:                                    seen.append('\n');
186:                                }
187:                            }
188:                            // XXX, diff of multiline stuff isn't right yet
189:                            if (st.countTokens() == 1) {
190:                                assertEquals("Line " + numSeen
191:                                        + " should be the same", expected, seen
192:                                        .toString());
193:                            }
194:                            numSeen++;
195:                        } catch (Exception e) {
196:                            // skip this line, not a message
197:                        }
198:                        line = br.readLine();
199:                    }
200:                    assertEquals("Should see this many debug records",
201:                            expectedList.size(), numSeen);
202:                } finally {
203:                    if (br != null) {
204:                        br.close();
205:                    }
206:                    if (fr != null) {
207:                        fr.close();
208:                    }
209:                }
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.