Methods Summary |
---|
java.lang.String | arrayToString(java.lang.Object[] a)
final StringBuffer buf = new StringBuffer();
buf.append( "{" );
for( int i = 0; i < a.length; ++i )
{
buf.append( a[ i ].toString() );
buf.append( ", " );
}
buf.append( "}" );
return( buf.toString() );
|
static java.lang.String | attributeListToString(javax.management.AttributeList attrs)
final StringBuffer buf = new StringBuffer();
for( int i = 0; i < attrs.size(); ++i )
{
buf.append( attributeToString( (Attribute)attrs.get( i ) ) );
buf.append( "\n" );
}
return( buf.toString() );
|
static java.lang.String | attributeToString(javax.management.Attribute attr)
return( attr.getName() + " = " + attr.getValue().toString() );
|
private static TesteeMBean | createTestee()
final TesteeMBean testee = new Testee();
return( testee );
|
static void | dm(java.lang.Object o)
System.out.println( o.toString() );
|
private java.lang.String[] | dottedNameList(java.lang.String name)
return( mGetSetMBean.dottedNameList( new String [] { name } ) );
|
private java.lang.String[] | dottedNameMonitoringList(java.lang.String name)
return( mGetSetMBean.dottedNameMonitoringList( new String [] { name } ) );
|
javax.management.Attribute | find(java.lang.Object[] attrs, java.lang.String name)
Attribute attr = null;
final int size = attrs.length;
for( int i = 0; i < size; ++i )
{
final Attribute candidate = (Attribute)attrs[ i ];
if ( candidate.getName().equals( name ) )
{
attr = candidate;
break;
}
}
return( attr );
|
javax.management.Attribute | getAttribute(java.lang.String name)
final Object result = mGetSetMBean.dottedNameGet( name );
if ( result instanceof Exception )
{
((Exception)result).printStackTrace();
}
assert( result instanceof Attribute ): "expecting Attribute, got " + result.getClass().getName();
return( (Attribute)result );
|
private static java.lang.String | getConfigDottedName(java.lang.String id)
return( getServerDottedName( id ) + CONFIG_SUFFIX );
|
javax.management.Attribute | getMonitoringAttribute(java.lang.String name)
final Object result = mGetSetMBean.dottedNameMonitoringGet( name );
assert( result instanceof Attribute ) :
"expecting single Attribute, got " + result.getClass().getName();
return( (Attribute)result );
|
private static java.lang.String | getMonitoringDottedName(java.lang.String id)
return( getServerDottedName( id ) );
|
private static java.lang.String | getServerDottedName(java.lang.String id)
return( SERVER_NAME_BASE + id );
|
javax.management.ObjectName | registerAndAddTestee(java.lang.Object mbean, java.lang.String dottedName, java.lang.String id, java.lang.String category, DottedNameRegistry registry)
final ObjectName objectName = new ObjectName( TESTEE_OBJECTNAME_BASE +
",id=" + id +
",category=" + category );
mServer.registerMBean( mbean, objectName );
registry.add( dottedName, objectName );
assert( registry.dottedNameToObjectName( dottedName ) == objectName );
return( objectName );
|
javax.management.ObjectName | registerAndAddTestee(java.lang.String dottedName, java.lang.String id, java.lang.String category, DottedNameRegistry registry)
final ObjectName objectName =
registerAndAddTestee( createTestee(), dottedName, id, category, registry );
return( objectName );
|
java.lang.String | setToString(java.util.Set s)
final Iterator iter = s.iterator();
final StringBuffer buf = new StringBuffer();
while ( iter.hasNext() )
{
buf.append( (String)iter.next() + "\n" );
}
return( buf.toString() );
|
public void | setUp()
mServer = MBeanServerFactory.newMBeanServer( "" + System.currentTimeMillis() );
mRegistry = new DottedNameRegistry1To1Impl();
mMonitoringRegistry = new DottedNameRegistry1To1Impl();
mGetSetMBean = new HookedDottedNameGetSetMBeanImpl( mServer, mRegistry, mMonitoringRegistry );
mServer.registerMBean( mGetSetMBean, new ObjectName( ":name=get-set-testee" ) );
/*
Set up configuration testees
*/
for( int i = 0; i < NUM_SERVERS; ++i )
{
final String id = "" + i;
final String dottedName = getConfigDottedName( id );
registerAndAddTestee( dottedName, id, CATEGORY_CONFIG, mRegistry );
}
// simulate the domain itself with some children
final ObjectName on = registerAndAddTestee( DOMAIN, DOMAIN, CATEGORY_CONFIG, mRegistry );
for( int i = 0; i < DOMAIN_SUBPARTS.length; ++i )
{
final String part = DOMAIN_SUBPARTS[ i ];
registerAndAddTestee( DOMAIN + "." + part, part, CATEGORY_CONFIG, mRegistry );
}
//dm( com.sun.cli.util.stringifier.MBeanInfoStringifier.DEFAULT.stringify( mServer.getMBeanInfo( on ) ) );
/*
Set up monitoring testees
*/
for( int i = 0; i < NUM_SERVERS; ++i )
{
final String id = "" + i;
final String dottedName = getMonitoringDottedName( id );
registerAndAddTestee( dottedName, id, CATEGORY_MONITORING, mMonitoringRegistry);
}
// simulate the domain itself
registerAndAddTestee( DOMAIN,
DOMAIN, CATEGORY_MONITORING, mMonitoringRegistry);
// Register an MBean with no properties
SIMPLE_OBJECT_NAME = registerAndAddTestee( new MonitoringTestee(), SIMPLE_NAME,
SIMPLE, CATEGORY_MONITORING, mMonitoringRegistry);
|
public void | tearDown()
mServer = null;
|
public void | testAliasingOffForMonitoring()
final Object result = mGetSetMBean.dottedNameMonitoringGet( getConfigDottedName( "0" ) + ".*" );
assert( result instanceof Attribute[] );
assertEquals( 0, dottedNameMonitoringList( "*config*" ).length );
|
public void | testConfigGetsOnlyConfig()
// '*' has special meaning of only getting the server.xxx names, *not* domain.xxx or config.xxx
final String [] names = dottedNameList( getConfigDottedName( "0" ) + "*" );
for( int i = 0; i < names.length; ++i )
{
final DottedName dn = DottedNameFactory.getInstance().get( names[ i ] );
assertEquals( dn.getScope(), getConfigDottedName( "0" ) );
}
|
public void | testDomainGetsOnlyDomain()
// '*' has special meaning of only getting the server.xxx names, *not* domain.xxx or config.xxx
final String [] names = dottedNameList( "domain*" );
for( int i = 0; i < names.length; ++i )
{
final DottedName dn = DottedNameFactory.getInstance().get( names[ i ] );
assertEquals( dn.getScope(), DottedNameAliasSupport.DOMAIN_SCOPE );
}
|
public void | testFunkyName()
// set up testee with strange name
// simulate the domain itself
registerAndAddTestee( FUNKY_DOTTED_NAME, FUNKY_ID, CATEGORY_SPECIAL, mRegistry);
|
public void | testGetProperty()
final String dottedName = PRIMARY_TESTEE + "." +
DottedNamePropertySupport.getPropertySuffix( Testee.PROPERTY_NAME );
final Attribute attr = getAttribute( dottedName );
assertEquals( Testee.PROPERTY_VALUE, attr.getValue() );
|
public void | testGetString()
final String dn = testeeValueName( "String" );
assertEquals( getAttribute( dn ), new Attribute( dn, "" ) );
|
public void | testGetStringArray()
final String dn = testeeValueName( "StringArray" );
final Attribute attr = getAttribute( dn );
assertEquals( 0, ((String [])attr.getValue()).length );
|
public void | testGetWild()
final Attribute [] attrs = (Attribute [])mGetSetMBean.dottedNameGet( "*.StringArray" );
// will only look in "server.*" namespace
assertEquals( NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS, attrs.length );
|
public void | testGetWildAttr()
Attribute[] attrs = (Attribute[])mGetSetMBean.dottedNameGet( "*.StringArray*" );
// we're using '*' which will select only server.xxx names. There should be one
// name for each server itself, and NUM_DOMAIN_SUBPARTS additional names per server.
assertEquals( NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS, attrs.length );
attrs = (Attribute[])mGetSetMBean.dottedNameGet("*.*int*" );
assertEquals( NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS, attrs.length );
|
public void | testGetWildAttrSingleMBean()
// this should get all 17 attributes and 1 property and 1 attribute called "Properties"
final Attribute[] attrs =
(Attribute[])mGetSetMBean.dottedNameGet( PRIMARY_TESTEE + ".*" );
assertEquals( 17 + 1 + 1, attrs.length );
|
public void | testGetWildProperty()
final Attribute [] attrs = (Attribute [])mGetSetMBean.dottedNameGet( PRIMARY_TESTEE + ".property.*" );
assertEquals( 1, attrs.length );
|
public void | testGetbyte()
final String dn = testeeValueName( "byte" );
assertEquals( getAttribute( dn ), new Attribute( dn, new Byte( (byte)0 ) ) );
|
public void | testGetchar()
final String dn = testeeValueName( "char" );
assertEquals( getAttribute( dn ), new Attribute( dn, new Character( 'c" ) ) );
|
public void | testGetdouble()
final String dn = testeeValueName( "double" );
assertEquals( getAttribute( dn ), new Attribute( dn, new Double( 0.0 ) ) );
|
public void | testGetfloat()
final String dn = testeeValueName( "float" );
assertEquals( getAttribute( dn ), new Attribute( dn, new Float( 0.0 ) ) );
|
public void | testGetint()
final String dn = testeeValueName( "int" );
assertEquals( getAttribute( dn ), new Attribute( dn, new Integer( 0 ) ) );
|
public void | testGetlong()
final String dn = testeeValueName( "long" );
assertEquals( getAttribute( dn ), new Attribute( dn, new Long( 0 ) ) );
|
public void | testGetshort()
final String dn = testeeValueName( "short" );
assertEquals( getAttribute( dn ), new Attribute( dn, new Short( (short)0 ) ) );
|
public void | testListAll()
// list all will only access server.* variants
final int required =
NUM_SERVERS + // server itself
NUM_SERVERS * NUM_DOMAIN_SUBPARTS + // aliased parts
0;
final String [] names = dottedNameList( "*" );
assertEquals( required, names.length );
|
public void | testListDomain()
// domain only works if it starts with "domain"
assertEquals( 0, dottedNameList( "*" + DOMAIN + "*" ).length );
assertEquals( 0, dottedNameList( "*" + DOMAIN ).length );
assertEquals( 1 + NUM_DOMAIN_SUBPARTS, dottedNameList( DOMAIN + "*" ).length );
|
public void | testListEmpty()
final String [] names = dottedNameList( "" );
assertEquals( 0, names.length );
|
public void | testListNoChildren()
assertEquals( 0, dottedNameList( getServerDottedName( "0." + DOMAIN_SUBPARTS[ 0 ] ) ).length );
assertEquals( 0, dottedNameList( getConfigDottedName( "0" ) ).length );
|
public void | testListNoMatch()
assertEquals( 0, dottedNameList( "*foo*" ).length );
|
public void | testListNonExistent()
assertEquals( 0, dottedNameList( "foo" ).length );
assertEquals( 0, dottedNameList( "/" ).length );
|
public void | testListNonRecursive()
assertEquals( NUM_DOMAIN_SUBPARTS, dottedNameList( getServerDottedName( "0" ) ).length );
assertEquals( NUM_DOMAIN_SUBPARTS, dottedNameList( DOMAIN ).length );
|
public void | testListRecursive()
final int required =
NUM_SERVERS + // one for each testee itself
NUM_SERVERS * NUM_DOMAIN_SUBPARTS + // each server aliases into domain
0;
assertEquals( required, dottedNameList( SERVER_NAME_BASE + "*").length );
|
public void | testListServer()
final int required = NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS;
assertEquals( required, dottedNameList( SERVER_NAME_BASE + "*" ).length );
assertEquals( required, dottedNameList( "*" + SERVER_NAME_BASE + "*" ).length );
|
public void | testListWildcardMonitoring()
assertEquals( NUM_SERVERS, dottedNameMonitoringList( "server*" ).length );
|
public void | testListWithChildren()
assertEquals( NUM_DOMAIN_SUBPARTS, dottedNameList( DOMAIN + ".*" ).length );
|
public void | testMonitoringGet()
final String dn = DOMAIN + ".int";
assertEquals( getMonitoringAttribute( dn ), new Attribute( dn, new Integer( 0 ) ) );
|
public void | testMultiGet()
final String [] params = new String []
{
testeeValueName( "char" ),
testeeValueName( "int" ),
testeeValueName( "float" ),
testeeValueName( "Double" ),
};
final Attribute[] attrs = (Attribute[])mGetSetMBean.dottedNameGet( params );
assertEquals( params.length, attrs.length );
for( int i = 0; i < attrs.length; ++i )
{
assert( attrs[ i ] instanceof Attribute );
}
|
public synchronized void | testMultiSet()
final String [] params = new String []
{
testeeValueName( "int" ) + "=99",
testeeValueName( "char" ) + "=x",
testeeValueName( "String" ) + "=9.999",
testeeValueName( "Double" ) + "=9.999",
};
final Object[] attrs = mGetSetMBean.dottedNameSet( params );
assertEquals( params.length, attrs.length );
assertEquals( new Attribute( testeeValueName( "int" ), new Integer( 99 ) ),
find( attrs, testeeValueName( "int" )));
assertEquals( new Attribute( testeeValueName( "String" ), "9.999" ),
find( attrs, testeeValueName( "String" )));
assertEquals( new Attribute( testeeValueName( "char" ), new Character( 'x" ) ),
find( attrs, testeeValueName( "char" )));
assertEquals( new Attribute( testeeValueName( "Double" ), new Double( 9.999 ) ),
find( attrs, testeeValueName( "Double" )));
|
public synchronized void | testNoProperties()
mServer.getMBeanInfo(SIMPLE_OBJECT_NAME );
// the MonitoringTestee has no properties
final Object result = mGetSetMBean.dottedNameMonitoringGet( SIMPLE + ".property.foo" );
assert( result instanceof AttributeNotFoundException ) :
"expected AttributeNotFoundException, got " + result.getClass().getName() +
" at ";
|
public void | testServerAliasIntoDomain()
// eg "server0.applications"
final String target = getServerDottedName( "0" ) + "." + DOMAIN_SUBPARTS[ 0 ];
getAttribute( target + ".int" );
|
public void | testSetByte()
final String dn = testeeValueName( "byte" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Byte( (byte)100 ) ) );
|
public void | testSetCharacter()
final String dn = testeeValueName( "Character" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=x" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Character( 'x" ) ) );
|
public void | testSetDouble()
final String dn = testeeValueName( "Double" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=99.99" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Double( 99.99 ) ) );
|
public void | testSetFloat()
final String dn = testeeValueName( "Float" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=99.99" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Float( 99.99 ) ) );
|
public void | testSetInteger()
final String dn = testeeValueName( "Integer" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Integer( 100 ) ) );
|
public void | testSetIntegerArray()
final String dn = testeeValueName( "IntegerArray" );
mGetSetMBean.dottedNameSet( dn + "=1,2,3" );
final Attribute attr = getAttribute( dn );
final Integer [] values = (Integer [])attr.getValue();
assertEquals( 3, values.length );
assertEquals( new Integer( 1 ), values[ 0 ] );
assertEquals( new Integer( 2 ), values[ 1 ] );
assertEquals( new Integer( 3 ), values[ 2 ] );
|
public void | testSetLong()
final String dn = testeeValueName( "Long" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Long( 100 ) ) );
|
public synchronized void | testSetProperty()
final String dottedName = PRIMARY_TESTEE + "." +
DottedNamePropertySupport.getPropertySuffix( "testProperty" );
final String TEST_VALUE = "hello";
// set a value and re-get it to verify it was set
final Object value = mGetSetMBean.dottedNameSet( dottedName + "=" + TEST_VALUE );
if ( value instanceof Exception )
{
((Exception)value).printStackTrace();
}
final Attribute attr = (Attribute)value;
assertEquals( TEST_VALUE, attr.getValue( ) );
assertEquals( TEST_VALUE, getAttribute( dottedName ).getValue() );
|
public void | testSetShort()
final String dn = testeeValueName( "Short" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Short( (short)100 ) ) );
|
public void | testSetString()
final String dn = testeeValueName( "String" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=hello world" } );
assertEquals( getAttribute( dn ), new Attribute( dn, "hello world" ) );
|
public void | testSetStringArray()
final String dn = testeeValueName( "StringArray" );
final Attribute result = (Attribute)mGetSetMBean.dottedNameSet( dn + "=hello,there,world" );
final Attribute attr = getAttribute( dn );
assertEquals( result, attr );
final String [] values = (String [])attr.getValue();
assertEquals( 3, values.length );
assertEquals( "hello", values[ 0 ] );
assertEquals( "there", values[ 1 ] );
assertEquals( "world", values[ 2 ] );
|
public void | testSetWild()
final Object result = mGetSetMBean.dottedNameSet( "*.int=1" );
assert( result instanceof Exception );
|
public void | testSetbyte()
final String dn = testeeValueName( "byte" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Byte( (byte)100 ) ) );
|
public void | testSetchar()
final String dn = testeeValueName( "char" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=x" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Character( 'x" ) ) );
|
public void | testSetdouble()
final String dn = testeeValueName( "double" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=99.99" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Double( 99.99 ) ) );
|
public void | testSetfloat()
final String dn = testeeValueName( "float" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=99.99" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Float( 99.99 ) ) );
|
public void | testSetint()
final String dn = testeeValueName( "int" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Integer( 100 ) ) );
|
public void | testSetlong()
final String dn = testeeValueName( "long" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Long( 100 ) ) );
|
public void | testSetshort()
final String dn = testeeValueName( "short" );
mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } );
assertEquals( getAttribute( dn ), new Attribute( dn, new Short( (short)100 ) ) );
|
public void | testWildcardAllGetsOnlyServers()
// '*' has special meaning of only getting the server.xxx names, *not* domain.xxx or config.xxx
final String [] names = dottedNameList( "*" );
final Set serverNames = new StubbedServerInfo().getServerNames();
for( int i = 0; i < names.length; ++i )
{
final DottedName dn = DottedNameFactory.getInstance().get( names[ i ] );
assert( serverNames.contains( dn.getScope() ) );
}
|
public synchronized void | testWildcardGetAll()
final Attribute[] list1 = (Attribute[])mGetSetMBean.dottedNameGet( "*" );
final Attribute[] list2 = (Attribute[])mGetSetMBean.dottedNameGet( "*.*" );
final Attribute[] list3 = (Attribute[])mGetSetMBean.dottedNameGet( "***.***" );
final Attribute[] list4 = (Attribute[])mGetSetMBean.dottedNameGet( "**********.*" );
final int expectedSize = list1.length;
assert( expectedSize != 0 );
assertEquals( expectedSize, list2.length );
assertEquals( expectedSize, list3.length );
assertEquals( expectedSize, list4.length );
|
public synchronized void | testWildcardGetAllMonitor()
final Attribute[] list = (Attribute[])mGetSetMBean.dottedNameMonitoringGet( "*" );
assert( list.length != 0 );
|
public synchronized void | testWildcardListAll()
final int length1 = dottedNameList( "*" ).length;
assert( length1 != 0 );
|
public void | testWildcardListEmpty()
assert( mGetSetMBean.dottedNameList( new String [ 0 ] ).length != 0 );
|
public synchronized void | testWildcardMonitoringGetAll()
final Attribute[] list1 = (Attribute[])mGetSetMBean.dottedNameMonitoringGet( "*" );
final Attribute[] list2 = (Attribute[])mGetSetMBean.dottedNameMonitoringGet( "*.*" );
final Attribute[] list3 = (Attribute[])mGetSetMBean.dottedNameMonitoringGet( "***.***" );
final Attribute[] list4 = (Attribute[])mGetSetMBean.dottedNameMonitoringGet( "**********.*" );
final int expectedSize = list1.length;
assert( expectedSize != 0 );
assertEquals( expectedSize, list2.length );
assertEquals( expectedSize, list3.length );
assertEquals( expectedSize, list4.length );
|
public synchronized void | testWildcardMonitoringListAll()
assert( dottedNameMonitoringList( "*" ).length != 0 );
|
static java.lang.String | testeeValueName(java.lang.String name)
return( PRIMARY_TESTEE + "." + name );
|
private static java.lang.String | valueName(java.lang.String prefix, java.lang.String valueName)
return( prefix + "." + valueName );
|