1 23 package com.sun.enterprise.management.base; 24 25 import java.io.Serializable ; 26 import java.io.IOException ; 27 28 import java.util.Set ; 29 import java.util.HashSet ; 30 import java.util.Map ; 31 import java.util.List ; 32 import java.util.Iterator ; 33 import java.util.Collections ; 34 import java.util.Date ; 35 import java.lang.reflect.Method ; 36 37 import javax.management.ObjectName ; 38 import javax.management.AttributeList ; 39 import javax.management.MBeanInfo ; 40 import javax.management.MBeanOperationInfo ; 41 import javax.management.MBeanParameterInfo ; 42 import javax.management.MBeanAttributeInfo ; 43 import javax.management.MBeanFeatureInfo ; 44 import javax.management.Attribute ; 45 import javax.management.JMException ; 46 import javax.management.MBeanServerConnection ; 47 import javax.management.AttributeNotFoundException ; 48 import javax.management.NotificationListener ; 49 import javax.management.Notification ; 50 51 52 import com.sun.appserv.management.DomainRoot; 53 import com.sun.appserv.management.base.AMX; 54 import com.sun.appserv.management.base.Container; 55 import com.sun.appserv.management.base.AMXAttributes; 56 import com.sun.appserv.management.base.QueryMgr; 57 import com.sun.appserv.management.base.Container; 58 import com.sun.appserv.management.base.Container; 59 import com.sun.appserv.management.base.Util; 60 import com.sun.appserv.management.base.XTypes; 61 import com.sun.appserv.management.base.Extra; 62 63 import com.sun.appserv.management.client.ProxyFactory; 64 65 import com.sun.appserv.management.monitor.Monitoring; 66 import com.sun.appserv.management.monitor.JMXMonitorMgr; 67 import com.sun.appserv.management.monitor.AMXStringMonitor; 68 import com.sun.appserv.management.monitor.AMXCounterMonitor; 69 import com.sun.appserv.management.monitor.AMXGaugeMonitor; 70 import com.sun.appserv.management.monitor.EJBModuleMonitor; 71 import com.sun.appserv.management.monitor.HTTPServiceMonitor; 72 import com.sun.appserv.management.monitor.ApplicationMonitor; 73 74 import com.sun.appserv.management.j2ee.J2EETypes; 75 76 import com.sun.appserv.management.config.AMXConfig; 77 import com.sun.appserv.management.config.NamedConfigElement; 78 import com.sun.appserv.management.config.SecurityMapConfig; 79 80 import com.sun.appserv.management.util.jmx.MBeanServerConnectionConnectionSource; 81 import com.sun.appserv.management.util.jmx.JMXUtil; 82 import com.sun.appserv.management.util.misc.ExceptionUtil; 83 84 import com.sun.appserv.management.util.misc.GSetUtil; 85 import com.sun.appserv.management.util.misc.ClassUtil; 86 import com.sun.appserv.management.util.misc.StringUtil; 87 import com.sun.appserv.management.util.misc.CollectionUtil; 88 89 import com.sun.appserv.management.ext.wsmgmt.WebServiceEndpointInfo; 90 import com.sun.appserv.management.ext.wsmgmt.MessageTrace; 91 import com.sun.appserv.management.ext.logging.LogQueryResult; 92 import com.sun.appserv.management.ext.logging.Logging; 93 94 import com.sun.enterprise.management.support.AMXNonConfigImplBase; 95 import com.sun.enterprise.management.support.QueryMgrImpl; 96 import com.sun.enterprise.management.support.TypeInfos; 97 import com.sun.enterprise.management.support.TypeInfo; 98 import com.sun.enterprise.management.support.CoverageInfo; 99 import com.sun.enterprise.management.support.AMXDebugStuff; 100 101 102 103 import com.sun.enterprise.management.AMXTestBase; 104 import com.sun.enterprise.management.Capabilities; 105 import com.sun.enterprise.management.Capabilities; 106 107 108 109 111 public final class AMXTest extends AMXTestBase 112 { 113 public 114 AMXTest( ) 115 { 116 } 117 118 public static Capabilities 119 getCapabilities() 120 { 121 return getOfflineCapableCapabilities( true ); 122 } 123 124 128 public void 129 checkContainerObjectName( final ObjectName objectName ) 130 throws Exception 131 { 132 final ObjectName containerObjectName = (ObjectName ) 133 getConnection().getAttribute( objectName, AMXAttributes.ATTR_CONTAINER_OBJECT_NAME ); 134 135 if ( Util.getJ2EEType( objectName ).equals( XTypes.DOMAIN_ROOT ) ) 136 { 137 assert( containerObjectName == null ); 138 } 139 else 140 { 141 assert( containerObjectName != null ); 142 final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class ); 143 assert( Util.getObjectName( proxy.getContainer() ).equals( containerObjectName ) ); 144 } 145 146 } 147 148 public void 149 testContainerObjectName() 150 throws Exception 151 { 152 testAll( "checkContainerObjectName" ); 153 } 154 155 156 160 public void 161 checkTemplateAttributes( final ObjectName objectName ) 162 { 163 final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class); 164 165 if ( proxy instanceof AMXConfig ) 166 { 167 final AMXConfig config = (AMXConfig)proxy; 168 169 final Set <String > s = new HashSet <String >(); 170 171 final MBeanInfo mbeanInfo = Util.getExtra( config ).getMBeanInfo(); 172 final MBeanAttributeInfo [] attrInfos = mbeanInfo.getAttributes(); 173 for( int i = 0; i < attrInfos.length; ++i ) 174 { 175 final MBeanAttributeInfo info = attrInfos[ i ]; 176 177 final String type = info.getType(); 178 if ( type.equals( "int" ) || type.equals( "long" ) ) 179 { 180 s.add( info.getName() ); 181 } 182 } 183 184 if ( s.size() != 0 ) 185 { 186 trace( "\n" + objectName + 187 " contains the following int/long Attributes which perhaps ought to be String" + 188 " due to the templatizing of config: " + toString( s ) + "\n" ); 189 } 190 } 191 } 192 193 public void 194 testTemplateAttributes() 195 throws Exception 196 { 197 testAll( "checkTemplateAttributes" ); 198 } 199 200 201 202 203 206 public void 207 checkSelfObjectName( final ObjectName obj ) 208 throws Exception 209 { 210 final ObjectName selfName = (ObjectName ) 211 getConnection().getAttribute( obj, AMXAttributes.ATTR_OBJECT_NAME ); 212 213 assert( selfName.equals( obj ) ); 214 } 215 216 public void 217 testSelfObjectName() 218 throws Exception 219 { 220 testAll( "checkSelfObjectName" ); 221 } 222 223 224 227 public void 228 checkInterface( final ObjectName src ) 229 throws Exception 230 { 231 final String interfaceName = (String ) 232 getConnection().getAttribute( src, AMXAttributes.ATTR_INTERFACE_NAME ); 233 234 assert( interfaceName != null ); 235 } 236 237 238 public void 239 testInterface() 240 throws Exception 241 { 242 testAll( "checkInterface" ); 243 } 244 245 248 public void 249 checkJ2EETypeAndName( final ObjectName src ) 250 throws Exception 251 { 252 assert( src.getKeyProperty( AMX.J2EE_TYPE_KEY ) != null ); 253 assert( src.getKeyProperty( AMX.NAME_KEY ) != null ); 254 } 255 256 257 public void 258 testJ2EETypeAndName() 259 throws Exception 260 { 261 testAll( "checkJ2EETypeAndName" ); 262 } 263 264 265 266 269 public void 270 testContainerChild() 271 { 272 final TypeInfos infos = TypeInfos.getInstance(); 273 final Set <String > j2eeTypesSet = infos.getJ2EETypes(); 274 275 for( final String j2eeType : j2eeTypesSet ) 276 { 277 checkContainerChild( j2eeType ); 278 } 279 } 280 281 284 public void 285 checkContainerChild( final String childJ2EEType ) 286 { 287 final QueryMgr queryMgr = getQueryMgr(); 288 final Set children = queryMgr.queryJ2EETypeSet( childJ2EEType ); 289 290 final Iterator iter = children.iterator(); 291 while ( iter.hasNext() ) 292 { 293 final AMX containee = Util.asAMX(iter.next()); 294 Container container = null; 295 296 final ObjectName objectName = Util.getObjectName( containee ); 297 if ( ! shouldTest( objectName ) ) 298 { 299 continue; 300 } 301 302 try 303 { 304 container = (Container)containee.getContainer(); 305 } 306 catch( Exception e ) 307 { 308 trace( "Can't get container for: " + objectName ); 309 } 310 311 if ( container == null ) 312 { 313 assert( containee.getJ2EEType().equals( XTypes.DOMAIN_ROOT ) ) : 314 "container is null for: " + objectName; 315 continue; 316 } 317 318 final Set <AMX> containeeSet = container.getContaineeSet( childJ2EEType ); 319 final Set <ObjectName > containeeObjectNameSet = Util.toObjectNames( containeeSet ); 320 321 assert( containeeObjectNameSet.contains( Util.getExtra( containee ).getObjectName() ) ); 322 } 323 } 324 325 326 329 public void 330 testHaveJ2EE_TYPE() 331 { 332 final TypeInfos infos = TypeInfos.getInstance(); 333 final Set j2eeTypes = infos.getJ2EETypes(); 334 335 boolean success = true; 336 final Iterator iter = j2eeTypes.iterator(); 337 while ( iter.hasNext() ) 338 { 339 final String j2eeType = (String )iter.next(); 340 final TypeInfo info = infos.getInfo( j2eeType ); 341 342 final Class theInterface = info.getInterface(); 343 try 344 { 345 final String value = 346 (String )ClassUtil.getFieldValue( theInterface, "J2EE_TYPE" ); 347 assert( value.equals( j2eeType ) ) : 348 "info and J2EE_TYPE don't match: " + j2eeType + " != " + value; 349 } 350 catch( Exception e ) 351 { 352 trace( "no J2EE_TYPE field found for proxy of type: " + theInterface.getName() ); 353 success = false; 354 } 355 } 356 assert( success ); 357 } 358 359 360 363 public void 364 checkNameMatchesJ2EEName( final ObjectName childObjectName ) 365 throws Exception 366 { 367 final AMX childProxy = getProxyFactory().getProxy( childObjectName, AMX.class); 368 if ( childProxy instanceof NamedConfigElement ) 369 { 370 final String j2eeName = childProxy.getName(); 371 372 assertEquals( j2eeName, childProxy.getName() ); 373 } 374 } 375 376 public void 377 testNameMatchesJ2EEName() 378 throws Exception 379 { 380 testAll( "checkNameMatchesJ2EEName" ); 381 } 382 383 384 private static final String MAP_SUFFIX = "Map"; 385 private static final String OBJECTNAME_MAP_SUFFIX = "ObjectName" + MAP_SUFFIX; 386 387 private static boolean 388 isMapGetterName( final String methodName ) 389 { 390 return( methodName.startsWith( JMXUtil.GET ) && 391 methodName.endsWith( MAP_SUFFIX ) ); 392 } 393 394 private static boolean 395 isMapGetter( final Method method) 396 { 397 return( Map .class.isAssignableFrom( method.getReturnType() ) && 398 isMapGetterName( method.getName() ) ); 399 } 400 401 405 public void 406 checkMaps( final ObjectName objectName ) 407 throws Exception 408 { 409 final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class ); 410 if ( proxy instanceof Container ) 411 { 412 final Method [] methods = getInterfaceClass( proxy ).getMethods(); 413 final MBeanInfo mbeanInfo = Util.getExtra( proxy ).getMBeanInfo(); 414 415 for( int methodIdx = 0; methodIdx < methods.length; ++methodIdx ) 416 { 417 final Method method = methods[ methodIdx ]; 418 final String methodName = method.getName(); 419 420 if ( isMapGetter( method ) ) 421 { 422 if ( methodName.endsWith( OBJECTNAME_MAP_SUFFIX ) ) 423 { 424 warning( "method should exist in MBeanInfo, not interface: " + methodName ); 425 continue; 426 } 427 428 final String peerMethodName = 431 StringUtil.replaceSuffix( methodName, MAP_SUFFIX, OBJECTNAME_MAP_SUFFIX); 432 433 checkCompatibleOperationExists( Util.getObjectName( proxy ), 434 method, 435 peerMethodName, 436 mbeanInfo ); 437 } 438 else if ( isMapGetterName( methodName ) ) 439 { 440 warning( "operation " + methodName + " does not return a Map!" ); 441 } 442 } 443 } 444 } 445 446 454 private void 455 checkCompatibleOperationExists( 456 final ObjectName objectName, 457 final Method proxyMethod, 458 final String mbeanMethodName, 459 final MBeanInfo mbeanInfo ) 460 { 461 final Class proxyReturnType = proxyMethod.getReturnType(); 462 final String proxyMethodName = proxyMethod.getName(); 463 464 String mbeanReturnType = null; 465 466 final Class [] parameterTypes = proxyMethod.getParameterTypes(); 467 if ( JMXUtil.isGetter( proxyMethod ) ) 468 { 469 final Map <String ,MBeanAttributeInfo > m = JMXUtil.attributeInfosToMap( mbeanInfo.getAttributes() ); 471 472 final String attrName = StringUtil.stripPrefix( mbeanMethodName, JMXUtil.GET ); 473 final MBeanAttributeInfo attrInfo = (MBeanAttributeInfo )m.get( attrName ); 474 if ( attrInfo != null ) 475 { 476 mbeanReturnType = attrInfo.getType(); 477 } 478 } 479 else 480 { 481 final MBeanOperationInfo [] operations = mbeanInfo.getOperations(); 483 484 final String [] stringSig = ClassUtil.classnamesFromSignature( parameterTypes ); 485 final MBeanOperationInfo opInfo = JMXUtil.findOperation( operations, mbeanMethodName, stringSig ); 486 if ( opInfo != null ) 487 { 488 mbeanReturnType = opInfo.getReturnType(); 489 } 490 } 491 492 boolean hasPeer = mbeanReturnType != null; 493 if ( hasPeer ) 494 { 495 if ( AMX.class.isAssignableFrom( proxyReturnType ) ) 497 { 498 assert( mbeanReturnType.equals( ObjectName .class.getName() ) ); 499 } 500 else { 502 assert( mbeanReturnType.equals( proxyReturnType.getName() ) ); 503 } 504 hasPeer = true; 505 } 506 507 508 if( ! hasPeer ) 509 { 510 trace( "MBean " + objectName + " has operation " + proxyMethodName + 511 " without corresponding peer Attribute/operation " + mbeanMethodName ); 512 } 513 } 514 515 public void 516 testMaps() 517 throws Exception 518 { 519 testAll( "checkMaps" ); 520 } 521 522 private static final Set SUITABLE_TYPES = GSetUtil.newUnmodifiableStringSet( 523 Void .class.getName(), 524 Object .class.getName(), 525 526 "boolean", "byte", "char", "short", "int", "long", "void", 528 529 boolean[].class.getName(), 530 char[].class.getName(), 531 byte[].class.getName(), 532 short[].class.getName(), 533 int[].class.getName(), 534 long[].class.getName(), 535 Object [].class.getName(), 536 537 Boolean .class.getName(), 538 Character .class.getName(), 539 Byte .class.getName(), 540 Short .class.getName(), 541 Integer .class.getName(), 542 Long .class.getName(), 543 544 String .class.getName(), 545 String [].class.getName(), 546 547 Date .class.getName(), 548 549 ObjectName .class.getName(), 550 ObjectName [].class.getName(), 551 552 Set .class.getName(), 553 List .class.getName(), 554 Map .class.getName(), 555 556 java.util.logging.Level .class.getName(), 557 java.io.File .class.getName(), 558 559 WebServiceEndpointInfo.class.getName(), 562 LogQueryResult.class.getName(), 563 MessageTrace.class.getName() 564 ); 565 566 567 576 private boolean 577 isSuitableReturnTypeForAPI( final String type ) 578 { 579 boolean isSuitable = SUITABLE_TYPES.contains( type ); 580 581 if ( ! isSuitable ) 582 { 583 final boolean isArray = ClassUtil.classnameIsArray( type ); 584 585 if ( isArray || 586 type.startsWith( "java." ) || type.startsWith( "javax.management." ) ) 587 { 588 Class c = null; 589 try 590 { 591 c = ClassUtil.getClassFromName( type ); 592 isSuitable = c.isInterface() || Serializable .class.isAssignableFrom( c ) || 593 c == Object .class; 594 } 595 catch( ClassNotFoundException e ) 596 { 597 trace( "WARNING: can't find class for type: " + type ); 598 isSuitable = false; 599 } 600 601 if ( isArray ) 602 { 603 final Class elementClass = ClassUtil.getArrayElementClass( c ); 604 isSuitable = isSuitableReturnTypeForAPI( elementClass.getName() ); 605 } 606 else if ( isSuitable && 607 (! type.startsWith( "javax." )) && 608 ! c.isInterface() ) 609 { 610 isSuitable = false; 612 } 613 } 614 else if ( type.endsWith( "Stats" ) ) 615 { 616 isSuitable = type.startsWith( "com.sun.appserv.management.monitor.statistics" ) || 617 type.startsWith( "javax.management.j2ee.statistics" ); 618 } 619 } 620 621 return( isSuitable ); 622 } 623 624 625 631 public void 632 checkReturnTypes( final ObjectName objectName ) 633 throws Exception 634 { 635 final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class); 636 final MBeanInfo info = Util.getExtra( proxy ).getMBeanInfo(); 637 final MBeanOperationInfo [] operations = info.getOperations(); 638 639 boolean emittedName = false; 640 641 for( int i = 0; i < operations.length; ++i ) 642 { 643 final MBeanOperationInfo opInfo = operations[ i ]; 644 645 final String returnType = opInfo.getReturnType(); 646 if ( ! isSuitableReturnTypeForAPI( returnType ) ) 647 { 648 if ( ! emittedName ) 649 { 650 emittedName = true; 651 trace( "\n" + objectName ); 652 } 653 654 trace( "WARNING: unsuitable return type in API: " + 655 returnType + " " + opInfo.getName() + "(...)" ); 656 } 657 } 658 } 659 660 661 public void 662 testReturnTypes() 663 throws Exception 664 { 665 testAll( "checkReturnTypes" ); 666 } 667 668 669 670 676 public void 677 checkAttributeTypes( final ObjectName objectName ) 678 throws Exception 679 { 680 final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class); 681 final MBeanInfo info = Util.getExtra( proxy ).getMBeanInfo(); 682 final MBeanAttributeInfo [] attributes = info.getAttributes(); 683 684 boolean emittedName = false; 685 686 for( int i = 0; i < attributes.length; ++i ) 687 { 688 final MBeanAttributeInfo attrInfo = attributes[ i ]; 689 690 final String type = attrInfo.getType(); 691 if ( ! isSuitableReturnTypeForAPI( type ) ) 692 { 693 if ( ! emittedName ) 694 { 695 emittedName = true; 696 } 697 698 if ( ! type.equals( CoverageInfo.class.getName() ) ) 699 { 700 trace( "WARNING: unsuitable Attribute type in API: " + 701 type + " " + attrInfo.getName() + " in " + objectName ); 702 } 703 } 704 } 705 } 706 707 public void 708 testAttributeTypes() 709 throws Exception 710 { 711 testAll( "checkAttributeTypes" ); 712 } 713 714 721 public void 722 checkCreateRemoveGet( final ObjectName objectName ) 723 throws Exception 724 { 725 final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class ); 726 if ( proxy instanceof Container ) 727 { 728 final Method [] methods = getInterfaceClass( proxy ).getMethods(); 729 final MBeanInfo mbeanInfo = Util.getExtra( proxy ).getMBeanInfo(); 730 final MBeanOperationInfo [] operations = mbeanInfo.getOperations(); 731 732 for( int methodIdx = 0; methodIdx < methods.length; ++methodIdx ) 733 { 734 final Method method = methods[ methodIdx ]; 735 final String methodName = method.getName(); 736 737 if ( methodName.startsWith( "create" ) && ! methodName.endsWith( "Config" ) ) 738 { 739 if ( AMXConfig.class.isAssignableFrom( method.getReturnType() ) && 740 (! (proxy instanceof SecurityMapConfig)) ) 741 { 742 trace( "WARNING: method " + methodName + " does not end in 'Config': " + objectName ); 743 } 744 } 745 else if ( methodName.startsWith( "remove" ) && 746 ! methodName.endsWith( "Config" ) && 747 proxy instanceof AMXConfig ) 748 { 749 if ( method.getParameterTypes().length == 1 && 751 method.getParameterTypes()[ 0 ] == String .class && 752 ! method.getName().equals( "removeProperty" ) && 753 ! method.getName().equals( "removeSystemProperty" ) && 754 (! (proxy instanceof SecurityMapConfig)) ) 755 { 756 trace( "WARNING: method " + methodName + " does not end in 'Config': " + methodName ); 757 } 758 } 759 } 760 } 761 } 762 763 764 public void 765 testCreateRemoveGet() 766 throws Exception 767 { 768 testAll( "checkCreateRemoveGet" ); 769 } 770 771 777 public void 778 checkImplementsAMXConfig( final ObjectName objectName ) 779 throws Exception 780 { 781 final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class ); 782 final String interfaceName = Util.getExtra( proxy ).getInterfaceName(); 783 if ( interfaceName.endsWith( "Config" ) || interfaceName.endsWith( "ConfigMgr" ) ) 784 { 785 if ( !( proxy instanceof AMXConfig) ) 786 { 787 trace( "WARNING: " + ClassUtil.stripPackageName( interfaceName ) + " does not implement AMXConfig" ); 788 } 789 } 790 } 791 792 793 796 private boolean 797 ignoreCreateRemove( 798 final String j2eeType, 799 final String suggestedMethod ) 800 { 801 boolean ignore = false; 802 803 if ( j2eeType.equals( XTypes.DOMAIN_CONFIG ) ) 804 { 805 if ( suggestedMethod.equals( "createServerConfig" ) || 806 suggestedMethod.equals( "createWebModuleConfig" ) || 807 suggestedMethod.equals( "createEJBModuleConfig" ) || 808 suggestedMethod.equals( "createJ2EEApplicationConfig" ) || 809 suggestedMethod.equals( "createRARModuleConfig" ) || 810 suggestedMethod.equals( "createAppClientModuleConfig" ) || 811 suggestedMethod.equals( "createNodeAgentConfig" ) || 812 false 813 ) 814 { 815 ignore = true; 816 } 817 } 818 else if ( j2eeType.equals( XTypes.CLUSTERED_SERVER_CONFIG ) ) 819 { 820 if ( suggestedMethod.equals( "createDeployedItemRefConfig" ) || 821 suggestedMethod.equals( "createResourceRefConfig" ) 822 ) 823 { 824 ignore = true; 825 } 826 } 827 828 return( ignore ); 829 } 830 831 834 public void 835 checkMapsHaveCreateRemove( final ObjectName objectName ) 836 throws Exception 837 { 838 final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class ); 839 840 if ( proxy instanceof Container && proxy.getGroup().equals( AMX.GROUP_CONFIGURATION ) ) 841 { 842 final Extra extra = Util.getExtra( proxy ); 843 final String [] attrNames = extra.getAttributeNames(); 844 845 for( int i = 0; i < attrNames.length; ++i ) 846 { 847 final String name = attrNames[ i ]; 848 849 final String SUFFIX = "ObjectNameMap"; 850 final String PREFIX = JMXUtil.GET; 851 if ( name.endsWith( SUFFIX ) ) 852 { 853 final String base = StringUtil.stripPrefixAndSuffix( name, PREFIX, SUFFIX ); 854 final String createName = "create" + base; 855 final String removeName = "remove" + base; 856 857 final String j2eeType = proxy.getJ2EEType(); 858 if ( ignoreCreateRemove( proxy.getJ2EEType(), createName ) ) 859 { 860 continue; 861 } 862 863 final MBeanOperationInfo [] creates = 864 JMXUtil.findOperations( extra.getMBeanInfo().getOperations(), createName ); 865 boolean haveCreate = false; 866 for( int op = 0; op < creates.length; ++op ) 867 { 868 final MBeanOperationInfo info = creates[ op ]; 869 if ( info.getReturnType().equals( ObjectName .class.getName() ) ) 870 { 871 haveCreate = true; 872 break; 873 } 874 } 875 assert( haveCreate ) : 876 "Missing operation " + createName + "() for " + objectName; 877 878 final MBeanOperationInfo [] removes = 879 JMXUtil.findOperations( extra.getMBeanInfo().getOperations(), removeName ); 880 boolean haveRemove = false; 881 for( int op = 0; op < removes.length; ++op ) 882 { 883 final MBeanOperationInfo info = removes[ op ]; 884 if ( info.getReturnType().equals( "void" ) && 885 info.getSignature().length <= 2) 886 { 887 haveRemove = true; 888 break; 889 } 890 } 891 assert( haveRemove ) : 892 "Missing operation " + removeName + "() for " + objectName; 893 } 894 } 895 } 896 } 897 898 public void 899 testMapsHaveCreateRemove() 900 throws Exception 901 { 902 testAll( "checkMapsHaveCreateRemove" ); 903 } 904 905 906 public void 907 testImplementsAMXConfig() 908 throws Exception 909 { 910 testAll( "checkImplementsAMXConfig" ); 911 } 912 913 914 private static Set <Class > MON_IGNORE = GSetUtil.newUnmodifiableSet( new Class [] 915 { 916 JMXMonitorMgr.class, 917 AMXStringMonitor.class, 918 AMXCounterMonitor.class, 919 AMXGaugeMonitor.class, 920 921 EJBModuleMonitor.class, 922 HTTPServiceMonitor.class, 923 ApplicationMonitor.class, 924 } ); 925 926 933 public void 934 testImplementsAMXMonitoring() 935 throws Exception 936 { 937 final TypeInfos infos = TypeInfos.getInstance(); 938 939 final Iterator iter = infos.getJ2EETypes().iterator(); 940 while ( iter.hasNext() ) 941 { 942 final TypeInfo info = infos.getInfo( (String )iter.next() ); 943 final Class theInterface = info.getInterface(); 944 final String interfaceName = theInterface.getName(); 945 if ( ! MON_IGNORE.contains( theInterface ) ) 946 { 947 if ( interfaceName.endsWith( "Monitor" ) ) 948 { 949 if ( ! Monitoring.class.isAssignableFrom( theInterface ) ) 950 { 951 warning( ClassUtil.stripPackageName( interfaceName ) + " does not implement Monitoring" ); 952 } 953 } 954 else if ( interfaceName.endsWith( "MonitorMgr" ) ) 955 { 956 if ( ! Container.class.isAssignableFrom( theInterface ) ) 957 { 958 warning( ClassUtil.stripPackageName( interfaceName ) + " does not implement Container" ); 959 } 960 } 961 } 962 } 963 } 964 965 public void 966 testGetInterfaceName() 967 throws IOException , JMException 968 { 969 final Set <ObjectName > all = getQueryMgr().queryAllObjectNameSet(); 970 971 final MBeanServerConnection conn = 972 Util.getExtra( getDomainRoot() ).getConnectionSource().getExistingMBeanServerConnection(); 973 974 final Set <ObjectName > failedSet = new HashSet <ObjectName >(); 975 976 for( final ObjectName objectName : all ) 977 { 978 try 979 { 980 final String value = (String ) 981 conn.getAttribute( objectName, AMXAttributes.ATTR_INTERFACE_NAME ); 982 assert( value != null ); 983 value.toString(); 984 } 985 catch( AttributeNotFoundException e ) 986 { 987 warning( "Can't get InterfaceName for: " + objectName ); 988 failedSet.add( objectName ); 989 } 990 } 991 992 if ( failedSet.size() != 0 ) 993 { 994 warning( "The following MBeans did not return the Attribute InterfaceName:\n" + 995 CollectionUtil.toString( failedSet, "\n") ); 996 assert( false ); 997 throw new Error (); 998 } 999 } 1000 1001 1002 public void 1003 testInterfaceAgainstDelegate() 1004 throws Exception 1005 { 1006 final long start = now(); 1007 final Set <AMX> all = getAllAMX(); 1008 1009 final MBeanServerConnection conn = getMBeanServerConnection(); 1010 for( final AMX amx : all ) 1011 { 1012 1013 final String result = (String ) 1014 conn.invoke( Util.getObjectName( amx ), 1015 "checkInterfaceAgainstDelegate", null, null ); 1016 } 1017 1018 printElapsed( "testInterfaceAgainstDelegate", all.size(), start ); 1019 } 1020 1021 public void 1022 testMisc() 1023 { 1024 final long start = now(); 1025 final Set <AMX> all = getAllAMX(); 1026 1027 for( final AMX amx : all ) 1028 { 1029 amx.setMBeanLogLevel( amx.getMBeanLogLevel() ); 1030 1031 final ObjectName objectName = Util.getObjectName( amx ); 1032 assert( objectName.getKeyProperty( AMX.NAME_KEY ) != null ); 1033 assert( objectName.getKeyProperty( AMX.J2EE_TYPE_KEY ) != null ); 1034 } 1035 1036 printElapsed( "testMisc", all.size(), start ); 1037 } 1038 1039 1040 1041 public void 1042 testNoGoofyNames( 1043 final ObjectName objectName, 1044 final MBeanFeatureInfo [] featureInfos ) 1045 { 1046 final Set <String > goofy = new HashSet <String >(); 1047 1048 for( final MBeanFeatureInfo info : featureInfos ) 1049 { 1050 final String name = info.getName(); 1051 1052 if ( name.indexOf( "ObjectNameObjectName" ) >= 0 ) 1053 { 1054 goofy.add( name ); 1055 } 1056 } 1057 1058 if ( goofy.size() != 0 ) 1059 { 1060 assert( false ) : NEWLINE + 1061 "MBean " + objectName + " has the following goofy Attributes:" + NEWLINE + 1062 CollectionUtil.toString( goofy, NEWLINE ); 1063 } 1064 } 1065 1066 public void 1067 testNoGoofyNames() 1068 { 1069 final long start = now(); 1070 final Set <AMX> all = getAllAMX(); 1071 1072 for( final AMX amx : all ) 1073 { 1074 final ObjectName objectName = Util.getObjectName( amx ); 1075 final MBeanInfo mbeanInfo = Util.getExtra( amx ).getMBeanInfo(); 1076 1077 testNoGoofyNames( objectName, mbeanInfo.getAttributes() ); 1078 testNoGoofyNames( objectName, mbeanInfo.getOperations() ); 1079 } 1080 1081 printElapsed( "testNoGoofyNames", all.size(), start ); 1082 } 1083 1084 1085 public void 1086 testToString() 1087 { 1088 final long start = now(); 1089 final Set <AMX> all = getAllAMX(); 1090 1091 for( final AMX amx : all ) 1092 { 1093 final AMXDebugStuff debug = getTestUtil().asAMXDebugStuff( amx ); 1094 1095 if ( debug != null ) 1096 { 1097 final String s = debug.getImplString( true ); 1098 assert( s.length() != 0 ); 1099 } 1100 } 1101 1102 printElapsed( "testToString", all.size(), start ); 1103 } 1104} 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | Popular Tags |