Methods Summary |
---|
private synchronized void | _testAttrs()
final Map<String,CustomMBeanConfig> all = getCustomMBeanConfigs();
if ( all.size() != 0 )
{
// everything is already tested generically, but we'll
// do some basic sanity checks here
for( final CustomMBeanConfig config : all.values() )
{
sanityCheck( config );
}
}
else
{
warning( "CustomMBeanConfigTest: No custom MBeans to test" );
}
|
private void | _testGetAll()
final Map<String,CustomMBeanConfig> all = getCustomMBeanConfigs();
assert( all != null );
|
public synchronized com.sun.appserv.management.config.CustomMBeanConfig | create(com.sun.appserv.management.config.DomainConfig domainConfig, java.lang.String name, java.util.Map optional)
return createInstance( domainConfig, name, optional );
|
public static com.sun.appserv.management.config.CustomMBeanConfig | createInstance(com.sun.appserv.management.config.DomainConfig domainConfig, java.lang.String name, java.util.Map optional)
final CustomMBeanConfig custom =
domainConfig.createCustomMBeanConfig( name, IMPL_CLASSNAME,
createObjectName( name ),
false,
optional );
return custom;
|
private static java.lang.String | createObjectName(java.lang.String name)
return CustomMBeanConfig.JMX_DOMAIN + ":name=" + name +
",type=" + TEST_TYPE;
|
private static java.util.Map | createProps()Create some dummy properties for creating a CustomMBeanConfig
final String PRP = PropertiesAccess.PROPERTY_PREFIX; // shorten
final Map<String,String> optional = new HashMap<String,String>();
// these must be available in test MBean
optional.put( PRP + "Attr1", "hello" );
optional.put( PRP + "Attr2", "world" );
return optional;
|
public static com.sun.appserv.management.config.CustomMBeanConfig | ensureDefaultInstance(com.sun.appserv.management.config.DomainConfig domainConfig)
CustomMBeanConfig result =
domainConfig.getCustomMBeanConfigMap().get( getDefaultInstanceName() );
if ( result == null )
{
result = createInstance(
domainConfig,
getDefaultInstanceName(),
createProps() );
}
return result;
|
public java.util.Map | getCustomMBeanConfigs()
return getDomainConfig().getCustomMBeanConfigMap();
|
public static java.lang.String | getDefaultInstanceName()
return getDefaultInstanceName( "CustomMBeanConfig" );
|
private java.util.Set | getRegisteredCustoms()
final QueryMgr queryMgr = getQueryMgr();
final Set<ObjectName> mbeans =
queryMgr.queryPatternObjectNameSet( CustomMBeanConfig.JMX_DOMAIN, "type=" + TEST_TYPE );
return mbeans;
|
private void | removeCustomMBean(java.lang.String name)
getDomainConfig().removeCustomMBeanConfig( name );
|
private void | sanityCheck(com.sun.appserv.management.config.CustomMBeanConfig config)
final String objectName = config.getObjectNameInConfig();
final String implClassname = config.getImplClassname();
|
public synchronized void | testCreateRemove()
if ( ! checkNotOffline( "testCreateRemove" ) )
{
return;
}
final DomainConfig domainConfig = getDomainConfig();
final Map<String,String> optional = createProps();
final Set<CustomMBeanConfig> created = new HashSet<CustomMBeanConfig>();
final Map<String,CustomMBeanConfig> existing =
getDomainConfig().getCustomMBeanConfigMap();
unregisterAnyTestMBeans();
final Set<ObjectName> customsBefore = getRegisteredCustoms();
if ( customsBefore.size() != 0 )
{
printVerbose( "custom MBeans already registered:\n" +
CollectionUtil.toString( customsBefore, "\n" ) );
}
final int NUM = 3;
for( int i = 0; i < NUM; ++i )
{
final String testName = TEST_NAME_BASE + i;
if ( existing.containsKey( testName ) )
{
RefHelper.removeAllRefsTo( existing.get( testName ), true );
// leftover from a failed test...
removeCustomMBean( testName );
}
final CustomMBeanConfig config =
create( domainConfig, TEST_NAME_BASE + i, optional );
//printVerbose( "created: " + Util.getObjectName( config ) );
assert( getCustomMBeanConfigs().get( config.getName() ) == config );
created.add( config );
sanityCheck( config );
verifyPropsAdded( config, optional );
}
_testGetAll();
_testAttrs();
for( final CustomMBeanConfig config : created )
{
//printVerbose( "removing: " + Util.getObjectName( config ) );
final String name = config.getName();
removeCustomMBean( name );
assert( getCustomMBeanConfigs().get( name ) == null );
}
_testGetAll();
mySleep( 100 );
final Set<ObjectName> customsAfter = getRegisteredCustoms();
customsAfter.removeAll( customsBefore );
if ( customsAfter.size() != 0 )
{
warning( "after removing custom MBeans, " +
"they are still registered (not an AMX bug):\n" +
CollectionUtil.toString( customsAfter, "\n" ) );
}
unregisterAnyTestMBeans();
|
private void | unregisterAnyTestMBeans()
final Set<ObjectName> customs = getRegisteredCustoms();
for( final ObjectName objectName : customs )
{
if ( TEST_TYPE.equals( objectName.getKeyProperty( "type" ) ) )
{
try
{
getMBeanServerConnection().unregisterMBean( objectName );
printVerbose( "unregistered: " + objectName );
}
catch( Exception e )
{
}
}
}
|
public synchronized void | verifyPropsAdded(com.sun.appserv.management.config.CustomMBeanConfig config, java.util.Map props)
for( final String key : props.keySet() )
{
if ( key.startsWith( PropertiesAccess.PROPERTY_PREFIX ) )
{
final String specifiedValue = props.get( key ).toString();
final String propName = key.substring(
PropertiesAccess.PROPERTY_PREFIX.length(), key.length());
final String actualValue = config.getPropertyValue( propName );
assert( specifiedValue.equals( actualValue ) );
}
}
|