dain        2005/01/26 18:28:02

  Modified:    modules/openejb-builder/src/test/org/openejb/deployment/slsb
                        BasicStatelessContainerTest.java MockEJB.java
                        MockLocal.java StatelessClientContainerTest.java
  Log:

  ENC is now passed around as a Map instead of a jndi Context.  This allows the 
ejb container to modify it and inject the kernel and class loader into 
references.
  Changed Stateless and MDB containers to use system chain for ejbCreate and 
ejbRemove invocations.
  Added test to verify that ejbRemove is propertly called from the cache code.
  
  Revision  Changes    Path
  1.4       +3 -3      
openejb/modules/openejb-builder/src/test/org/openejb/deployment/slsb/BasicStatelessContainerTest.java
  
  Index: BasicStatelessContainerTest.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/slsb/BasicStatelessContainerTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BasicStatelessContainerTest.java  22 Jan 2005 00:39:16 -0000      1.3
  +++ BasicStatelessContainerTest.java  26 Jan 2005 23:28:02 -0000      1.4
  @@ -49,12 +49,12 @@
   
   import java.util.Collections;
   import java.util.HashSet;
  +import java.util.HashMap;
   import javax.management.ObjectName;
   
   import junit.framework.TestCase;
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.kernel.jmx.JMXUtil;
  -import org.apache.geronimo.naming.java.ReadOnlyContext;
   import org.apache.geronimo.gbean.GBeanData;
   import org.openejb.deployment.DeploymentHelper;
   import org.openejb.deployment.StatelessContainerBuilder;
  @@ -168,7 +168,7 @@
               }
           });
           builder.setSecurityConfiguration(new SecurityConfiguration());
  -        builder.setComponentContext(new ReadOnlyContext());
  +        builder.setComponentContext(new HashMap());
           container = builder.createConfiguration();
   
           //start the ejb container
  
  
  
  1.2       +26 -5     
