Source Code Cross Referenced for ClusteredStatefulInstanceManagerTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » openejb » cluster » stateful » container » 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 » EJB Server geronimo » plugins » org.apache.geronimo.openejb.cluster.stateful.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         *  http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.geronimo.openejb.cluster.stateful.container;
021:
022:        import java.io.IOException;
023:        import java.rmi.dgc.VMID;
024:        import java.util.concurrent.Callable;
025:        import java.util.concurrent.FutureTask;
026:
027:        import javax.transaction.TransactionManager;
028:        import javax.transaction.TransactionSynchronizationRegistry;
029:
030:        import org.apache.geronimo.clustering.Session;
031:        import org.apache.geronimo.clustering.SessionListener;
032:        import org.apache.geronimo.clustering.wadi.WADISessionManager;
033:        import org.apache.geronimo.openejb.cluster.stateful.container.ClusteredStatefulContainerTest.SFSB;
034:        import org.apache.openejb.core.CoreDeploymentInfo;
035:        import org.apache.openejb.core.ThreadContext;
036:        import org.apache.openejb.core.stateful.BeanEntry;
037:        import org.apache.openejb.persistence.JtaEntityManagerRegistry;
038:        import org.apache.openejb.spi.SecurityService;
039:
040:        import com.agical.rmock.core.Action;
041:        import com.agical.rmock.core.MethodHandle;
042:        import com.agical.rmock.core.describe.ExpressionDescriber;
043:        import com.agical.rmock.core.match.operator.AbstractExpression;
044:        import com.agical.rmock.extension.junit.RMockTestCase;
045:
046:        /**
047:         *
048:         * @version $Rev:$ $Date:$
049:         */
050:        public class ClusteredStatefulInstanceManagerTest extends RMockTestCase {
051:
052:            private ClusteredStatefulInstanceManager manager;
053:            private String deploymentId;
054:            private CoreDeploymentInfo deploymentInfo;
055:            private VMID primKey;
056:            private ThreadContext threadContext;
057:            private WADISessionManager sessionManager;
058:            private SessionListener sessionListener;
059:
060:            @Override
061:            protected void setUp() throws Exception {
062:                TransactionManager txManager = (TransactionManager) mock(TransactionManager.class);
063:                SecurityService securityService = (SecurityService) mock(SecurityService.class);
064:                TransactionSynchronizationRegistry txSynchRegistry = (TransactionSynchronizationRegistry) mock(TransactionSynchronizationRegistry.class);
065:                JtaEntityManagerRegistry jtaEntityManagerRegistry = new JtaEntityManagerRegistry(
066:                        txSynchRegistry);
067:
068:                manager = (ClusteredStatefulInstanceManager) intercept(
069:                        ClusteredStatefulInstanceManager.class, new Object[] {
070:                                txManager, securityService,
071:                                jtaEntityManagerRegistry, null, 1, 1, 1 });
072:
073:                deploymentId = "deploymentId";
074:                deploymentInfo = new CoreDeploymentInfo(null, SFSB.class, null,
075:                        null, null, null, null, null, null, null, null) {
076:                    @Override
077:                    public ClassLoader getClassLoader() {
078:                        return getClass().getClassLoader();
079:                    }
080:
081:                    @Override
082:                    public Object getDeploymentID() {
083:                        return deploymentId;
084:                    }
085:                };
086:
087:                primKey = new VMID();
088:
089:                sessionManager = (WADISessionManager) mock(WADISessionManager.class);
090:
091:                threadContext = new ThreadContext(deploymentInfo, primKey);
092:                ThreadContext.enter(threadContext);
093:            }
094:
095:            @Override
096:            protected void tearDown() throws Exception {
097:                ThreadContext.exit(threadContext);
098:            }
099:
100:            public void testNewBeanEntryForUnknownDeploymentThrowsISE()
101:                    throws Exception {
102:                startVerification();
103:
104:                try {
105:                    manager.newBeanEntry("primaryKey", new Object());
106:                    fail();
107:                } catch (IllegalStateException e) {
108:                }
109:            }
110:
111:            public void testNewBeanEntryOK() throws Exception {
112:                VMID primaryKey = new VMID();
113:
114:                recordAddSessionManagerAndCreateSession(primaryKey);
115:
116:                startVerification();
117:
118:                manager.addSessionManager(deploymentId, sessionManager);
119:                manager.newBeanEntry(primaryKey, new Object());
120:            }
121:
122:            public void testSessionDestructionFreeInstance() throws Exception {
123:                Session session = recordAddSessionManagerAndCreateSession(primKey);
124:                FutureTask<BeanEntry> newBeanEntryTask = newBeanEntryTask(
125:                        primKey, session);
126:
127:                manager.freeInstance(null);
128:                modify().args(new ThreadContextArgAssertion());
129:
130:                startVerification();
131:
132:                manager.deploy(deploymentInfo, null);
133:                manager.addSessionManager(deploymentId, sessionManager);
134:
135:                newBeanEntryTask.run();
136:                sessionListener.notifySessionDestruction(session);
137:            }
138:
139:            public void testInboundSessionMigrationActivateAndPoolBeanEntry()
140:                    throws Exception {
141:                Session session = recordAddSessionManagerAndCreateSession(primKey);
142:                FutureTask<BeanEntry> newBeanEntryTask = newBeanEntryTask(
143:                        primKey, session);
144:
145:                manager.activateInstance(null, null);
146:                modify().args(new ThreadContextArgAssertion(), is.NOT_NULL);
147:                manager.poolInstance(null, null);
148:                modify().args(new ThreadContextArgAssertion(), is.NOT_NULL);
149:
150:                startVerification();
151:
152:                manager.deploy(deploymentInfo, null);
153:                manager.addSessionManager(deploymentId, sessionManager);
154:
155:                newBeanEntryTask.run();
156:                sessionListener.notifyInboundSessionMigration(session);
157:            }
158:
159:            public void testOutboundSessionMigrationPassivateBeanEntry()
160:                    throws Exception {
161:                Session session = recordAddSessionManagerAndCreateSession(primKey);
162:                FutureTask<BeanEntry> newBeanEntryTask = newBeanEntryTask(
163:                        primKey, session);
164:
165:                manager.passivate(null, null);
166:                modify().args(new ThreadContextArgAssertion(), is.NOT_NULL);
167:
168:                manager.freeInstance(null);
169:                modify().args(new ThreadContextArgAssertion());
170:
171:                startVerification();
172:
173:                manager.deploy(deploymentInfo, null);
174:                manager.addSessionManager(deploymentId, sessionManager);
175:
176:                newBeanEntryTask.run();
177:                sessionListener.notifyOutboundSessionMigration(session);
178:            }
179:
180:            public void testOnFreeBeanEntryReleaseSession() throws Exception {
181:                Session session = (Session) mock(Session.class);
182:                session.addState(ClusteredBeanEntry.SESSION_KEY_ENTRY, null);
183:                modify().args(is.AS_RECORDED, is.NOT_NULL);
184:
185:                session.release();
186:
187:                startVerification();
188:
189:                manager.onFreeBeanEntry(threadContext, new ClusteredBeanEntry(
190:                        session, deploymentId, new Object(), primKey, 0));
191:            }
192:
193:            public void testOnPoolInstanceWithoutTransactionTriggersSessionOnEndAccess()
194:                    throws Exception {
195:                Session session = (Session) mock(Session.class);
196:                session.addState(ClusteredBeanEntry.SESSION_KEY_ENTRY, null);
197:                modify().args(is.AS_RECORDED, is.NOT_NULL);
198:
199:                session.addState(ClusteredBeanEntry.SESSION_KEY_ENTRY, null);
200:                modify().args(is.AS_RECORDED, is.NOT_NULL);
201:                session.onEndAccess();
202:
203:                startVerification();
204:
205:                manager.onPoolInstanceWithoutTransaction(threadContext,
206:                        new ClusteredBeanEntry(session, deploymentId,
207:                                new Object(), primKey, 0));
208:            }
209:
210:            private FutureTask<BeanEntry> newBeanEntryTask(
211:                    final VMID primaryKey, Session session) {
212:                final FutureTask<BeanEntry> newBeanEntryTask = new FutureTask<BeanEntry>(
213:                        new Callable<BeanEntry>() {
214:                            public BeanEntry call() throws Exception {
215:                                return manager.newBeanEntry(primaryKey,
216:                                        new Object());
217:                            }
218:                        });
219:                session.getState(ClusteredBeanEntry.SESSION_KEY_ENTRY);
220:                modify().multiplicity(expect.from(0)).perform(new Action() {
221:                    public Object invocation(Object[] arg0, MethodHandle arg1)
222:                            throws Throwable {
223:                        return newBeanEntryTask.get();
224:                    }
225:                });
226:                return newBeanEntryTask;
227:            }
228:
229:            private Session recordAddSessionManagerAndCreateSession(
230:                    VMID primaryKey) throws Exception {
231:                sessionManager.registerListener(null);
232:                modify().args(new AbstractExpression() {
233:                    public void describeWith(ExpressionDescriber arg0)
234:                            throws IOException {
235:                    }
236:
237:                    public boolean passes(Object arg0) {
238:                        sessionListener = (SessionListener) arg0;
239:                        return true;
240:                    }
241:                });
242:
243:                Session session = sessionManager.createSession(primaryKey
244:                        .toString());
245:
246:                session.addState(ClusteredBeanEntry.SESSION_KEY_ENTRY, null);
247:                modify().args(is.AS_RECORDED, is.NOT_NULL);
248:
249:                return session;
250:            }
251:
252:            protected final class ThreadContextArgAssertion extends
253:                    AbstractExpression {
254:                public void describeWith(ExpressionDescriber arg0)
255:                        throws IOException {
256:                }
257:
258:                public boolean passes(Object arg0) {
259:                    ThreadContext context = (ThreadContext) arg0;
260:                    assertSame(deploymentInfo, context.getDeploymentInfo());
261:                    assertSame(primKey, context.getPrimaryKey());
262:                    return true;
263:                }
264:            }
265:
266:        }
w__ww_.__j_a_v___a2__s___.__c__o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.