Source Code Cross Referenced for ManagedObjectPersistorImplTest.java in  » Net » Terracotta » com » tc » objectserver » impl » 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 » Net » Terracotta » com.tc.objectserver.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.objectserver.impl;
006:
007:        import com.sleepycat.je.CursorConfig;
008:        import com.tc.logging.TCLogger;
009:        import com.tc.logging.TCLogging;
010:        import com.tc.object.ObjectID;
011:        import com.tc.objectserver.core.api.ManagedObject;
012:        import com.tc.objectserver.core.impl.TestManagedObject;
013:        import com.tc.objectserver.persistence.api.PersistenceTransaction;
014:        import com.tc.objectserver.persistence.api.PersistenceTransactionProvider;
015:        import com.tc.objectserver.persistence.impl.TestMutableSequence;
016:        import com.tc.objectserver.persistence.impl.TestPersistenceTransactionProvider;
017:        import com.tc.objectserver.persistence.sleepycat.DBEnvironment;
018:        import com.tc.objectserver.persistence.sleepycat.ManagedObjectPersistorImpl;
019:        import com.tc.objectserver.persistence.sleepycat.OidBitsArrayMapManagerImpl;
020:        import com.tc.objectserver.persistence.sleepycat.SleepycatCollectionFactory;
021:        import com.tc.objectserver.persistence.sleepycat.SleepycatCollectionsPersistor;
022:        import com.tc.objectserver.persistence.sleepycat.SleepycatSerializationAdapterFactory;
023:        import com.tc.properties.TCPropertiesImpl;
024:        import com.tc.test.TCTestCase;
025:        import com.tc.util.SyncObjectIdSet;
026:
027:        import java.io.File;
028:        import java.util.Collection;
029:        import java.util.HashMap;
030:        import java.util.HashSet;
031:        import java.util.Iterator;
032:        import java.util.Map;
033:        import java.util.Random;
034:
035:        public class ManagedObjectPersistorImplTest extends TCTestCase {
036:            private static final TCLogger logger = TCLogging
037:                    .getTestingLogger(ManagedObjectPersistorImplTest.class);
038:            private ManagedObjectPersistorImpl managedObjectPersistor;
039:            private Map map;
040:            private TestManagedObjectPersistor persistor;
041:            private PersistentManagedObjectStore objectStore;
042:            PersistenceTransactionProvider persistenceTransactionProvider;
043:            DBEnvironment env;
044:            private OidBitsArrayMapManagerImpl oidManager;
045:            private final String OID_FAST_LOAD = "l2.objectmanager.loadObjectID.fastLoad";
046:
047:            public ManagedObjectPersistorImplTest() {
048:                //
049:            }
050:
051:            protected void setUp() throws Exception {
052:                super .setUp();
053:                // test only with Oid fastLoad enabled
054:                TCPropertiesImpl.setProperty(OID_FAST_LOAD, "true");
055:                assertTrue(TCPropertiesImpl.getProperties().getBoolean(
056:                        OID_FAST_LOAD));
057:                boolean paranoid = true;
058:                env = newDBEnvironment(paranoid);
059:                env.open();
060:                CursorConfig dbCursorConfig = new CursorConfig();
061:                persistenceTransactionProvider = new TestPersistenceTransactionProvider();
062:                CursorConfig rootDBCursorConfig = new CursorConfig();
063:                SleepycatCollectionFactory sleepycatCollectionFactory = new SleepycatCollectionFactory();
064:                SleepycatCollectionsPersistor sleepycatCollectionsPersistor = new SleepycatCollectionsPersistor(
065:                        logger, env.getMapsDatabase(),
066:                        sleepycatCollectionFactory);
067:                managedObjectPersistor = new ManagedObjectPersistorImpl(logger,
068:                        env.getClassCatalogWrapper().getClassCatalog(),
069:                        new SleepycatSerializationAdapterFactory(), env
070:                                .getObjectDatabase(), env.getOidDatabase(),
071:                        dbCursorConfig, new TestMutableSequence(), env
072:                                .getRootDatabase(), rootDBCursorConfig,
073:                        persistenceTransactionProvider,
074:                        sleepycatCollectionsPersistor, env.isParanoidMode());
075:                map = new HashMap();
076:                persistor = new TestManagedObjectPersistor(map);
077:                objectStore = new PersistentManagedObjectStore(
078:                        managedObjectPersistor);
079:                oidManager = managedObjectPersistor.getOidManager();
080:            }
081:
082:            protected void tearDown() throws Exception {
083:                env.close();
084:                super .tearDown();
085:            }
086:
087:            private DBEnvironment newDBEnvironment(boolean paranoid)
088:                    throws Exception {
089:                File dbHome;
090:                int count = 0;
091:                do {
092:                    dbHome = new File(this .getTempDirectory(), getClass()
093:                            .getName()
094:                            + "db" + (++count));
095:                } while (dbHome.exists());
096:                dbHome.mkdir();
097:                assertTrue(dbHome.exists());
098:                assertTrue(dbHome.isDirectory());
099:                System.out.println("DB Home: " + dbHome);
100:                DBEnvironment env = new DBEnvironment(paranoid, dbHome);
101:                return env;
102:            }
103:
104:            private Collection createRandomObjects(int num) {
105:                Random r = new Random();
106:                HashSet objects = new HashSet(num);
107:                HashSet ids = new HashSet(num);
108:                for (int i = 0; i < num; i++) {
109:                    long id = (long) r.nextInt(num * 10) + 1;
110:                    if (ids.add(new Long(id))) {
111:                        ManagedObject mo = new TestManagedObject(new ObjectID(
112:                                id), new ObjectID[] {});
113:                        objects.add(mo);
114:                    }
115:                }
116:                logger.info("Test with " + objects.size() + " objects");
117:                return (objects);
118:            }
119:
120:            private void verify(Collection objects) {
121:                // verify a in-memory bit crosspond to an object ID
122:                HashSet originalIds = new HashSet();
123:                for (Iterator i = objects.iterator(); i.hasNext();) {
124:                    ManagedObject mo = (ManagedObject) i.next();
125:                    originalIds.add(mo.getID());
126:                }
127:                Collection inMemoryIds = oidManager.bitsArrayMapToObjectID();
128:                assertTrue("Wrong bits in memory were set", originalIds
129:                        .containsAll(inMemoryIds));
130:
131:                // verify on disk object IDs
132:                // clear in memory arrays then read in from persistor
133:                oidManager.resetBitsArrayMap();
134:                SyncObjectIdSet idSet = managedObjectPersistor
135:                        .getAllObjectIDs();
136:                idSet.snapshot(); // blocked while reading from disk
137:                Collection diskIds = oidManager.bitsArrayMapToObjectID();
138:                assertTrue("Wrong object IDs on disk", diskIds
139:                        .equals(inMemoryIds));
140:
141:            }
142:
143:            public void testOidBitsArraySave() throws Exception {
144:                // wait for background retrieving persistent data
145:                objectStore.getAllObjectIDs();
146:                oidManager.resetBitsArrayMap();
147:
148:                // publish data
149:                Collection objects = createRandomObjects(15050);
150:                PersistenceTransaction ptx = persistenceTransactionProvider
151:                        .newTransaction();
152:                managedObjectPersistor.saveAllObjects(ptx, objects);
153:                ptx.commit();
154:
155:                // verify object IDs is in memory
156:                for (Iterator i = objects.iterator(); i.hasNext();) {
157:                    ManagedObject mo = (ManagedObject) i.next();
158:                    assertTrue("Object:" + mo.getID() + " missed in memory! ",
159:                            oidManager.inMemoryContains(mo.getID()));
160:                }
161:
162:                verify(objects);
163:            }
164:
165:            public void testOidBitsArrayDeleteHalf() throws Exception {
166:                // wait for background retrieving persistent data
167:                objectStore.getAllObjectIDs();
168:                oidManager.resetBitsArrayMap();
169:
170:                // publish data
171:                Collection objects = createRandomObjects(15050);
172:                PersistenceTransaction ptx = persistenceTransactionProvider
173:                        .newTransaction();
174:                managedObjectPersistor.saveAllObjects(ptx, objects);
175:                ptx.commit();
176:
177:                int total = objects.size();
178:                HashSet toDelete = new HashSet();
179:                int count = 0;
180:                for (Iterator i = objects.iterator(); (count < total / 2)
181:                        && i.hasNext();) {
182:                    ManagedObject mo = (ManagedObject) i.next();
183:                    toDelete.add(mo.getID());
184:                    i.remove();
185:                }
186:                ptx = persistenceTransactionProvider.newTransaction();
187:                managedObjectPersistor.deleteAllObjectsByID(ptx, toDelete);
188:                ptx.commit();
189:
190:                verify(objects);
191:            }
192:
193:            public void testOidBitsArrayDeleteAll() throws Exception {
194:                // wait for background retrieving persistent data
195:                objectStore.getAllObjectIDs();
196:                oidManager.resetBitsArrayMap();
197:
198:                // publish data
199:                Collection objects = createRandomObjects(15050);
200:                PersistenceTransaction ptx = persistenceTransactionProvider
201:                        .newTransaction();
202:                managedObjectPersistor.saveAllObjects(ptx, objects);
203:                ptx.commit();
204:
205:                HashSet objectIds = new HashSet();
206:                for (Iterator i = objects.iterator(); i.hasNext();) {
207:                    ManagedObject mo = (ManagedObject) i.next();
208:                    objectIds.add(mo.getID());
209:                }
210:                ptx = persistenceTransactionProvider.newTransaction();
211:                managedObjectPersistor.deleteAllObjectsByID(ptx, objectIds);
212:                ptx.commit();
213:
214:                objects.clear();
215:                verify(objects);
216:            }
217:
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.