Source Code Cross Referenced for ConvertAndAddTest.java in  » JMX » je » com » sleepycat » persist » test » 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.persist.test 
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: ConvertAndAddTest.java,v 1.1.2.4 2008/01/07 15:14:35 cwl Exp $
007:         */
008:
009:        package com.sleepycat.persist.test;
010:
011:        import java.io.File;
012:        import java.io.IOException;
013:
014:        import junit.framework.TestCase;
015:
016:        import com.sleepycat.je.DatabaseException;
017:        import com.sleepycat.je.Environment;
018:        import com.sleepycat.je.EnvironmentConfig;
019:        import com.sleepycat.je.util.TestUtils;
020:        import com.sleepycat.persist.EntityStore;
021:        import com.sleepycat.persist.PrimaryIndex;
022:        import com.sleepycat.persist.StoreConfig;
023:        import com.sleepycat.persist.evolve.Conversion;
024:        import com.sleepycat.persist.evolve.Converter;
025:        import com.sleepycat.persist.evolve.Mutations;
026:        import com.sleepycat.persist.model.Entity;
027:        import com.sleepycat.persist.model.EntityModel;
028:        import com.sleepycat.persist.model.PrimaryKey;
029:
030:        /**
031:         * Test a bug fix where an IndexOutOfBoundsException occurs when adding a field
032:         * and converting another field, where the latter field is alphabetically
033:         * higher than the former.  This is also tested by
034:         * EvolveClasses.FieldAddAndConvert, but that class does not test evolving an
035:         * entity that was created by catalog version 0.  [#15797]
036:         *
037:         * A modified version of this program was run manually with JE 3.2.30 to
038:         * produce a log, which is the result of the testSetup() test.  The sole log
039:         * file was renamed from 00000000.jdb to ConvertAndAddTest.jdb and added to CVS
040:         * in this directory.  When that log file is opened here, the bug is
041:         * reproduced.  The modifications to this program for 3.2.30 are:
042:         *
043:         *  + X in testSetup
044:         *  + X out testConvertAndAddField
045:         *  + don't remove log files in tearDown
046:         *  + @Entity version is 0
047:         *  + removed field MyEntity.a
048:         *
049:         * This test should be excluded from the BDB build because it uses a stored JE
050:         * log file and it tests a fix for a bug that was never present in BDB.
051:         *
052:         * @author Mark Hayes
053:         */
054:        public class ConvertAndAddTest extends TestCase {
055:
056:            private static final String STORE_NAME = "test";
057:
058:            private File envHome;
059:            private Environment env;
060:
061:            public void setUp() throws IOException {
062:
063:                envHome = new File(System.getProperty(TestUtils.DEST_DIR));
064:                TestUtils.removeLogFiles("Setup", envHome, false);
065:            }
066:
067:            public void tearDown() throws IOException {
068:
069:                if (env != null) {
070:                    try {
071:                        env.close();
072:                    } catch (DatabaseException e) {
073:                        System.out.println("During tearDown: " + e);
074:                    }
075:                }
076:                try {
077:                    TestUtils.removeLogFiles("TearDown", envHome, false);
078:                } catch (Error e) {
079:                    System.out.println("During tearDown: " + e);
080:                }
081:                envHome = null;
082:                env = null;
083:            }
084:
085:            private EntityStore open(boolean addConverter)
086:                    throws DatabaseException {
087:
088:                EnvironmentConfig envConfig = new EnvironmentConfig();
089:                envConfig.setAllowCreate(true);
090:                env = new Environment(envHome, envConfig);
091:
092:                Mutations mutations = new Mutations();
093:                mutations.addConverter(new Converter(MyEntity.class.getName(),
094:                        0, "b", new MyConversion()));
095:
096:                StoreConfig storeConfig = new StoreConfig();
097:                storeConfig.setAllowCreate(true);
098:                storeConfig.setMutations(mutations);
099:                return new EntityStore(env, "foo", storeConfig);
100:            }
101:
102:            private void close(EntityStore store) throws DatabaseException {
103:
104:                store.close();
105:                env.close();
106:                env = null;
107:            }
108:
109:            public void testConvertAndAddField() throws DatabaseException,
110:                    IOException {
111:
112:                /* Copy log file resource to log file zero. */
113:                TestUtils.loadLog(getClass(), "ConvertAndAddTest.jdb", envHome);
114:
115:                EntityStore store = open(true /*addConverter*/);
116:
117:                PrimaryIndex<Long, MyEntity> index = store.getPrimaryIndex(
118:                        Long.class, MyEntity.class);
119:
120:                MyEntity entity = index.get(1L);
121:                assertNotNull(entity);
122:                assertEquals(123, entity.b);
123:
124:                close(store);
125:            }
126:
127:            public void xtestSetup() throws DatabaseException {
128:
129:                EntityStore store = open(false /*addConverter*/);
130:
131:                PrimaryIndex<Long, MyEntity> index = store.getPrimaryIndex(
132:                        Long.class, MyEntity.class);
133:
134:                MyEntity entity = new MyEntity();
135:                entity.key = 1;
136:                entity.b = 123;
137:                index.put(entity);
138:
139:                close(store);
140:            }
141:
142:            @Entity(version=1)
143:            static class MyEntity {
144:
145:                @PrimaryKey
146:                long key;
147:
148:                int a; // added in version 1
149:                int b;
150:
151:                private MyEntity() {
152:                }
153:            }
154:
155:            public static class MyConversion implements  Conversion {
156:
157:                public void initialize(EntityModel model) {
158:                }
159:
160:                public Object convert(Object fromValue) {
161:                    return fromValue;
162:                }
163:
164:                @Override
165:                public boolean equals(Object o) {
166:                    return o instanceof  MyConversion;
167:                }
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.