Package org.jboss.byteman.contrib.bmunit
Class BMUnitConfigState
java.lang.Object
org.jboss.byteman.contrib.bmunit.BMUnitConfigState
class used to model a specific BMUnit configuration
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
System property specifying the host to be used when starting the agent and when submitting rules to it.static final String
System property which inhibits automatic loading of the agent.static final String
System property specifying whether to set a security policy when loading the agent.static final String
System property specifying the port to be used when starting the agent and when submitting rules to it.static final String
system property set by the agent to advertise the version of the loaded agentprivate String
private int
private boolean
static final String
System property which enables tracing of bmunit activityprivate boolean
static final String
System property which enables tracing of Byteman activitystatic final String
System property which enables printing of Byteman rule debug statementsstatic final String
System property which enables dumping of generated classesstatic final String
System property which configures directory path for files used for dumping of generated classesstatic final String
System property which configures dumping of intermediate versions of generated classesstatic final String
System property which enables tracing of Byteman activityprivate static BMUnitConfigState
private boolean
static BMUnitConfigState
a default configuration state used when a test class does not specify a configuration state.private boolean
private String
private boolean
private boolean
static final String
System property which identifies the directory from which to start searching for rule script.private String
private boolean
private BMUnitConfigState
static final String
System property which identifies the resource load directory from which to start searching for rule script.private String
private static BMUnitConfigState
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
static final String
this is only provided for backward compatibility in case some app was using this constant string to configure the required property. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
BMUnitConfigState
(BMUnitConfig config, BMUnitConfigState previous) private
BMUnitConfigState
(BMUnitConfigState previous) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkBMUnitVersion
(String agentVersion) private static boolean
configurePropertyReset
(BMUnitConfigState newConfigState, BMUnitConfigState oldConfigState, Properties props) helper method to configure the properties to be reset when a config change occursstatic BMUnitConfigState
the global configuration state which configures the operation of BMUnit when running tests in a specific class or a method in that class.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.getHost()
getter for currently configured agent host settinggetter 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 settinggetter for currently configured resource directory settingprivate static boolean
private static boolean
private static String
computes the default load directory from system property org.jboss.byteman.contrib.bmunit.load.directory or defaults it to ""private static String
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
private static String
private static boolean
private static String
initHost()
return the String configured for the agent host or null if it was not configuredprivate static boolean
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
boolean
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
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
getter for current dumpGeneratedClasses settingboolean
smart getter for current dumpGeneratedClassesIntermediate setting which only returns the attribute setting if dumpGeneratedClasses has also been set.boolean
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
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
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
(Class<?> testClass) static void
popConfigurationState
(Method method) static void
pushConfigurationState
(BMUnitConfig config, 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, Method method) private static void
static void
resetConfigurationState
(Class<?> testClass) static void
resetConfigurationState
(Method method) private static void
-
Field Details
-
currentConfigState
-
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
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
-
agentPort
private int agentPort -
loadDirectory
-
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
-
dumpGeneratedClassesIntermediate
private boolean dumpGeneratedClassesIntermediate -
previous
-
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
System property which identifies the resource load directory from which to start searching for rule script.- See Also:
-
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
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
System property specifying whether to set a security policy when loading the agent.- See Also:
-
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
system property set by the agent to advertise the version of the loaded agent- See Also:
-
BYTEMAN_ALLOW_CONFIG_UPDATE
System property which enables tracing of Byteman activity- See Also:
-
BYTEMAN_VERBOSE
System property which enables tracing of Byteman activity- See Also:
-
BYTEMAN_DEBUG
System property which enables printing of Byteman rule debug statements- See Also:
-
BMUNIT_VERBOSE
System property which enables tracing of bmunit activity- See Also:
-
BYTEMAN_DUMP_GENERATED_CLASSES
System property which enables dumping of generated classes- See Also:
-
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
System property which configures dumping of intermediate versions of generated classes- See Also:
-
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
- Throws:
Exception
-
resetAgentProperties
- Throws:
Exception
-
checkBMUnitVersion
- Throws:
Exception
-
loadAgent
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
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:
Exception
- if the config cannot be installed or an agent load error occurs
-
popConfigurationState
- Throws:
Exception
-
pushConfigurationState
- Throws:
Exception
-
popConfigurationState
- Throws:
Exception
-
resetConfigurationState
- Throws:
Exception
-
resetConfigurationState
- Throws:
Exception
-
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
-
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
getter for currently configured load directory setting- Returns:
- the current load directory setting
-
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
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
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
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
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
-
initDumpGeneratedClassesIntermediate
private static boolean initDumpGeneratedClassesIntermediate()
-