Announcement Announcement Module
Collapse

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
Using spring dm for JUnit tests invoked from JMeter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using spring dm for JUnit tests invoked from JMeter

    Hi,

    I'm working on application which client is an Eclipse RCP application.
    Now I need to create series of load tests. I'm using JMeter 2.3.4 which invokes JUnit tests. In order to JMeter 'see' JUnit test classes and methods all my bundles jars are located in jmeter/lib/junit folder, there are also all supporting libraries in this folder.

    I was able to run spring dm test examples successfully. I created class OsgiHelper which extends AbstractConfigurableBundleCreatorTests. But when I try to run simple JMeter script which just invokes my method OsgiHelper.testInit(), then this.bundleContext is null and call to getApplicationContext() fails as follows:

    Code:
    DEBUG 02/17, 02:50:46 [AWT-EventQueue-0] atchingResourcePatternResolver Found Equinox FileLocator for OSGi bundle URL resolution
    INFO  02/17, 02:50:46 [AWT-EventQueue-0] a.osgi.testfacade.JMeterHelper params: cz.bsc.g6.components.base.gba.osgi.testfacade.OsgiHelper
    INFO  02/17, 02:50:46 [AWT-EventQueue-0] a.osgi.testfacade.JMeterHelper params: cz.bsc.g6.components.base.gba.osgi.testfacade.OsgiHelper
    INFO  02/17, 02:50:46 [AWT-EventQueue-0] a.osgi.testfacade.JMeterHelper params: cz.bsc.g6.components.base.gba.osgi.testfacade.OsgiHelper
    INFO  02/17, 02:50:46 [AWT-EventQueue-0] a.osgi.testfacade.JMeterHelper params: cz.bsc.g6.components.base.gba.osgi.testfacade.OsgiHelper
    INFO  02/17, 02:50:48 [MainGroup 1-1] a.osgi.testfacade.JMeterHelper params: app.server.url=http://localhost:9080/gba;catalogs.baseDirectory=C:\catalogServiceRootDirectory;kladr.baseDirectory=C:\kladrServiceRootDirectory
    INFO  02/17, 02:50:48 [MainGroup 1-1] a.osgi.testfacade.JMeterHelper app.server.url=http://localhost:9080/gba
    INFO  02/17, 02:50:48 [MainGroup 1-1] a.osgi.testfacade.JMeterHelper catalogs.baseDirectory=C:\catalogServiceRootDirectory
    INFO  02/17, 02:50:48 [MainGroup 1-1] a.osgi.testfacade.JMeterHelper kladr.baseDirectory=C:\kladrServiceRootDirectory
    INFO  02/17, 02:50:48 [MainGroup 1-1] gba.osgi.testfacade.OsgiHelper testInit invoked ------------------------------------------
    INFO  02/17, 02:50:48 [MainGroup 1-1] gba.osgi.testfacade.OsgiHelper bundleContext: null
    INFO  02/17, 02:50:48 [MainGroup 1-1] gba.osgi.testfacade.OsgiHelper Loading context for locations: /META-INF/spring/osgi.xml
    DEBUG 02/17, 02:50:48 [MainGroup 1-1] gba.osgi.testfacade.OsgiHelper Caught exception while retrieving the ApplicationContext for test [cz.bsc.g6.components.base.gba.osgi.testfacade.OsgiHelper.testInit].
    java.lang.NullPointerException
    	at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.setBundleContext(AbstractOsgiBundleApplicationContext.java:157)
    	at org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests.createApplicationContext(AbstractOptionalDependencyInjectionTests.java:106)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:189)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:169)
    	at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:140)
    	at org.springframework.test.AbstractSingleSpringContextTests.getApplicationContext(AbstractSingleSpringContextTests.java:338)
    	at cz.bsc.g6.components.base.gba.osgi.testfacade.OsgiHelper.testInit(OsgiHelper.java:29)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.apache.jmeter.protocol.java.sampler.JUnitSampler$1.protect(JUnitSampler.java:360)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at org.apache.jmeter.protocol.java.sampler.JUnitSampler.sample(JUnitSampler.java:363)
    	at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:346)
    	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:243)
    	at java.lang.Thread.run(Unknown Source)
    INFO  02/17, 02:50:48 [MainGroup 1-1] gba.osgi.testfacade.OsgiHelper ------------------------------------------ testInit ended
    INFO  02/17, 02:50:48 [MainGroup 1-1] a.osgi.testfacade.JMeterHelper params: org.apache.jmeter.protocol.java.sampler.JUnitSampler
    INFO  02/17, 02:50:48 [MainGroup 1-1] gba.osgi.testfacade.OsgiHelper testCleanup invoked ------------------------------------------
    INFO  02/17, 02:50:48 [MainGroup 1-1] gba.osgi.testfacade.OsgiHelper ------------------------------------------ testCleanup ended
    Here is class OsgiHelper:

    Code:
    package cz.bsc.g6.components.base.gba.osgi.testfacade;
    
    import java.util.Map;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.context.ApplicationContext;
    import org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests;
    
    public class OsgiHelper extends AbstractConfigurableBundleCreatorTests {
      protected Logger logger = LoggerFactory.getLogger(getClass());
    
      private Map<String, String> parameters;
    
      public OsgiHelper(String params) {
        parameters = JMeterHelper.parseParameters(params);
      }
    
      @Override
      protected String[] getConfigLocations() {
        return new String[] { "/META-INF/spring/osgi.xml"};
      }
    
      public void testInit() {
        logger.info("testInit invoked ------------------------------------------");
    
        logger.info("bundleContext: " + bundleContext);
        
        ApplicationContext applicationContext = getApplicationContext();
      
        logger.info("------------------------------------------ testInit ended");
      }
    
      public void testCleanup() {
        logger.info("testCleanup invoked ------------------------------------------");
        try {
          tearDown();
        } catch (Throwable t) {
          logger.error(JMeterHelper.getStackTrace(t));
        }
        logger.info("------------------------------------------ testCleanup ended");
      }
    }
    Any help appreciated, thanx in forward, Vladimir.

  • #2
    Most likely, the OSGi tests are not ran properly - if you look at the sources, you'll notice that the base class (AbstractOsgiTest) overrides JUnit's runBare() so that the OSGi platform is started and cached and the junit test itself wrapped and deployed in the platform.
    The NPE is usually a sign that this step hasn't been executed and thus the platform wasn't started (and such, no BundleContext injected).

    Comment

    Working...
    X