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


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2000,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: StoredClassCatalogTest.java,v 1.35.2.2 2008/01/07 15:14:24 cwl Exp $
007:         */
008:        package com.sleepycat.collections.test.serial;
009:
010:        import java.io.ObjectStreamClass;
011:        import java.util.Map;
012:
013:        import junit.framework.Test;
014:        import junit.framework.TestCase;
015:        import junit.framework.TestSuite;
016:
017:        import com.sleepycat.bind.serial.SerialBinding;
018:        import com.sleepycat.bind.serial.StoredClassCatalog;
019:        import com.sleepycat.collections.StoredMap;
020:        import com.sleepycat.collections.TransactionRunner;
021:        import com.sleepycat.collections.TransactionWorker;
022:        import com.sleepycat.collections.test.DbTestUtil;
023:        import com.sleepycat.collections.test.TestEnv;
024:        import com.sleepycat.compat.DbCompat;
025:        import com.sleepycat.je.Database;
026:        import com.sleepycat.je.DatabaseConfig;
027:        import com.sleepycat.je.Environment;
028:
029:        /**
030:         * Runs part two of the StoredClassCatalogTest.  This part is run with the
031:         * new/updated version of TestSerial in the classpath.  It uses the
032:         * environment and databases created by StoredClassCatalogTestInit.  It
033:         * verifies that it can read objects serialized using the old class format,
034:         * and that it can create new objects with the new class format.
035:         *
036:         * @author Mark Hayes
037:         */
038:        public class StoredClassCatalogTest extends TestCase implements 
039:                TransactionWorker {
040:
041:            static final String CATALOG_FILE = "catalogtest-catalog.db";
042:            static final String STORE_FILE = "catalogtest-store.db";
043:
044:            public static void main(String[] args) throws Exception {
045:
046:                junit.framework.TestResult tr = junit.textui.TestRunner
047:                        .run(suite());
048:                if (tr.errorCount() > 0 || tr.failureCount() > 0) {
049:                    System.exit(1);
050:                } else {
051:                    System.exit(0);
052:                }
053:            }
054:
055:            public static Test suite() throws Exception {
056:
057:                TestSuite suite = new TestSuite();
058:                for (int i = 0; i < TestEnv.ALL.length; i += 1) {
059:                    suite.addTest(new StoredClassCatalogTest(TestEnv.ALL[i]));
060:                }
061:                return suite;
062:            }
063:
064:            private TestEnv testEnv;
065:            private Environment env;
066:            private StoredClassCatalog catalog;
067:            private StoredClassCatalog catalog2;
068:            private Database store;
069:            private Map map;
070:            private TransactionRunner runner;
071:
072:            public StoredClassCatalogTest(TestEnv testEnv) {
073:
074:                super (makeTestName(testEnv));
075:                this .testEnv = testEnv;
076:            }
077:
078:            static String makeTestName(TestEnv testEnv) {
079:                return "StoredClassCatalogTest-" + testEnv.getName();
080:            }
081:
082:            public void setUp() throws Exception {
083:
084:                DbTestUtil.printTestName(getName());
085:                env = testEnv.open(makeTestName(testEnv), false);
086:                runner = new TransactionRunner(env);
087:
088:                catalog = new StoredClassCatalog(openDb(CATALOG_FILE, false));
089:                catalog2 = new StoredClassCatalog(openDb("catalog2.db", true));
090:
091:                SerialBinding keyBinding = new SerialBinding(catalog,
092:                        String.class);
093:                SerialBinding valueBinding = new SerialBinding(catalog,
094:                        TestSerial.class);
095:                store = openDb(STORE_FILE, false);
096:
097:                map = new StoredMap(store, keyBinding, valueBinding, true);
098:            }
099:
100:            private Database openDb(String file, boolean create)
101:                    throws Exception {
102:
103:                DatabaseConfig config = new DatabaseConfig();
104:                DbCompat.setTypeBtree(config);
105:                config.setTransactional(testEnv.isTxnMode());
106:                config.setAllowCreate(create);
107:
108:                return DbCompat.openDatabase(env, null, file, null, config);
109:            }
110:
111:            public void tearDown() {
112:
113:                try {
114:                    if (catalog != null) {
115:                        catalog.close();
116:                        catalog.close(); // should have no effect
117:                    }
118:                    if (catalog2 != null) {
119:                        catalog2.close();
120:                    }
121:                    if (store != null) {
122:                        store.close();
123:                    }
124:                    if (env != null) {
125:                        env.close();
126:                    }
127:                } catch (Exception e) {
128:                    System.err.println("Ignored exception during tearDown: ");
129:                    e.printStackTrace();
130:                } finally {
131:                    /* Ensure that GC can cleanup. */
132:                    catalog = null;
133:                    catalog2 = null;
134:                    store = null;
135:                    env = null;
136:                    testEnv = null;
137:                    map = null;
138:                    runner = null;
139:                }
140:            }
141:
142:            public void runTest() throws Exception {
143:
144:                runner.run(this );
145:            }
146:
147:            public void doWork() throws Exception {
148:
149:                TestSerial one = (TestSerial) map.get("one");
150:                TestSerial two = (TestSerial) map.get("two");
151:                assertNotNull(one);
152:                assertNotNull(two);
153:                assertEquals(one, two.getOther());
154:                assertNull(one.getStringField());
155:                assertNull(two.getStringField());
156:
157:                TestSerial three = new TestSerial(two);
158:                assertNotNull(three.getStringField());
159:                map.put("three", three);
160:                three = (TestSerial) map.get("three");
161:                assertEquals(two, three.getOther());
162:
163:                ObjectStreamClass desc = ObjectStreamClass
164:                        .lookup(TestSerial.class);
165:
166:                assertNotNull(catalog.getClassID(desc));
167:                assertNotNull(catalog.getClassID(desc));
168:
169:                // test with empty catalog
170:                assertNotNull(catalog2.getClassID(desc));
171:                assertNotNull(catalog2.getClassID(desc));
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.