4 Replies Latest reply: Sep 16, 2010 6:34 AM by 807581 RSS

    OpenMQ embedded broker in Maven JUnit

    807581
      I have standalone application wich interacts with OpenMQ through JMS. Maven build tool is used. I want to write JUnit tests checking application interaction with OpenMQ. For this purpose I want to use OpenMQ embedded broker. I found https://mq.dev.java.net/4.4-content/embedded-example.html guide. With minor changes I implemented embedded broker. But it's not work as described in guide.
      At first it appear to me that it cann't create necessary directories and I've added
      new File("target/openmq/var/instances/imqbroker").mkdirs();
      but later I understood that for some reason it's not creating directories and files which should create itself.
      I browsed the sources code and found, that Broker.start() method return value ignored during embedded broker creation. It seems to be a bug.
      I receive broker event 'READY : Broker has been started' but actually it don't starts and jms port 7676 close.

      Please, look at my code and tell me what's wrong with it?

      Application can be downloaded from this thread: http://forums.java.net/jive/thread.jspa?messageID=482904&#482904 .
      Direct link: http://forums.java.net/jive/servlet/JiveServlet/download/56-153207-482904-13987/openmqtest.zip
      To start build process put libraries defined in lib/dir.txt from OpenMQ distribution to project lib directory. Then use
      mvn clean package

      Here is the output:


      Running bulatnig.openmqtest.EmbeddedBrokerTest
      [16/сен/2010:09:04:03 MSD] WARNING [B2001]: Unable to load default property file /home/bulat/IdeaProjects/glassjmstest/openmqtest/target/openmq/lib/props/broker/default.properties:
      java.io.FileNotFoundException: /home/bulat/IdeaProjects/glassjmstest/openmqtest/target/openmq/lib/props/broker/default.properties (No such file or directory)
      [16/сен/2010:09:04:03 MSD] ERROR [B3001]: Defaulting to use the fallback properties. The Broker will only run in a minimal configuration using these settings. Fallback properties are being used because the defaults.property files could not be loaded. Please check the value of IMQ_HOME
      [16/сен/2010:09:04:03 MSD]
      ================================================================================
      Open Message Queue 4.5
      Oracle
      Version: 4.5 (Build 10-f)
      Compile: Wed Jun 16 23:23:56 PDT 2010

      Copyright (c) 2010 Sun Microsystems, Inc. All rights reserved. Use is
      subject to license terms.
      ================================================================================
      Java Runtime: 1.6.0_20 Sun Microsystems Inc. /usr/lib/jvm/java-6-sun-1.6.0.20/jre
      [16/сен/2010:09:04:03 MSD] IMQ_HOME=/home/bulat/IdeaProjects/glassjmstest/openmqtest/target/openmq
      [16/сен/2010:09:04:03 MSD] IMQ_VARHOME=/home/bulat/IdeaProjects/glassjmstest/openmqtest/target/openmq/var
      [16/сен/2010:09:04:03 MSD] Linux 2.6.32-24-generic amd64 nigmatullin (2 cpu) bulat
      [16/сен/2010:09:04:03 MSD] Java Heap Size: max=449664k, current=30336k
      [16/сен/2010:09:04:03 MSD] Arguments: -imqhome target/openmq
      [16/сен/2010:09:04:03 MSD] Embedded Broker
      [16/сен/2010:09:04:03 MSD] ERROR [B3086]: The broker got an exception when trying to acquire the lock file:
      null/instances/imqbroker/lock
      java.io.IOException: No such file or directory
      The lock file may be corrupted, or there may be a permission problem
      with the lock file or the directory that contains the lock file.
      If you are certain no other copy of the broker is running with the
      instance name "imqbroker" then you may remove the lock file and
      try starting the broker again.:
      java.io.IOException: No such file or directory
           at java.io.UnixFileSystem.createFileExclusively(Native Method)
           at java.io.File.createNewFile(File.java:883)
           at com.sun.messaging.jmq.jmsserver.util.LockFile.getLock(LockFile.java:113)
           at com.sun.messaging.jmq.jmsserver.Broker._start(Broker.java:798)
           at com.sun.messaging.jmq.jmsserver.Broker.start(Broker.java:412)
           at com.sun.messaging.jmq.jmsserver.BrokerProcess.start(BrokerProcess.java:219)
           at com.sun.messaging.jmq.jmsserver.DirectBrokerProcess.start(DirectBrokerProcess.java:87)
           at com.sun.messaging.jmq.jmsclient.runtime.impl.BrokerInstanceImpl.start(BrokerInstanceImpl.java:144)
           at bulatnig.openmqtest.EmbeddedBrokerTest.startServer(EmbeddedBrokerTest.java:50)
           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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
           at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
           at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
           at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
           at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
           at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
           at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
           at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
           at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
           at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
           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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
           at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
      Received broker event:READY : Broker has been started

      Edited by: bulatka on Sep 15, 2010 10:37 PM
        • 1. Re: OpenMQ embedded broker in Maven JUnit
          805009
          The product documentation for this feature is here:

          [http://docs.sun.com/app/docs/doc/821-1796/gjmtl?l=en&n=1&a=view|http://docs.sun.com/app/docs/doc/821-1796/gjmtl?l=en&n=1&a=view]

          Did you set the -imqhome, -libhome and -varhome arguments to the embedded broker? The errors you report suggest that these are not correctly configured.

          Nigel
          • 2. Re: OpenMQ embedded broker in Maven JUnit
            807581
            I changed arguments to:
            -imqhome target/openmq -libhome /home/bulat/desktop/MessageQueue4_4/mq/lib

            Build Failed:

            <testcase time="0" classname="bulatnig.openmqtest.EmbeddedBrokerTest" name="bulatnig.openmqtest.EmbeddedBrokerTest">
            <error message="com/sun/messaging/jms/management/server/ClusterNotification" type="java.lang.NoClassDefFoundError">java.lang.NoClassDefFoundError: com/sun/messaging/jms/management/server/ClusterNotification
            at com.sun.messaging.jmq.jmsserver.management.agent.Agent.loadAllMBeans(Agent.java:671)
            at com.sun.messaging.jmq.jmsserver.management.agent.Agent.loadMBeans(Agent.java:628)
            at com.sun.messaging.jmq.jmsserver.Broker._start(Broker.java:1385)
            at com.sun.messaging.jmq.jmsserver.Broker.start(Broker.java:412)
            at com.sun.messaging.jmq.jmsserver.BrokerProcess.start(BrokerProcess.java:219)
            at com.sun.messaging.jmq.jmsserver.DirectBrokerProcess.start(DirectBrokerProcess.java:87)
            at com.sun.messaging.jmq.jmsclient.runtime.impl.BrokerInstanceImpl.start(BrokerInstanceImpl.java:144)
            at bulatnig.openmqtest.EmbeddedBrokerTest.startServer(EmbeddedBrokerTest.java:50)
            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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
            at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
            at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
            at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
            at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
            at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
            at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
            at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
            at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
            at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
            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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
            at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
            Caused by: java.lang.ClassNotFoundException: com.sun.messaging.jms.management.server.ClusterNotification
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
            ... 28 more
            </error>
            </testcase>

            I added imqjmx to project dependencies: project builds without errors.

            The next question: is it possible start embedded broker without OpenMQ locally installed? Which libraries should I put in dependencies to run embedded broker in JUnit tests?
            • 3. Re: OpenMQ embedded broker in Maven JUnit
              807581
              I solved this problem. Thanks to Nigel aka nigeldeakin.

              I just added -libhome target/openmq/lib arguments and put props folder from OpenMQ distribution to target/openmq/lib.

              Working sample http://forums.java.net/jive/servlet/JiveServlet/download/56-153207-482943-13989/openmqtest.zip .
              • 4. Re: OpenMQ embedded broker in Maven JUnit
                805009
                As you suspected, an embedded broker requires a MQ installation to be available. There are a few files it doesn't need, such as the executables in the bin directory, and the .war files in the lib directory, but there's no formal list.