1 23 24 29 package com.sun.enterprise.management.client; 30 31 import java.util.Set ; 32 import java.util.HashSet ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 import java.util.ArrayList ; 36 import java.io.IOException ; 37 38 import java.lang.reflect.Method ; 39 40 import javax.management.ObjectName ; 41 import javax.management.AttributeList ; 42 import javax.management.MBeanServerConnection ; 43 import javax.management.NotCompliantMBeanException ; 44 import javax.management.AttributeNotFoundException ; 45 import javax.management.InstanceNotFoundException ; 46 47 import com.sun.appserv.management.j2ee.J2EEDomain; 48 49 import com.sun.appserv.management.client.ProxyFactory; 50 import com.sun.appserv.management.base.Container; 51 import com.sun.appserv.management.config.Description; 52 import com.sun.appserv.management.base.XTypes; 53 import com.sun.appserv.management.DomainRoot; 54 import com.sun.appserv.management.base.QueryMgr; 55 import com.sun.appserv.management.base.AMX; 56 import com.sun.appserv.management.base.Util; 57 import com.sun.appserv.management.config.ResourceRefConfig; 58 import com.sun.appserv.management.config.DeployedItemRefConfig; 59 import com.sun.appserv.management.config.ResourceConfig; 60 import com.sun.enterprise.management.support.TypeInfos; 61 import com.sun.enterprise.management.support.TypeInfo; 62 63 import com.sun.appserv.management.util.jmx.JMXUtil; 64 import com.sun.appserv.management.util.misc.ExceptionUtil; 65 import com.sun.appserv.management.util.misc.StringUtil; 66 import com.sun.appserv.management.util.misc.ClassUtil; 67 import com.sun.appserv.management.util.stringifier.CollectionStringifier; 68 69 70 71 import com.sun.enterprise.management.AMXTestBase; 72 import com.sun.enterprise.management.Capabilities; 73 74 76 public final class ProxyTest extends AMXTestBase 77 { 78 public 79 ProxyTest( ) 80 { 81 } 82 public static Capabilities 83 getCapabilities() 84 { 85 return getOfflineCapableCapabilities( false ); 86 } 87 88 89 public void 90 checkCreateProxy( final ObjectName src ) 91 throws Exception 92 { 93 final AMX proxy = getProxyFactory().getProxy( src, AMX.class); 94 95 Util.getObjectName( proxy ); 96 proxy.getContainer(); 97 proxy.getDomainRoot(); 98 } 99 100 public void 101 testCreateAllProxies() 102 throws Exception 103 { 104 testAll( "checkCreateProxy" ); 105 } 106 107 public void 108 checkProxiesCached( final ObjectName src ) 109 throws Exception 110 { 111 final AMX proxy = getProxyFactory().getProxy( src, AMX.class); 112 113 assert( proxy == getProxyFactory().getProxy( src, AMX.class) ); 114 assert( proxy.getContainer() == proxy.getContainer() ); 115 assert( proxy.getDomainRoot() == proxy.getDomainRoot() ); 116 117 final Class interfaceClass = getInterfaceClass( proxy ); 118 final Method [] proxyMethods = interfaceClass.getMethods(); 119 120 for( int methodIdx = 0; methodIdx < proxyMethods.length; ++methodIdx ) 121 { 122 final Method method = proxyMethods[ methodIdx ]; 123 final String methodName = method.getName(); 124 125 if ( isProxyGetter( method ) ) 126 { 127 method.invoke( proxy, (Object [])null ); 130 } 131 } 132 } 133 134 public void 135 testProxiesCached() 136 throws Exception 137 { 138 testAll( "checkProxiesCached" ); 139 } 140 141 142 143 144 private boolean 145 isProxyGetter( final Method method ) 146 { 147 return( method.getName().startsWith( JMXUtil.GET ) && 148 method.getParameterTypes().length == 0 && 149 AMX.class.isAssignableFrom( method.getReturnType() ) ); 150 } 151 152 private boolean 153 isChildProxyGetter( final Method method ) 154 { 155 final Class [] paramTypes = method.getParameterTypes(); 156 157 return( paramTypes.length == 1 && 158 paramTypes[ 0 ] == String .class && 159 AMX.class.isAssignableFrom( method.getReturnType() ) ); 160 } 161 162 private boolean 163 isProxiesGetter( final Method method ) 164 { 165 return( method.getParameterTypes().length == 0 && 166 Set .class.isAssignableFrom( method.getReturnType() ) ); 167 } 168 169 170 private String 171 getProxyGetterName( final String getterName ) 172 { 173 final int baseLength = getterName.length() - "ObjectName".length(); 174 final String baseName = getterName.substring( 0, baseLength ); 175 176 return( baseName + "Proxy" ); 177 } 178 179 180 public void 181 testProxyInterfaceIsAMX() 182 throws Exception 183 { 184 final long start = now(); 185 final TypeInfos infos = TypeInfos.getInstance(); 186 187 final Iterator iter = infos.getJ2EETypes().iterator(); 188 while ( iter.hasNext() ) 189 { 190 final TypeInfo info = infos.getInfo( (String )iter.next() ); 191 final Class proxyClass = info.getInterface(); 192 193 if ( ! AMX.class.isAssignableFrom( proxyClass ) ) 194 { 195 warning( "Proxy interface does not extend AMX: " + proxyClass.getName() ); 196 } 197 } 198 printElapsed( "testProxyInterfaceNameConsistent", start ); 199 } 200 201 public void 202 testProxyInterfaceNameConsistent() 203 throws Exception 204 { 205 final long start = now(); 206 207 final TypeInfos infos = TypeInfos.getInstance(); 208 209 final Iterator iter = infos.getJ2EETypes().iterator(); 210 while ( iter.hasNext() ) 211 { 212 final TypeInfo info = infos.getInfo( (String )iter.next() ); 213 214 final Class proxyClass = info.getInterface(); 215 216 217 if ( proxyClass.getName().endsWith( "ResourceConfigProxy" ) ) 218 { 219 if ( proxyClass.getName().endsWith( "ConnectorConnectionPoolConfigProxy" ) ) 220 { 221 } 223 else if ( ! ResourceConfig.class.isAssignableFrom( proxyClass ) ) 224 { 225 warning( "Proxy interface does not extend ResourceConfigProxy: " + 226 proxyClass.getName() ); 227 } 228 } 229 230 if ( proxyClass.getName().endsWith( "ResourceRefConfigProxy" ) ) 231 { 232 if ( ! ResourceRefConfig.class.isAssignableFrom( proxyClass ) ) 233 { 234 warning( "Proxy interface does not extend ResourceRefConfigProxy: " + 235 proxyClass.getName() ); 236 } 237 } 238 239 if ( proxyClass.getName().endsWith( "DeployedItemRefConfig" ) ) 240 { 241 if ( ! DeployedItemRefConfig.class.isAssignableFrom( proxyClass ) ) 242 { 243 trace( "Proxy interface does not extend DeployedItemRefConfig: " + 244 proxyClass.getName() ); 245 } 246 } 247 } 248 printElapsed( "testProxyInterfaceNameConsistent", start ); 249 } 250 251 254 public void 255 testProxyGetters( final AMX proxy ) 256 throws ClassNotFoundException 257 { 258 final Method [] methods = getInterfaceClass( proxy ).getMethods(); 259 260 final List <Method > failedMethods = new ArrayList <Method >(); 261 final List <Throwable > exceptions = new ArrayList <Throwable >(); 262 263 final long start = now(); 264 265 for( int methodIdx = 0; methodIdx < methods.length; ++methodIdx ) 266 { 267 final Method method = methods[ methodIdx ]; 268 final String methodName = method.getName(); 269 final Class [] parameterTypes = method.getParameterTypes(); 270 271 if ( methodName.startsWith( JMXUtil.GET ) && parameterTypes.length == 0 ) 272 { 273 try 274 { 275 final Object result = method.invoke( proxy, (Object [])null ); 276 } 278 catch( Throwable t ) 279 { 280 final ObjectName objectName = Util.getObjectName( proxy ); 281 if ( isRemoteIncomplete( objectName ) ) 282 { 283 trace( "remoteIncomplete: " + objectName ); 284 } 285 else 286 { 287 trace( "failure: " + methodName + " = " + t.getClass().getName() ); 288 failedMethods.add( method ); 289 exceptions.add( t ); 290 } 291 } 292 } 293 } 294 final long elapsed = now() - start; 295 297 if ( failedMethods.size() != 0 ) 298 { 299 final int numFailed = failedMethods.size(); 300 301 trace( "\nMBean \"" + Util.getObjectName( proxy ) + "\" failed for:" ); 302 for( int i = 0; i < numFailed; ++i ) 303 { 304 final Method m = (Method )failedMethods.get( i ); 305 final Throwable t = (Throwable )exceptions.get( i ); 306 307 final Throwable rootCause = ExceptionUtil.getRootCause( t ); 308 final String rootTrace = ExceptionUtil.getStackTrace( rootCause ); 309 final Class rootCauseClass = rootCause.getClass(); 310 311 trace( "testProxyGetters: failure from: " + m.getName() + ": " + rootCauseClass.getName() ); 312 if ( rootCauseClass != AttributeNotFoundException .class ) 313 { 314 trace( rootTrace + "\n" ); 315 } 316 } 317 } 318 } 319 320 public void 321 testAllGetters() 322 throws Exception 323 { 324 final long start = now(); 325 326 final Set <AMX> proxies = getAllAMX(); 327 for( final AMX amx : proxies ) 328 { 329 testProxyGetters( amx ); 330 } 331 332 printElapsed( "testAllGetters", start ); 333 } 334 335 336 public void 337 testQueryMgr() 338 throws Exception 339 { 340 final QueryMgr proxy = (QueryMgr)getQueryMgr(); 341 Util.getObjectName( proxy ); 342 proxy.getContainer(); 343 proxy.getDomainRoot(); 344 } 345 346 public void 347 testDomainRootCachedProxies() 348 throws Exception 349 { 350 final DomainRoot root = (DomainRoot)getDomainRoot(); 351 352 assert( root.getJ2EEDomain() == root.getJ2EEDomain() ); 353 assert( root.getDomainConfig() == root.getDomainConfig() ); 354 assert( root.getQueryMgr() == root.getQueryMgr() ); 355 assert( root.getBulkAccess() == root.getBulkAccess() ); 356 assert( root.getUploadDownloadMgr() == root.getUploadDownloadMgr() ); 357 assert( root.getConfigDottedNames() == root.getConfigDottedNames() ); 358 assert( root.getMonitoringDottedNames() == root.getMonitoringDottedNames() ); 359 360 assert( root.getJ2EEDomain() == root.getJ2EEDomain() ); 361 } 362 363 368 public void 369 testProxyTime() 370 throws Exception 371 { 372 final DomainRoot root = (DomainRoot)getDomainRoot(); 373 374 final long start = now(); 375 for( int i = 0; i < 5; ++i ) 376 { 377 root.getContainer(); 378 root.getDomainRoot(); 379 380 root.getJ2EEDomain(); 381 root.getDomainConfig(); 382 root.getQueryMgr(); 383 root.getBulkAccess(); 384 root.getUploadDownloadMgr(); 385 root.getConfigDottedNames(); 386 root.getMonitoringDottedNames(); 387 root.getDeploymentMgr(); 388 } 389 final long elapsed = now() - start; 390 391 assert( elapsed < 300 * 10 ); 393 } 394 } 395 396 397 398 399 400 | Popular Tags |