openejb/modules/openejb-builder/src/test/org/openejb/deployment/slsb/MockEJB.java
  
  Index: MockEJB.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/slsb/MockEJB.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MockEJB.java      10 Nov 2004 01:35:12 -0000      1.1
  +++ MockEJB.java      26 Jan 2005 23:28:02 -0000      1.2
  @@ -54,19 +54,38 @@
   import javax.ejb.Timer;
   import javax.ejb.TimerService;
   
  -
   /**
  - *
  - *
  - *
    * @version $Revision$ $Date$
    */
   public class MockEJB implements SessionBean, TimedObject {
  +    private static final Object lock = new Object();
  +    private static boolean hasWaiter = false;
   
       private int timeoutCount = 0;
   
       private SessionContext sessionContext;
   
  +    public boolean createCalled = false;
  +    public boolean removeCalled = false;
  +
  +    public MockEJB waitForSecondThread(long timeout) {
  +        synchronized (lock) {
  +            if (!hasWaiter) {
  +                try {
  +                    hasWaiter = true;
  +                    lock.wait(timeout);
  +                } catch (InterruptedException e) {
  +                    // don't care
  +                } finally {
  +                    hasWaiter = false;
  +                }
  +            } else {
  +                lock.notifyAll();
  +            }
  +            return this;
  +        }
  +    }
  +
       public int intMethod(int i) {
           return i + 1;
       }
  @@ -97,6 +116,7 @@
       }
   
       public void ejbCreate() throws CreateException {
  +        createCalled = true;
       }
   
       public void ejbActivate() {
  @@ -106,6 +126,7 @@
       }
   
       public void ejbRemove() {
  +        removeCalled = true;
       }
   
       public void ejbTimeout(Timer timer) {
  
  
  
  1.2       +3 -5      
openejb/modules/openejb-builder/src/test/org/openejb/deployment/slsb/MockLocal.java
  
  Index: MockLocal.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/slsb/MockLocal.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MockLocal.java    10 Nov 2004 01:35:12 -0000      1.1
  +++ MockLocal.java    26 Jan 2005 23:28:02 -0000      1.2
  @@ -49,14 +49,12 @@
   
   import javax.ejb.EJBLocalObject;
   
  -
   /**
  - *
  - *
  - *
    * @version $Revision$ $Date$
    */
   public interface MockLocal extends EJBLocalObject {
  +    MockEJB waitForSecondThread(long timeout);
  +
       int intMethod(int i);
   
       Integer integerMethod(Integer i);
  
  
  
  1.3       +28 -10    
openejb/modules/openejb-builder/src/test/org/openejb/deployment/slsb/StatelessClientContainerTest.java
  
  Index: StatelessClientContainerTest.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/slsb/StatelessClientContainerTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StatelessClientContainerTest.java 11 Dec 2004 05:03:33 -0000      1.2
  +++ StatelessClientContainerTest.java 26 Jan 2005 23:28:02 -0000      1.3
  @@ -49,6 +49,7 @@
   
   import java.rmi.RemoteException;
   import java.util.HashSet;
  +import java.util.HashMap;
   import javax.ejb.EJBException;
   import javax.ejb.EJBHome;
   import javax.ejb.EJBMetaData;
  @@ -60,19 +61,12 @@
   import junit.framework.AssertionFailedError;
   import junit.framework.TestCase;
   import 
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
  -import org.apache.geronimo.naming.java.ReadOnlyContext;
   import org.apache.geronimo.transaction.context.TransactionContextManager;
   import org.openejb.EJBContainer;
   import org.openejb.deployment.MockTransactionManager;
   import org.openejb.deployment.StatelessContainerBuilder;
   import org.openejb.dispatch.InterfaceMethodSignature;
   import org.openejb.security.SecurityConfiguration;
  -import org.openejb.slsb.AppException;
  -import org.openejb.slsb.MockEJB;
  -import org.openejb.slsb.MockHome;
  -import org.openejb.slsb.MockLocal;
  -import org.openejb.slsb.MockLocalHome;
  -import org.openejb.slsb.MockRemote;
   import org.openejb.transaction.ContainerPolicy;
   import org.openejb.transaction.TransactionPolicy;
   import org.openejb.transaction.TransactionPolicySource;
  @@ -126,7 +120,7 @@
           }
           try {
               home.remove(new Handle() {
  -                public EJBObject getEJBObject() throws RemoteException {
  +                public EJBObject getEJBObject() {
                       return null;
                   }
               });
  @@ -140,6 +134,30 @@
           }
       }
   
  +    public MockEJB mockEJB1;
  +    public MockEJB mockEJB2;
  +
  +    public void testRemove() throws Throwable {
  +        MockLocalHome home = (MockLocalHome) container.getEJBLocalHome();
  +        final MockLocal mock1 = home.create();
  +        Thread waiter = new Thread("Waiter") {
  +            public void run() {
  +                mockEJB1 = mock1.waitForSecondThread(10000);
  +            }
  +        };
  +        waiter.start();
  +
  +        MockLocal mock2 = home.create();
  +        mockEJB2 = mock2.waitForSecondThread(10000);
  +        waiter.join();
  +
  +        assertTrue("We should have two different EJB instances", mockEJB1 != 
mockEJB2);
  +        assertTrue("ejbCreate should have been called on the first 
instance", mockEJB1.createCalled);
  +        assertTrue("ejbCreate should have been called on the second 
instance", mockEJB2.createCalled);
  +        assertTrue("ejbRemove should have been called on either instance 
since the pool size is one",
  +                mockEJB1.removeCalled || mockEJB2.removeCalled);
  +    }
  +
       public void testLocalHomeInterface() {
           MockLocalHome localHome = (MockLocalHome) 
container.getEJBLocalHome();
           try {
  @@ -228,7 +246,7 @@
               }
           });
           builder.setSecurityConfiguration(new SecurityConfiguration());
  -        builder.setComponentContext(new ReadOnlyContext());
  +        builder.setComponentContext(new HashMap());
           builder.setTransactionContextManager(new 
TransactionContextManager(new MockTransactionManager(), null));
           builder.setTrackedConnectionAssociator(new 
ConnectionTrackingCoordinator());
           container = builder.createContainer();
  
  
  

Reply via email to