Source Code Cross Referenced for FileReaderBufferingTest.java in  » JMX » je » com » sleepycat » je » log » 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.log 
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: FileReaderBufferingTest.java,v 1.12.2.3 2008/01/07 15:14:29 cwl Exp $
007:         */
008:
009:        package com.sleepycat.je.log;
010:
011:        import java.io.File;
012:        import java.io.IOException;
013:        import java.util.ArrayList;
014:        import java.util.Arrays;
015:        import java.util.Iterator;
016:
017:        import junit.framework.TestCase;
018:
019:        import com.sleepycat.je.DatabaseException;
020:        import com.sleepycat.je.DbInternal;
021:        import com.sleepycat.je.Environment;
022:        import com.sleepycat.je.EnvironmentConfig;
023:        import com.sleepycat.je.config.EnvironmentParams;
024:        import com.sleepycat.je.dbi.EnvironmentImpl;
025:        import com.sleepycat.je.util.TestUtils;
026:        import com.sleepycat.je.utilint.DbLsn;
027:        import com.sleepycat.je.utilint.Tracer;
028:
029:        /**
030:         * Check our ability to adjust the file reader buffer size.
031:         */
032:        public class FileReaderBufferingTest extends TestCase {
033:
034:            private File envHome;
035:            private Environment env;
036:            private EnvironmentImpl envImpl;
037:            private ArrayList expectedLsns;
038:            private ArrayList expectedVals;
039:
040:            public FileReaderBufferingTest() {
041:                super ();
042:                envHome = new File(System.getProperty(TestUtils.DEST_DIR));
043:            }
044:
045:            public void setUp() throws IOException, DatabaseException {
046:
047:                TestUtils.removeLogFiles("Setup", envHome, false);
048:            }
049:
050:            public void tearDown() throws IOException, DatabaseException {
051:
052:                TestUtils.removeFiles("TearDown", envHome,
053:                        FileManager.JE_SUFFIX);
054:            }
055:
056:            /**
057:             * Should overflow once and then grow.
058:             */
059:            public void testBasic() throws Exception {
060:                readLog(1050, // starting size of object in entry
061:                        0, // object growth increment
062:                        100, // starting read buffer size
063:                        "3000", // max read buffer size
064:                        0); // expected number of overflows.
065:            }
066:
067:            /**
068:             * Should overflow once and then grow.
069:             */
070:            public void testCantGrow() throws Exception {
071:                readLog(2000, // starting size of object in entry
072:                        0, // object growth increment
073:                        100, // starting read buffer size
074:                        "1000", // max read buffer size
075:                        11); // expected number of overflows. This comes out to
076:                // an odd number because one of the entries hits it
077:                // in just the right place so as to overflow twice.
078:            }
079:
080:            /**
081:             * Should overflow, grow, and then reach the max.
082:             */
083:            public void testReachMax() throws Exception {
084:                readLog(1000, // size of object in entry
085:                        1000, // object growth increment
086:                        100, // starting read buffer size
087:                        "3500", // max read buffer size
088:                        8); // expected number of overflows.
089:            }
090:
091:            /**
092:             *
093:             */
094:            private void readLog(int entrySize, int entrySizeIncrement,
095:                    int readBufferSize, String bufferMaxSize,
096:                    int expectedOverflows) throws Exception {
097:
098:                try {
099:
100:                    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
101:                    envConfig.setAllowCreate(true);
102:                    envConfig.setConfigParam(
103:                            EnvironmentParams.LOG_ITERATOR_MAX_SIZE.getName(),
104:                            bufferMaxSize);
105:                    env = new Environment(envHome, envConfig);
106:
107:                    envImpl = DbInternal.envGetEnvironmentImpl(env);
108:
109:                    /* Make a log file */
110:                    createLogFile(10, entrySize, entrySizeIncrement);
111:                    SearchFileReader reader = new SearchFileReader(envImpl,
112:                            readBufferSize, true, DbLsn
113:                                    .longToLsn((Long) expectedLsns.get(0)),
114:                            DbLsn.NULL_LSN, LogEntryType.LOG_TRACE);
115:
116:                    Iterator lsnIter = expectedLsns.iterator();
117:                    Iterator valIter = expectedVals.iterator();
118:                    while (reader.readNextEntry()) {
119:                        Tracer rec = (Tracer) reader.getLastObject();
120:                        assertTrue(lsnIter.hasNext());
121:                        assertEquals(reader.getLastLsn(), DbLsn
122:                                .longToLsn((Long) lsnIter.next()));
123:                        assertEquals((String) valIter.next(), rec.getMessage());
124:                    }
125:                    assertEquals(10, reader.getNumRead());
126:                    assertEquals(expectedOverflows, reader
127:                            .getNRepeatIteratorReads());
128:
129:                } catch (Exception e) {
130:                    e.printStackTrace();
131:                    throw e;
132:                } finally {
133:                    env.close();
134:                }
135:            }
136:
137:            /**
138:             * Write a logfile of entries, put the entries that we expect to
139:             * read into a list for later verification.
140:             * @return end of file LSN.
141:             */
142:            private void createLogFile(int numItems, int size, int sizeIncrement)
143:                    throws IOException, DatabaseException {
144:
145:                LogManager logManager = envImpl.getLogManager();
146:                expectedLsns = new ArrayList();
147:                expectedVals = new ArrayList();
148:
149:                for (int i = 0; i < numItems; i++) {
150:                    /* Add a debug record just to be filler. */
151:                    int recordSize = size + (i * sizeIncrement);
152:                    byte[] filler = new byte[recordSize];
153:                    Arrays.fill(filler, (byte) i);
154:                    String val = new String(filler);
155:
156:                    Tracer rec = new Tracer(val);
157:                    long lsn = rec.log(logManager);
158:                    expectedLsns.add(new Long(lsn));
159:                    expectedVals.add(val);
160:                }
161:
162:                logManager.flush();
163:                envImpl.getFileManager().clear();
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.