Package org.jboss.byteman.contrib.bmunit
Class BMUnitConfigState
- java.lang.Object
-
- org.jboss.byteman.contrib.bmunit.BMUnitConfigState
-
public class BMUnitConfigState extends java.lang.Object
class used to model a specific BMUnit configuration
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
AGENT_HOST
System property specifying the host to be used when starting the agent and when submitting rules to it.static java.lang.String
AGENT_INHIBIT
System property which inhibits automatic loading of the agent.static java.lang.String
AGENT_POLICY
System property specifying whether to set a security policy when loading the agent.static java.lang.String
AGENT_PORT
System property specifying the port to be used when starting the agent and when submitting rules to it.static java.lang.String
AGENT_VERSION
system property set by the agent to advertise the version of the loaded agentprivate java.lang.String
agentHost
private int
agentPort
private boolean
allowConfigUpdate
static java.lang.String
BMUNIT_VERBOSE
System property which enables tracing of bmunit activityprivate boolean
bmunitVerbose
static java.lang.String
BYTEMAN_ALLOW_CONFIG_UPDATE
System property which enables tracing of Byteman activitystatic java.lang.String
BYTEMAN_DEBUG
System property which enables printing of Byteman rule debug statementsstatic java.lang.String
BYTEMAN_DUMP_GENERATED_CLASSES
System property which enables dumping of generated classesstatic java.lang.String
BYTEMAN_DUMP_GENERATED_CLASSES_DIRECTORY
System property which configures directory path for files used for dumping of generated classesstatic java.lang.String
BYTEMAN_DUMP_GENERATED_CLASSES_INTERMEDIATE
System property which configures dumping of intermediate versions of generated classesstatic java.lang.String
BYTEMAN_VERBOSE
System property which enables tracing of Byteman activityprivate static BMUnitConfigState
currentConfigState
private boolean
debug
static BMUnitConfigState
defaultConfigState
a default configuration state used when a test class does not specify a configuration state.private boolean
dumpGeneratedClasses
private java.lang.String
dumpGeneratedClassesDirectory
private boolean
dumpGeneratedClassesIntermediate
private boolean
inhibitAgentLoad
static java.lang.String
LOAD_DIRECTORY
System property which identifies the directory from which to start searching for rule script.private java.lang.String
loadDirectory
private boolean
policy
private BMUnitConfigState
previous
static java.lang.String
RESOURCE_LOAD_DIRECTORY
System property which identifies the resource load directory from which to start searching for rule script.private java.lang.String
resourceLoadDirectory
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.private boolean
verbose
static java.lang.String
VERBOSE
this is only provided for backward compatibility in case some app was using this constant string to configure the required property.
-
Constructor Summary
Constructors Modifier Constructor Description private
BMUnitConfigState(BMUnitConfig config, BMUnitConfigState previous)
private
BMUnitConfigState(BMUnitConfigState previous)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkBMUnitVersion(java.lang.String agentVersion)
private static boolean
configurePropertyReset(BMUnitConfigState newConfigState, BMUnitConfigState oldConfigState, java.util.Properties props)
helper method to configure the properties to be reset when a config change occursBMUnitConfigState
currentConfigState()
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.java.lang.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.java.lang.String
getHost()
getter for currently configured agent host settingjava.lang.String
getLoadDirectory()
getter for currently configured load directory settingprivate static int
getPid()
return the integer process id of the current process.int
getPort()
getter for currently configured agent port settingjava.lang.String
getResourceLoadDirectory()
getter for currently configured resource directory settingprivate static boolean
initBMUnitVerbose()
private static boolean
initDebug()
private static java.lang.String
initDefaultLoadDirectory()
computes the default load directory from system property org.jboss.byteman.contrib.bmunit.load.directory or defaults it to ""private static java.lang.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 directoryprivate static boolean
initDumpGeneratedClasses()
private static java.lang.String
initDumpGeneratedClassesDirectory()
private static boolean
initDumpGeneratedClassesIntermediate()
private static java.lang.String
initHost()
return the String configured for the agent host or null if it was not configuredprivate static boolean
initPolicy()
test whether a security policy should be set for agent code when the agent is installedprivate static int
initPort()
return the integer port configured for the agent port or 0 if it was not configured or was misconfiguredprivate static boolean
initVerbose()
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 loadboolean
isBMUnitVerbose()
getter for currently configured BMUnit verbose settingboolean
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 settingboolean
isDumpGeneratedClasses()
getter for current dumpGeneratedClasses settingboolean
isDumpGeneratedClassesIntermediate()
smart getter for current dumpGeneratedClassesIntermediate setting which only returns the attribute setting if dumpGeneratedClasses has also been set.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 loadboolean
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 loadboolean
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 settingprivate void
loadAgent()
load the agent into this JVM if not already loaded.private static boolean
needPropertyReset(BMUnitConfigState newConfigState, BMUnitConfigState oldConfigState)
helper method to check whether we need to update agent properties when we switch configstatic void
popConfigurationState(java.lang.Class<?> testClass)
static void
popConfigurationState(java.lang.reflect.Method method)
static void
pushConfigurationState(BMUnitConfig config, java.lang.Class<?> testClass)
install the configuration for a specific test class, possibly also adopting it as the default configuration this method is not thread-safe.static void
pushConfigurationState(BMUnitConfig config, java.lang.reflect.Method method)
private static void
resetAgentProperties()
static void
resetConfigurationState(java.lang.Class<?> testClass)
static void
resetConfigurationState(java.lang.reflect.Method method)
private static void
uploadAgentProperties()
-
-
-
Field Detail
-
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 java.lang.String agentHost
-
agentPort
private int agentPort
-
loadDirectory
private java.lang.String loadDirectory
-
resourceLoadDirectory
private java.lang.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 java.lang.String dumpGeneratedClassesDirectory
-
dumpGeneratedClassesIntermediate
private boolean dumpGeneratedClassesIntermediate
-
previous
private BMUnitConfigState previous
-
LOAD_DIRECTORY
public static final java.lang.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:
- Constant Field Values
-
RESOURCE_LOAD_DIRECTORY
public static final java.lang.String RESOURCE_LOAD_DIRECTORY
System property which identifies the resource load directory from which to start searching for rule script.- See Also:
- Constant Field Values
-
AGENT_PORT
public static final java.lang.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:
- Constant Field Values
-
AGENT_HOST
public static final java.lang.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:
- Constant Field Values
-
AGENT_POLICY
public static final java.lang.String AGENT_POLICY
System property specifying whether to set a security policy when loading the agent.- See Also:
- Constant Field Values
-
AGENT_INHIBIT
public static final java.lang.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:
- Constant Field Values
-
AGENT_VERSION
public static final java.lang.String AGENT_VERSION
system property set by the agent to advertise the version of the loaded agent- See Also:
- Constant Field Values
-
BYTEMAN_ALLOW_CONFIG_UPDATE
public static final java.lang.String BYTEMAN_ALLOW_CONFIG_UPDATE
System property which enables tracing of Byteman activity- See Also:
- Constant Field Values
-
BYTEMAN_VERBOSE
public static final java.lang.String BYTEMAN_VERBOSE
System property which enables tracing of Byteman activity- See Also:
- Constant Field Values
-
BYTEMAN_DEBUG
public static final java.lang.String BYTEMAN_DEBUG
System property which enables printing of Byteman rule debug statements- See Also:
- Constant Field Values
-
BMUNIT_VERBOSE
public static final java.lang.String BMUNIT_VERBOSE
System property which enables tracing of bmunit activity- See Also:
- Constant Field Values
-
BYTEMAN_DUMP_GENERATED_CLASSES
public static final java.lang.String BYTEMAN_DUMP_GENERATED_CLASSES
System property which enables dumping of generated classes- See Also:
- Constant Field Values
-
BYTEMAN_DUMP_GENERATED_CLASSES_DIRECTORY
public static final java.lang.String BYTEMAN_DUMP_GENERATED_CLASSES_DIRECTORY
System property which configures directory path for files used for dumping of generated classes- See Also:
- Constant Field Values
-
BYTEMAN_DUMP_GENERATED_CLASSES_INTERMEDIATE
public static final java.lang.String BYTEMAN_DUMP_GENERATED_CLASSES_INTERMEDIATE
System property which configures dumping of intermediate versions of generated classes- See Also:
- Constant Field Values
-
VERBOSE
public static final java.lang.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:
- Constant Field Values
-
-
Constructor Detail
-
BMUnitConfigState
private BMUnitConfigState(BMUnitConfig config, BMUnitConfigState previous) throws java.lang.Exception
- Throws:
java.lang.Exception
-
BMUnitConfigState
private BMUnitConfigState(BMUnitConfigState previous) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-
Method Detail
-
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, java.util.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 java.lang.Exception
- Throws:
java.lang.Exception
-
resetAgentProperties
private static void resetAgentProperties() throws java.lang.Exception
- Throws:
java.lang.Exception
-
checkBMUnitVersion
private void checkBMUnitVersion(java.lang.String agentVersion) throws java.lang.Exception
- Throws:
java.lang.Exception
-
loadAgent
private void loadAgent() throws java.lang.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:
java.lang.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, java.lang.Class<?> testClass) throws java.lang.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 availabletestClass
- the test class which may or may not have an associated config- Throws:
java.lang.Exception
- if the config cannot be installed or an agent load error occurs
-
popConfigurationState
public static void popConfigurationState(java.lang.Class<?> testClass) throws java.lang.Exception
- Throws:
java.lang.Exception
-
pushConfigurationState
public static void pushConfigurationState(BMUnitConfig config, java.lang.reflect.Method method) throws java.lang.Exception
- Throws:
java.lang.Exception
-
popConfigurationState
public static void popConfigurationState(java.lang.reflect.Method method) throws java.lang.Exception
- Throws:
java.lang.Exception
-
resetConfigurationState
public static void resetConfigurationState(java.lang.reflect.Method method) throws java.lang.Exception
- Throws:
java.lang.Exception
-
resetConfigurationState
public static void resetConfigurationState(java.lang.Class<?> testClass) throws java.lang.Exception
- Throws:
java.lang.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 java.lang.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 java.lang.String getLoadDirectory()
getter for currently configured load directory setting- Returns:
- the current load directory setting
-
getResourceLoadDirectory
public java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.String initDumpGeneratedClassesDirectory()
-
initDumpGeneratedClassesIntermediate
private static boolean initDumpGeneratedClassesIntermediate()
-
-