9 Replies Latest reply on Mar 20, 2009 11:33 AM by mazz

    Problem with running plugin unittest

    Carl Abramsson Newbie

      Hello!

      I'm working on a custom plugin. I've got it setup like this:

      <plugin name="MyJmxBasedPlugin"
       displayName="MyJmxBasedPlugin Services"
       package="org.rhq.plugins.myplugin"
       description="Provides monitoring of MyJmxBasedPlugin"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="urn:xmlns:rhq-plugin"
       xmlns:c="urn:xmlns:rhq-configuration">
      
       <depends plugin="JMX" />
       <depends plugin="Tomcat" />
      ....
      


      When I run the unittests (with maven2) i get this exception:

      11:41:44,996 INFO [JMXServerComponent] Starting connection to JMX Server 9980
      11:41:44,996 WARN [JMXServerComponent] JMX Plugin connection failure
      org.mc4j.ems.connection.EmsException: Unable to make temporary file store
       at org.mc4j.ems.connection.support.classloader.ClassLoaderFactory.storeImplToTemp(ClassLoaderFactory.java:109)
       at org.mc4j.ems.connection.support.classloader.ClassLoaderFactory.buildClassLoader(ClassLoaderFactory.java:202)
       at org.mc4j.ems.connection.ConnectionFactory.getConnectionProvider(ConnectionFactory.java:120)
       at org.rhq.plugins.jmx.JMXServerComponent.prepareConnection(JMXServerComponent.java:190)
       at org.rhq.plugins.jmx.JMXServerComponent.internalStart(JMXServerComponent.java:138)
       at org.rhq.plugins.jmx.JMXServerComponent.start(JMXServerComponent.java:77)
       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.rhq.core.pc.inventory.ResourceContainer$ComponentInvocationThread.call(ResourceContainer.java:449)
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
       at java.util.concurrent.FutureTask.run(FutureTask.java:138)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
       at java.lang.Thread.run(Thread.java:619)
      Caused by: java.io.IOException: The system cannot find the path specified
       at java.io.WinNTFileSystem.createFileExclusively(Native Method)
       at java.io.File.checkAndCreate(File.java:1704)
       at java.io.File.createTempFile(File.java:1792)
       at org.mc4j.ems.connection.support.classloader.ClassLoaderFactory.copyFileToTemp(ClassLoaderFactory.java:117)
       at org.mc4j.ems.connection.support.classloader.ClassLoaderFactory.storeImplToTemp(ClassLoaderFactory.java:100)
       ... 15 more
      11:41:45,011 WARN [JMXServerComponent] Unable to connect to JMX Server 9980
      


      It seems like it has something to do with the mc4j.ems.JarTempDir property in org.mc4j.ems.connection.support.classloader.ClassLoaderFactory



      I'm running this on a winxp-box with
      mvn -Pdev -Drhq.containerDir=C:\a\jopr-server-2.2.0.Beta1 -Djava.io.tempdir=C:\temp install

      ...in my custom plugin dir that sits beside the other jopr-plugins. The jopr source I've got checked out is the trunk.

      Anyone else that have had this problem?

        • 1. Re: Problem with running plugin unittest
          Greg Hinkle Newbie

          Looks like EMS needs to be a bit more tolerant, but its expecting be handed a temporary directory (an apparently not falling back to the java io temp). You can set it with the following or disable copying the files to temp in the first place.



          connectionSettings.getControlProperties().
           setProperty(ConnectionFactory.COPY_JARS_TO_TEMP,
           String.valueOf(Boolean.FALSE));
          
          OR
          
          connectionSettings.getControlProperties().
           setProperty(ConnectionFactory.JAR_TEMP_DIR,
           "<SomePathThatExists>");
          
          
          


          • 2. Re: Problem with running plugin unittest
            mazz Master

            When running inside the agent, sometimes we set up the EMS temp directory to be the agent's data/tmp directory. Its possible you didn't override that default and you do not have a "data" directory - thus it can't create the "tmp" directory since the "data" directory is missing.

            • 3. Re: Problem with running plugin unittest
              Carl Abramsson Newbie

              Tnx for the reply, but I can't figure this out... :(

              I've tried to set temp and/or data dirs like this:

              @BeforeSuite
               public void start()
               {
               try
               {
               File pluginDir = new File("target/itest/plugins");
               PluginContainerConfiguration pcConfig = new PluginContainerConfiguration();
               pcConfig.setPluginFinder(new FileSystemPluginFinder(pluginDir));
               pcConfig.setPluginDirectory(pluginDir);
               pcConfig.setDataDirectory( new File("target/itest/plugins"));
               pcConfig.setTemporaryDirectory( new File("target/itest/plugins"));
              
               pcConfig.setInsideAgent(false);
               PluginContainer.getInstance().setConfiguration(pcConfig);
               PluginContainer.getInstance().initialize();
               log.info("PC started.");
              
               for (String plugin : PluginContainer.getInstance().getPluginManager().getMetadataManager().getPluginNames()) {
               log.info("...Loaded plugin: " + plugin);
               }
               }
               catch (Exception e)
               {
               e.printStackTrace();
               }
               }
              


              ...but that only makes the tests fail without any plugins loaded at all.

              I have the exact some error with the hibernate-plugin test.

              • 4. Re: Problem with running plugin unittest
                mazz Master

                What if, in that test class you have there, you try to create a file in that temporary directory? I'd be curious to know if something is causing Java in general from failing to create and write files there?

                • 5. Re: Problem with running plugin unittest
                  Greg Hinkle Newbie

                  EMS does not respect the agent's temp directory settings either. It only respects what you directly tell it via the code example I gave above.

                  • 6. Re: Problem with running plugin unittest
                    mazz Master

                    I was assuming he was extending the JMX plugin, which DOES respect those settings (the JMX components will set the EMS temp location to the same place where the PC has its temp directory - see JMXServerComponent.prepareConnection()).

                    Now, if your custom plugin is creating its OWN connections via EMS, then yes you need to do what Greg is saying to do in your own code.

                    • 7. Re: Problem with running plugin unittest
                      mazz Master

                      Looking at the exception posted in this thread, my assumption was correct - the JMX plugin is being utilized:

                      11:41:44,996 WARN [JMXServerComponent] JMX Plugin connection failure
                      org.mc4j.ems.connection.EmsException: Unable to make temporary file store
                       at org.mc4j.ems.connection.support.classloader.ClassLoaderFactory.storeImplToTemp(ClassLoade
                      rFactory.java:109)
                       at org.mc4j.ems.connection.support.classloader.ClassLoaderFactory.buildClassLoader(ClassLoad
                      erFactory.java:202)
                       at org.mc4j.ems.connection.ConnectionFactory.getConnectionProvider(ConnectionFactory.java:12
                      0)
                       at org.rhq.plugins.jmx.JMXServerComponent.prepareConnection(JMXServerComponent.java:190)
                      


                      • 8. Re: Problem with running plugin unittest
                        Carl Abramsson Newbie

                        Yes, and as I said. I have the exact some problem with the jopr hibernate plug-in in svn.

                        The JVM can create files under the tmp dir, so that is not it...

                        • 9. Re: Problem with running plugin unittest
                          mazz Master

                          I'm not sure what debugging messages EMS will emit - try to set the log4j category org.mc4j to DEBUG and see if any more info is logged.

                          Also, can you attach a debugger at that spot and find out why its failing? You probably have to look at the connection object and the settings on it to see what directory its trying to create.

                          If you are using the normal RHQ maven setup, you just have to run mvn with "-Dtest.debug" command line option, we'll start the unit tests with JPDA enabled listening on port 8797.