dain 2006/02/01 06:50:10
Modified: modules/core/src/test/org/openejb/slsb InvocationTest.java
MockEJBContainerGBean.java
Added: modules/core/src/test/org/openejb/slsb
MockEjbDeployment.java
Removed: modules/core/src/test/org/openejb/slsb MockEJBContainer.java
StatelessInstanceInterceptorTest.java
Log:
Major refactor
Split container into an object to represent a deployed ejb and a set of
shared containers which process invocations
Introduced interface between CMP container and CMP engine
Revision Changes Path
1.10 +1 -49
openejb/modules/core/src/test/org/openejb/slsb/InvocationTest.java
Index: InvocationTest.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/test/org/openejb/slsb/InvocationTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- InvocationTest.java 5 Feb 2005 00:49:46 -0000 1.9
+++ InvocationTest.java 1 Feb 2006 11:50:10 -0000 1.10
@@ -48,21 +48,10 @@
package org.openejb.slsb;
import java.lang.reflect.Method;
-import java.util.HashSet;
-
-import javax.ejb.SessionBean;
-import javax.ejb.SessionContext;
-import javax.ejb.Timer;
import junit.framework.TestCase;
import net.sf.cglib.reflect.FastClass;
import org.apache.geronimo.core.service.SimpleInvocationResult;
-import org.openejb.EJBInterfaceType;
-import org.openejb.EJBInvocation;
-import org.openejb.EJBInvocationImpl;
-import org.openejb.dispatch.InterfaceMethodSignature;
-import org.openejb.dispatch.MethodSignature;
-import org.openejb.dispatch.SystemMethodIndices;
/**
*
@@ -70,19 +59,8 @@
* @version $Revision$ $Date$
*/
public class InvocationTest extends TestCase {
- private BusinessMethod bizMethod;
private FastClass fastClass;
private int index;
- private final static InterfaceMethodSignature[] signatures = new
InterfaceMethodSignature[] {
- new InterfaceMethodSignature("ejbActivate", false),
- new InterfaceMethodSignature("ejbLoad", false),
- new InterfaceMethodSignature("ejbPassivate", false),
- new InterfaceMethodSignature("ejbStore", false),
- new InterfaceMethodSignature("ejbCreate", false),
- new InterfaceMethodSignature("ejbRemove", false),
- new InterfaceMethodSignature("ejbTimeout", new Class[]
{Timer.class}, false),
- new InterfaceMethodSignature("setSessionContext", new Class[]
{SessionContext.class}, false),
- };
public void testMethodInvoke() throws Exception {
MockEJB instance = new MockEJB();
@@ -131,35 +109,9 @@
System.out.println("FastClass with result: " + ((end - start) *
1000000.0 / 1000000) + "ns");
}
- public void testBizMethodInvoke() throws Throwable {
- SessionBean instance = new MockEJB();
- Object[] args = {new Integer(1)};
- EJBInvocation invocation = new
EJBInvocationImpl(EJBInterfaceType.LOCAL, index, args);
- StatelessInstanceContext ctx = new StatelessInstanceContext(
- "containerID",
- instance,
- null,
-// transactionContextManager,
- null,
- null,
- SystemMethodIndices.createSystemMethodIndices(signatures,
"setSessionContext", SessionContext.class.getName(), null),
- null, new HashSet(),
- new HashSet(),
- null);
- invocation.setEJBInstanceContext(ctx);
- bizMethod.execute(invocation);
- long start = System.currentTimeMillis();
- for (int i = 0; i < 1000000; i++) {
- bizMethod.execute(invocation);
- }
- long end = System.currentTimeMillis();
- System.out.println("BizMethod: " + ((end - start) * 1000000.0 /
1000000) + "ns");
- }
-
protected void setUp() throws Exception {
super.setUp();
fastClass = FastClass.create(MockEJB.class);
index = fastClass.getIndex("intMethod", new Class[]{Integer.TYPE});
- bizMethod = new BusinessMethod(MockEJB.class, new
MethodSignature("intMethod", new Class[]{Integer.TYPE}));
}
}
1.6 +3 -3
openejb/modules/core/src/test/org/openejb/slsb/MockEJBContainerGBean.java
Index: MockEJBContainerGBean.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/test/org/openejb/slsb/MockEJBContainerGBean.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MockEJBContainerGBean.java 1 Dec 2005 08:34:53 -0000 1.5
+++ MockEJBContainerGBean.java 1 Feb 2006 11:50:10 -0000 1.6
@@ -63,7 +63,7 @@
public static final GBeanInfo GBEAN_INFO;
static {
- GBeanInfoBuilder infoFactory =
GBeanInfoBuilder.createStatic(MockEJBContainerGBean.class,
MockEJBContainer.class);
+ GBeanInfoBuilder infoFactory =
GBeanInfoBuilder.createStatic(MockEJBContainerGBean.class,
MockEjbDeployment.class);
infoFactory.addAttribute("ejbJarURL", URL.class, true);
infoFactory.addAttribute("ejbName", String.class, true);
@@ -98,7 +98,7 @@
public static ObjectName addGBean(Kernel kernel, URL ejbJarURL, String
ejbName, String ejbClass, String home, String remote, String localHome, String
local, String serviceEndpoint) throws GBeanAlreadyExistsException,
GBeanNotFoundException {
GBeanData gbean = createGBean(ejbJarURL, ejbName, ejbClass, home,
remote, localHome, local, serviceEndpoint);
- kernel.loadGBean(gbean, MockEJBContainer.class.getClassLoader());
+ kernel.loadGBean(gbean, MockEjbDeployment.class.getClassLoader());
kernel.startGBean(gbean.getName());
return gbean.getName();
}
1.1
openejb/modules/core/src/test/org/openejb/slsb/MockEjbDeployment.java
Index: MockEjbDeployment.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: MockEjbDeployment.java,v 1.1 2006/02/01 11:50:10 dain Exp $
*/
package org.openejb.slsb;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.io.Serializable;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
import javax.management.ObjectName;
import javax.security.auth.Subject;
import org.apache.geronimo.core.service.Invocation;
import org.apache.geronimo.core.service.InvocationResult;
import org.apache.geronimo.core.service.SimpleInvocationResult;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.openejb.EJBComponentType;
import org.openejb.RpcEjbDeployment;
import org.openejb.EjbDeployment;
import org.openejb.dispatch.InterfaceMethodSignature;
import org.openejb.proxy.EJBProxyFactory;
import org.openejb.proxy.ProxyInfo;
public class MockEjbDeployment implements RpcEjbDeployment {
private final ProxyInfo proxyInfo;
private final Class ejbClass;
private final Method[] methods;
public MockEjbDeployment() {
this.proxyInfo = new ProxyInfo(EJBComponentType.STATELESS, "foo",
MockHome.class, MockRemote.class, MockLocalHome.class, MockLocal.class,
MockServiceEndpoint.class, null);
ejbClass = MockEJB.class;
methods = ejbClass.getMethods();
}
public MockEjbDeployment(URL ejbJarURL, String ejbName, String ejbClass,
String home, String remote, String localHome, String local, String
serviceEndpoint) {
ClassLoader cl = new URLClassLoader(new URL[]{ejbJarURL},
MockEjbDeployment.class.getClassLoader());
try {
this.proxyInfo = new ProxyInfo(EJBComponentType.STATELESS,
ejbName, cl.loadClass(home), cl.loadClass(remote), cl.loadClass(localHome),
cl.loadClass(local), cl.loadClass(serviceEndpoint), null);
this.ejbClass = cl.loadClass(ejbClass);
this.methods = this.ejbClass.getMethods();
} catch (ClassNotFoundException e) {
throw (IllegalStateException) new IllegalStateException("Could
not initialize the MockEJBContainer").initCause(e);
}
}
public int getMethodIndex(Method callMethod) {
assert callMethod == null: "Method cannot be null";
Method ejbMethod = null;
try {
ejbMethod = ejbClass.getMethod(callMethod.getName(),
callMethod.getParameterTypes());
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Method does not exist in bean
class: " + callMethod);
}
for (int i = 0; i < methods.length; i++) {
if (methods[i].equals(ejbMethod)) {
return i;
}
}
throw new IllegalArgumentException("Method does not exist in bean
class: " + callMethod);
}
public String getContainerId() {
return null;
}
public String getEjbName() {
return null;
}
public EJBHome getEjbHome() {
return null;
}
public EJBObject getEjbObject(Object primaryKey) {
return null;
}
public EJBLocalHome getEjbLocalHome() {
return null;
}
public EJBLocalObject getEjbLocalObject(Object primaryKey) {
return null;
}
public Object invoke(Method callMethod, Object[] args, Object primKey)
throws Throwable {
Method ejbMethod = ejbClass.getMethod(callMethod.getName(),
callMethod.getParameterTypes());
Object ejb = ejbClass.newInstance();
return ejbMethod.invoke(ejb, args);
}
public InvocationResult invoke(Invocation invocation) throws Throwable {
try {
org.openejb.EjbInvocation i = (org.openejb.EjbInvocation)
invocation;
Object result = invoke(methods[i.getMethodIndex()],
i.getArguments(), i.getId());
return new SimpleInvocationResult(true, result);
} catch (Throwable throwable) {
return new SimpleInvocationResult(false, throwable);
}
}
public String[] getJndiNames() {
return new String[0];
}
public String[] getLocalJndiNames() {
return new String[0];
}
public EJBProxyFactory getProxyFactory() {
return null;
}
public ClassLoader getClassLoader() {
return MockEjbDeployment.class.getClassLoader();
}
public EjbDeployment getUnmanagedReference() {
return null;
}
public InterfaceMethodSignature[] getSignatures() {
return new InterfaceMethodSignature[0];
}
public ProxyInfo getProxyInfo() {
return proxyInfo;
}
public Subject getDefaultSubject() {
return null;
}
public Serializable getHomeTxPolicyConfig() {
return null;
}
public Serializable getRemoteTxPolicyConfig() {
return null;
}
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory =
GBeanInfoBuilder.createStatic(MockEjbDeployment.class);
infoFactory.addAttribute("ejbName", String.class, true);
infoFactory.addAttribute("ProxyInfo", ProxyInfo.class, true);
infoFactory.addOperation("getMethodIndex", new Class[]
{Method.class});
infoFactory.addOperation("getEjbObject", new Class[] {Object.class});
infoFactory.addOperation("getEjbLocalObject", new Class[]
{Object.class});
infoFactory.addOperation("invoke", new Class[]{Invocation.class});
infoFactory.addOperation("invoke", new Class[]{Method.class,
Object[].class, Object.class});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
public static ObjectName addGBean(Kernel kernel, String name) throws
GBeanAlreadyExistsException, GBeanNotFoundException {
ObjectName gbeanName =
JMXUtil.getObjectName("openejb:j2eeType=StatelessSessionBean,name=" + name);
GBeanData gbean1 = new GBeanData(gbeanName,
MockEjbDeployment.GBEAN_INFO);
GBeanData gbean = gbean1;
kernel.loadGBean(gbean, MockEjbDeployment.class.getClassLoader());
kernel.startGBean(gbean.getName());
return gbean.getName();
}
public static ObjectName addGBean(Kernel kernel, String name, ClassLoader
cl) throws GBeanAlreadyExistsException, GBeanNotFoundException {
ObjectName gbeanName =
JMXUtil.getObjectName("openejb:j2eeType=StatelessSessionBean,name=" + name);
GBeanData gbean1 = new GBeanData(gbeanName,
MockEjbDeployment.GBEAN_INFO);
GBeanData gbean = gbean1;
kernel.loadGBean(gbean, cl);
kernel.startGBean(gbean.getName());
return gbean.getName();
}
}