2 Replies Latest reply on Apr 30, 2008 3:35 PM by Louie Liu

    Bootstrap.undeploy doesn't work properly

    gumnaam suri Newbie

      I have a test case that extends from jboss's BaseTestCase

      Here's the code for the deploy and undeploy methods.

       private static AssembledDirectory jar;
      
       public static void deploy() {
       jar = AssembledContextFactory.getInstance().create("ejbTestCase.jar");
       jar.addResources(EchoServiceLocal.class, new String[]{"**/*.class"}, new String[]);
      
       try {
       Bootstrap.getInstance().deploy(jar);
       } catch (DeploymentException e) {
       e.printStackTrace();
       throw new RuntimeException("Unable to deploy", e);
       }
       }
      
       public static void undeploy() {
       try {
       Bootstrap.getInstance().undeploy(jar);
       AssembledContextFactory.getInstance().remove(jar);
      
       } catch (DeploymentException e) {
       e.printStackTrace();
       throw new RuntimeException("Unable to undeploy", e);
       }
      
      


      This works correctly only if I have one single test method in my class.
      If I have 2+ methods, The deploy/undeploy get called before and after each test. But the ejb's are never undeployed by the call to

      Bootstrap.getInstance().undeploy(jar);

      So when the deploy() method is called for the second test method I get the following exception

      ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Real: name=vfs://12067092458921/ state=PostClassLoader mode=Manual requiredState=Real
      org.jboss.deployers.spi.DeploymentException: Error deploying ejbTestCase.jar: Error creating ejb container EchoService: Container jboss.j2ee:jar=ejbTestCase.jar,name=EchoService,service=EJB3,VMID=b3b0ab650f4bdfe2:-1951e759:118f579d2d3:-8000 + is already registered
       at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:158)
       at org.jboss.ejb3.deployers.Ejb3Deployer.deploy(Ejb3Deployer.java:88)
       at org.jboss.deployers.vfs.spi.deployer.AbstractVFSRealDeployer.internalDeploy(AbstractVFSRealDeployer.java:45)
       at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
       at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:853)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:794)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:327)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:622)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:411)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:498)
       at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:506)
       at org.jboss.embedded.DeploymentGroup.process(DeploymentGroup.java:127)
       at org.jboss.embedded.Bootstrap.deploy(Bootstrap.java:327)
       at com.cybertrust.ejbtest.ejb.EchoServiceLocalTest.deploy(EchoServiceLocalTest.java:43)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.jboss.embedded.junit.BaseTestCase.setUp(BaseTestCase.java:70)
      


        • 1. Re: Bootstrap.undeploy doesn't work properly
          gumnaam suri Newbie

          Actually this is a 2 fold problem.

          I am using maven-surefire-plugin to run the tests.
          And somehow it completely ignores the static "suite" method.
          So the deploy/undeploy methods get called before/after every test method.

          But the fact remains that the Bootstrap.getInstance().undeploy(jar) doesn't cause the EJB3 deployer to undeploy the ejbs.

          • 2. Re: Bootstrap.undeploy doesn't work properly
            Louie Liu Newbie

            Hello,

            Thanks for your information on how to fix the issue with the jdk1.6. I am trying to use this embedded jboss testing my EJB3 session bean. I would like to know if you have any success on EJB3 unit testing. If so, I wonder if you can share your configuration information.

            Here is my setup: maven2.0.8 + jdk1.6+embeded beta3


             <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <version>2.4.2</version>
             <configuration>
             <!-- for JDK6 Support -->
             <argLine>-Dsun.lang.ClassLoader.allowArraySyntax=true</argLine>
             </configuration>
             </plugin>
            


            My dependents:

            
            <dependency>
             <groupId>org.testng</groupId>
             <artifactId>testng</artifactId>
             <classifier>jdk15</classifier>
             <version>5.7</version>
             <scope>test</scope>
             </dependency>
             <dependency>
             <groupId>jboss</groupId>
             <artifactId>jboss-annotations-ejb3</artifactId>
             <version>4.2.2.GA</version>
             <scope>test</scope>
             </dependency>
             <dependency>
             <groupId>org.jboss.seam.embedded</groupId>
             <artifactId>hibernate-all</artifactId>
             <version>beta3</version>
             <scope>test</scope>
             </dependency>
             <dependency>
             <groupId>org.jboss.seam.embedded</groupId>
             <artifactId>jboss-embedded-all</artifactId>
             <version>beta3</version>
             <scope>test</scope>
             </dependency>
             <dependency>
             <groupId>org.jboss.seam.embedded</groupId>
             <artifactId>thirdparty-all</artifactId>
             <version>beta3</version>
             <scope>test</scope>
             </dependency>
             <dependency>
             <groupId>javax.mail</groupId>
             <artifactId>mail</artifactId>
             <version>1.4</version>
             <scope>test</scope>
             </dependency>
             <dependency>
             <groupId>com.oracle</groupId>
             <artifactId>ojdbc14</artifactId>
             <version>10.2.0.2.0</version>
             <scope>test</scope>
             </dependency>
            


            My code:

            
             @BeforeTest
             protected void startup() {
             if (globalSetup) {
             return;
             }
             try {
             Bootstrap.getInstance().bootstrap();
             deploy();
             } catch (DeploymentException e) {
             e.printStackTrace();
             }
            
             }
            
             @AfterTest
             protected void shutdown() {
             if (globalSetup) {
             return;
             }
             undeploy();
             }
            
             private void deploy() {
             jar = AssembledContextFactory.getInstance().create("ejbTest.jar");
             jar.addClass(BusinessCalendar.class);
             jar.addClass(BusinessCalendarDate.class);
             jar.addClass(CalendarService.class);
             jar.addClass(CalendarServiceSessionBean.class);
             jar.addClass(Holiday.class);
             jar.addClass(HolidayCalendar.class);
             jar.addClass(HolidayHandlerType.class);
             jar.mkdir("META-INF").addResource("testPersistence.xml", "persistence.xml");
             try {
             Bootstrap.getInstance().deploy(jar);
             } catch (DeploymentException e) {
             e.fillInStackTrace();
             throw new RuntimeException("Unable to deploy", e);
             }
             }
            
             private static void undeploy() {
             try {
             Bootstrap.getInstance().undeploy(jar);
             AssembledContextFactory.getInstance().remove(jar);
             } catch (DeploymentException e) {
             throw new RuntimeException("Unable to undeploy", e);
             }
             }
            


            Thanks for your help.