Class JMXProfilerTestUtil

java.lang.Object
calibration.java.mx.JMXProfilerTestUtil

public final class JMXProfilerTestUtil extends Object
The Class JMXProfiler4UnitTest

Invoked when a JMX notification occurs. Receive JMX notification

Example use of JMXProfilerTestUtil in a JUnit Test Case - angular.domain.test.ServiceModelJUnitTest - with AspectJ MXBeans Attributes Configurations [using Java MX Calibration Framework API] =>

 
 public class ServiceModel_UnitTest 
 { 
 /**    AOP Profiling Configuration from META-INF/profile.xml:
 *      <aspectj> 
 *      	<aspects> 
 *      		<concrete-aspect name="ServiceModelProfiler" extends="calibration.java.mx.ProfilerAspect"> 
 *      		<pointcut expression="execution(* angular.domain.ServiceModel.getEcho(..))" /> 
 *      		</concrete-aspect> 
 *      	</aspects> 
 *      	<weaver> 
 *      		<include within="angular.domain.ServiceModel" /> 
 *      	</weaver> 
 *      </aspectj> 
 */
 
 final Logger logger = Logger.getLogger(getClass().getCanonicalName());
  
 private final String CONCRETE_ASPECT_NAME = "ServiceModelProfiler";
 private final String POINTCUT_EXPRESSION = "ServiceModel.getEcho";
 private final long METHOD_ALLOCATED_BYTES_BENCHMARK = 1570L;

 /** The service model.  */ 
 private final angular.domain.ServiceModel serviceModel = new ServiceModel();
 /** The echo. */ 
 private final static String ECHO = "echo";
 
 /** Sets the up. */
 @org.junit.Before 
 public void setUp() {
        serviceModel.setEcho(ECHO);
        JMXProfilerTestUtil.install(CONCRETE_ASPECT_NAME,POINTCUT_EXPRESSION,METHOD_ALLOCATED_BYTES_BENCHMARK);
 }

 @org.junit.After 
 public void uninstall() {
        JMXProfilerTestUtil.uninstall(CONCRETE_ASPECT_NAME,POINTCUT_EXPRESSION);
 }
        
 /**Profile service model.
  * @throws InstanceNotFoundException
  *            the instance not found exception
  * @throws MalformedObjectNameException
  *            the malformed object name exception
  * @throws AttributeNotFoundException
  *            the attribute not found exception
  * @throws ReflectionException
  *            the reflection exception
  * @throws MBeanException
  *            the m bean exception
  * @throws NullPointerException
  *            the null pointer exception
  * @throws IOException
  *            Signals that an I/O exception has occurred.
  * @throws InterruptedException
  * @throws NotCompliantMBeanException 
  * @throws InstanceAlreadyExistsException 
  */
  @org.junit.Test 
  public void profileServiceModel() {
        logger.log(Level.INFO, "\n>>> Start Test: serviceModel.getEcho() <<<\n");
        /** FUNCTIONAL JUnit Method Testing */ 
        assertEquals(ECHO, serviceModel.getEcho());
        logger.log(Level.INFO, "\n>>> End Test: serviceModel.getEcho() <<<\n");
 }
 } 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Logger
    The Constant LOGGER.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    install(String CONCRETE_ASPECT_NAME, String POINTCUT_EXPRESSION, Long attributeOldValue)
    Instantiates a new JMX profiler test util.
    static void
    uninstall(String CONCRETE_ASPECT_NAME, String POINTCUT_EXPRESSION)
    Removes the NotificationListener from the registered Profiler MBean.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOGGER

      static final Logger LOGGER
      The Constant LOGGER.
  • Constructor Details

    • JMXProfilerTestUtil

      public JMXProfilerTestUtil()
  • Method Details

    • uninstall

      public static void uninstall(String CONCRETE_ASPECT_NAME, String POINTCUT_EXPRESSION)
      Removes the NotificationListener from the registered Profiler MBean.
      Parameters:
      CONCRETE_ASPECT_NAME - the concrete aspect name
      POINTCUT_EXPRESSION - the pointcut expression
    • install

      public static void install(String CONCRETE_ASPECT_NAME, String POINTCUT_EXPRESSION, Long attributeOldValue) throws AssertionError
      Instantiates a new JMX profiler test util.

      Construct an object name from: "CONCRETE_ASPECT_NAME:type=POINTCUT_EXPRESSION".

      Then Registers a pre-existing object as an MBean with the MBeanserver or a ObjectInstance of ThreadProfiler for the given MBean is registered with the MBean server.

      If the constructor successfully registers an MBean, a notification is sent. Then adds a listener to a registered MBean. Notifications emitted by the MBean will be forwarded to this listener and are implemented in method handleNotification.

      Set the following Java VM arguments in your environment at JVM start:
      --add-opens java.base/java.lang=ALL-UNNAMED (no use in AspectJ 1.9.21.1 and JRE 16+)
      -javaagent:C:/Users/tmerten/.m2/repository/org/aspectj/aspectjweaver/1.9.24/aspectjweaver-1.9.24.jar
      -Dorg.aspectj.weaver.loadtime.configuration=META-INF/profile.xml
      -Dcalibration.java.mx=JMX
      -Dcalibration.java.mx.log
      -Dorg.aspectj.tracing.debug=true
      -Dorg.aspectj.tracing.enabled=true

      Parameters:
      CONCRETE_ASPECT_NAME - the concrete aspect name
      POINTCUT_EXPRESSION - the pointcut expression
      attributeOldValue - the attribute old value
      Throws:
      AssertionError - the assertion error