Class BMUnitConfigState

java.lang.Object
org.jboss.byteman.contrib.bmunit.BMUnitConfigState

public class BMUnitConfigState extends Object
class used to model a specific BMUnit configuration
  • Field Details

    • currentConfigState

      private static BMUnitConfigState currentConfigState
    • shadowConfigState

      private static BMUnitConfigState shadowConfigState
      a global configuration state used to preserve the configuration associated with a test class should the BMUnitRunner temporarily reconfigure the state for a specific test method.
    • defaultConfigState

      public static BMUnitConfigState defaultConfigState
      a default configuration state used when a test class does not specify a configuration state. this state is initialised using the state associated with the first test class processed during the test run. it is also the state used to define parameters which configure autoload of the Byteman agent.
    • agentHost

      private String agentHost
    • agentPort

      private int agentPort
    • loadDirectory

      private String loadDirectory
    • resourceLoadDirectory

      private String resourceLoadDirectory
    • allowConfigUpdate

      private boolean allowConfigUpdate
    • verbose

      private boolean verbose
    • debug

      private boolean debug
    • bmunitVerbose

      private boolean bmunitVerbose
    • inhibitAgentLoad

      private boolean inhibitAgentLoad
    • policy

      private boolean policy
    • dumpGeneratedClasses

      private boolean dumpGeneratedClasses
    • dumpGeneratedClassesDirectory

      private String dumpGeneratedClassesDirectory
    • dumpGeneratedClassesIntermediate

      private boolean dumpGeneratedClassesIntermediate
    • previous

      private BMUnitConfigState previous
    • LOAD_DIRECTORY

      public static final String LOAD_DIRECTORY
      System property which identifies the directory from which to start searching for rule script. If unset the current working directory of the test is used.
      See Also:
    • RESOURCE_LOAD_DIRECTORY

      public static final String RESOURCE_LOAD_DIRECTORY
      System property which identifies the resource load directory from which to start searching for rule script.
      See Also:
    • AGENT_PORT

      public static final String AGENT_PORT
      System property specifying the port to be used when starting the agent and when submitting rules to it. You can normally just use the default port.
      See Also:
    • AGENT_HOST

      public static final String AGENT_HOST
      System property specifying the host to be used when starting the agent and when submitting rules to it. You can normally just use the default host.
      See Also:
    • AGENT_POLICY

      public static final String AGENT_POLICY
      System property specifying whether to set a security policy when loading the agent.
      See Also:
    • AGENT_INHIBIT

      public static final String AGENT_INHIBIT
      System property which inhibits automatic loading of the agent. If you set this then you have to load the agent yourself using the Install API or ensure JUnit loads by forking a JVM and passing the necessary -javaagent options on the command line. You may also want to set this if you you have loaded the agent into a remote service in another JVM driven by your unit test.
      See Also:
    • AGENT_VERSION

      public static final String AGENT_VERSION
      system property set by the agent to advertise the version of the loaded agent
      See Also:
    • BYTEMAN_ALLOW_CONFIG_UPDATE

      public static final String BYTEMAN_ALLOW_CONFIG_UPDATE
      System property which enables tracing of Byteman activity
      See Also:
    • BYTEMAN_VERBOSE

      public static final String BYTEMAN_VERBOSE
      System property which enables tracing of Byteman activity
      See Also:
    • BYTEMAN_DEBUG

      public static final String BYTEMAN_DEBUG
      System property which enables printing of Byteman rule debug statements
      See Also:
    • BMUNIT_VERBOSE

      public static final String BMUNIT_VERBOSE
      System property which enables tracing of bmunit activity
      See Also:
    • BYTEMAN_DUMP_GENERATED_CLASSES

      public static final String BYTEMAN_DUMP_GENERATED_CLASSES
      System property which enables dumping of generated classes
      See Also:
    • BYTEMAN_DUMP_GENERATED_CLASSES_DIRECTORY

      public static final String BYTEMAN_DUMP_GENERATED_CLASSES_DIRECTORY
      System property which configures directory path for files used for dumping of generated classes
      See Also:
    • BYTEMAN_DUMP_GENERATED_CLASSES_INTERMEDIATE

      public static final String BYTEMAN_DUMP_GENERATED_CLASSES_INTERMEDIATE
      System property which configures dumping of intermediate versions of generated classes
      See Also:
    • VERBOSE

      public static final String VERBOSE
      this is only provided for backward compatibility in case some app was using this constant string to configure the required property.
      See Also:
  • Constructor Details

  • Method Details

    • needPropertyReset

      private static boolean needPropertyReset(BMUnitConfigState newConfigState, BMUnitConfigState oldConfigState)
      helper method to check whether we need to update agent properties when we switch config
      Parameters:
      newConfigState -
      oldConfigState -
      Returns:
    • configurePropertyReset

      private static boolean configurePropertyReset(BMUnitConfigState newConfigState, BMUnitConfigState oldConfigState, Properties props)
      helper method to configure the properties to be reset when a config change occurs
      Parameters:
      newConfigState -
      oldConfigState -
      props -
      Returns:
    • uploadAgentProperties

      private static void uploadAgentProperties() throws Exception
      Throws:
      Exception
    • resetAgentProperties

      private static void resetAgentProperties() throws Exception
      Throws:
      Exception
    • checkBMUnitVersion

      private void checkBMUnitVersion(String agentVersion) throws Exception
      Throws:
      Exception
    • loadAgent

      private void loadAgent() throws Exception
      load the agent into this JVM if not already loaded. unfortunately this can only be done if we have the pid of the current process and we cannot get that in a portable way
      Throws:
      Exception
    • getPid

      private static int getPid()
      return the integer process id of the current process. n.b. only works on Linux.
      Returns:
    • pushConfigurationState

      public static void pushConfigurationState(BMUnitConfig config, Class<?> testClass) throws Exception
      install the configuration for a specific test class, possibly also adopting it as the default configuration this method is not thread-safe. BMUnit assumes that only one JUnit/TestNG test is run at a time.
      Parameters:
      config - the config to install or null if no config is available
      testClass - the test class which may or may not have an associated config
      Throws:
      Exception - if the config cannot be installed or an agent load error occurs
    • popConfigurationState

      public static void popConfigurationState(Class<?> testClass) throws Exception
      Throws:
      Exception
    • pushConfigurationState

      public static void pushConfigurationState(BMUnitConfig config, Method method) throws Exception
      Throws:
      Exception
    • popConfigurationState

      public static void popConfigurationState(Method method) throws Exception
      Throws:
      Exception
    • resetConfigurationState

      public static void resetConfigurationState(Method method) throws Exception
      Throws:
      Exception
    • resetConfigurationState

      public static void resetConfigurationState(Class<?> testClass) throws Exception
      Throws:
      Exception
    • getCurrentConfigState

      public static BMUnitConfigState getCurrentConfigState()
      the global configuration state which configures the operation of BMUnit when running tests in a specific class or a method in that class. this value is set by BMUnitRunner before it starts running the tests in a test class. it may be reset temporarily by BMUnitRunner before executing a specific test method but should then be set back to the previous configuration.
      Returns:
      the current configuration
    • currentConfigState

      public BMUnitConfigState currentConfigState()
    • getHost

      public String getHost()
      getter for currently configured agent host setting
      Returns:
      the current host setting
    • getPort

      public int getPort()
      getter for currently configured agent port setting
      Returns:
      the current port setting
    • getLoadDirectory

      public String getLoadDirectory()
      getter for currently configured load directory setting
      Returns:
      the current load directory setting
    • getResourceLoadDirectory

      public String getResourceLoadDirectory()
      getter for currently configured resource directory setting
      Returns:
      the current resource directory setting
    • isAllowConfigUpdate

      public boolean isAllowConfigUpdate()
      smart getter for currently configured allowAgentConfigUpdate setting which redirects through to the previous config to ensure that we employ the setting used for the initial agent load
      Returns:
      the current allowAgentConfigUpdate setting
    • isVerbose

      public boolean isVerbose()
      smart getter for currently configured Byteman verbose setting which redirects through to the previous config if config updates are not allowed but otherwise returns the currently configured Byteman verbose setting
      Returns:
      the current Byteman verbose setting
    • isDebug

      public boolean isDebug()
      smart getter for currently configured Byteman debug setting which redirects through to the previous config if config updates are not allowed but otherwise returns the currently configured Byteman debug setting
      Returns:
      the current Byteman debug setting
    • isBMUnitVerbose

      public boolean isBMUnitVerbose()
      getter for currently configured BMUnit verbose setting
      Returns:
      the current BMUnit verbose setting
    • isInhibitAgentLoad

      public boolean isInhibitAgentLoad()
      smart getter for currently configured inhibitAgentLoad setting which redirects through to the previous config to ensure that we employ the setting used for the initial agent load
      Returns:
      the current inhibitAgentLoad setting
    • isPolicy

      public boolean isPolicy()
      smart getter for currently configured policy setting which redirects through to the previous config to ensure that we employ the setting used for the initial agent load
      Returns:
      the current policy setting
    • isDumpGeneratedClasses

      public boolean isDumpGeneratedClasses()
      getter for current dumpGeneratedClasses setting
      Returns:
      the current dumpGeneratedClasses setting
    • getDumpGeneratedClassesDirectory

      public String getDumpGeneratedClassesDirectory()
      smart getter for current dumpGeneratedClassesDirectory setting which only returns a directory when dumpGeneratedClasses is set in which case it uses any current setting but delegates to previous if no value has been set.
      Returns:
      the current dumpGeneratedClasseDirectory setting
    • isDumpGeneratedClassesIntermediate

      public boolean isDumpGeneratedClassesIntermediate()
      smart getter for current dumpGeneratedClassesIntermediate setting which only returns the attribute setting if dumpGeneratedClasses has also been set.
      Returns:
      the current dumpGeneratedClassesIntermediate
    • initHost

      private static String initHost()
      return the String configured for the agent host or null if it was not configured
      Returns:
      the iniital agent host
    • initPort

      private static int initPort()
      return the integer port configured for the agent port or 0 if it was not configured or was misconfigured
      Returns:
      the initial agent port
    • initDefaultLoadDirectory

      private static String initDefaultLoadDirectory()
      computes the default load directory from system property org.jboss.byteman.contrib.bmunit.load.directory or defaults it to ""
      Returns:
      the initial load directory
    • initDefaultResourceLoadDirectory

      private static String initDefaultResourceLoadDirectory()
      computes the default resource load directory from system property org.jboss.byteman.contrib.bmunit.resource.load.directory or defaults it to the load directory
      Returns:
      the initial resource load directory
    • initVerbose

      private static boolean initVerbose()
    • initDebug

      private static boolean initDebug()
    • initBMUnitVerbose

      private static boolean initBMUnitVerbose()
    • initPolicy

      private static boolean initPolicy()
      test whether a security policy should be set for agent code when the agent is installed
      Returns:
      the initial policy setting
    • initDumpGeneratedClasses

      private static boolean initDumpGeneratedClasses()
    • initDumpGeneratedClassesDirectory

      private static String initDumpGeneratedClassesDirectory()
    • initDumpGeneratedClassesIntermediate

      private static boolean initDumpGeneratedClassesIntermediate()