1 23 package com.sun.enterprise.management.base; 24 25 import java.util.Set ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 29 import java.io.IOException ; 30 31 import javax.management.ObjectName ; 32 import javax.management.MBeanServerConnection ; 33 import javax.management.MBeanException ; 34 import javax.management.AttributeNotFoundException ; 35 import javax.management.InstanceNotFoundException ; 36 import javax.management.JMException ; 37 38 39 import com.sun.appserv.management.DomainRoot; 40 import com.sun.appserv.management.base.AMX; 41 import com.sun.appserv.management.base.AMXAttributes; 42 import com.sun.appserv.management.base.QueryMgr; 43 import com.sun.appserv.management.base.Util; 44 import com.sun.appserv.management.base.XTypes; 45 46 import com.sun.appserv.management.util.jmx.JMXUtil; 47 48 import com.sun.appserv.management.util.misc.GSetUtil; 49 import com.sun.appserv.management.util.misc.CollectionUtil; 50 51 import com.sun.appserv.management.util.stringifier.SmartStringifier; 52 53 54 55 import com.sun.enterprise.management.AMXTestBase; 56 import com.sun.enterprise.management.Capabilities; 57 58 60 public final class QueryMgrTest extends AMXTestBase 61 { 62 final QueryMgr mQM; 63 64 public 65 QueryMgrTest( ) 66 { 67 mQM = getQueryMgr(); 68 } 69 public static Capabilities 70 getCapabilities() 71 { 72 return getOfflineCapableCapabilities( true ); 73 } 74 75 76 private <T> void 77 checkSetsEqual( 78 final String msg, 79 final Set <T> set1, 80 final Set <T> set2 ) 81 { 82 if ( ! set1.equals( set2 ) ) 83 { 84 final Set <T> conflict = GSetUtil.newNotCommonSet( set1, set2 ); 85 final String values = CollectionUtil.toString( conflict, "\n" ); 86 failure( msg + ", mismatch =\n" + values ); 87 } 88 } 89 90 91 private void 92 checkAMXWithObjectNames( 93 final String msg, 94 final Set <AMX> set1, 95 final Set <ObjectName > set2 ) 96 { 97 if ( set1.size() != set2.size() ) 98 { 99 failure( msg + "set sizes don't match: " + set1.size() + " != " + set2.size() ); 100 } 101 102 final Set <ObjectName > set1ObjectNames = new HashSet <ObjectName >(); 103 for( final AMX item : set1 ) 104 { 105 final ObjectName objectName = Util.getObjectName( item ); 106 107 if ( set1ObjectNames.contains( objectName ) ) 108 { 109 failure( "set1 contains the same proxy twice with ObjectName: " + objectName ); 110 } 111 set1ObjectNames.add( objectName ); 112 } 113 114 checkSetsEqual( msg, set1ObjectNames, set2 ); 115 } 116 117 118 public void 119 testQueryJ2EETypePvsON() 120 throws ClassNotFoundException 121 { 122 final long start = now(); 123 124 final String testType1 = XTypes.DOMAIN_CONFIG; 125 checkAMXWithObjectNames( 126 "queryJ2EETypeSet(XTypes.DOMAIN_CONFIG) != queryJ2EETypeObjectNameSet(XTypes.DOMAIN_CONFIG)", 127 mQM.queryJ2EETypeSet( testType1 ), 128 mQM.queryJ2EETypeObjectNameSet( testType1 ) ); 129 printElapsed( "testObjectNameVersusProxy", start ); 130 } 131 132 public void 133 testQueryJ2EENamePvsON() 134 throws ClassNotFoundException 135 { 136 final long start = now(); 137 138 final String name = getDomainRoot().getName(); 139 checkAMXWithObjectNames( 140 "queryJ2EENameSet() != queryJ2EENameObjectNameSet()", 141 mQM.queryJ2EENameSet( name ), 142 mQM.queryJ2EENameObjectNameSet( name ) ); 143 printElapsed( "testObjectNameVersusProxy", start ); 144 } 145 146 public void 147 testQueryPatternPvsON() 148 throws ClassNotFoundException 149 { 150 final long start = now(); 151 152 final String domain = Util.getObjectName( mQM ).getDomain(); 153 final ObjectName pat = JMXUtil.newObjectNamePattern( domain, "*" ); 154 checkAMXWithObjectNames( 155 "queryPatternSet() != queryPatternObjectNameSet()", 156 mQM.queryPatternSet( pat ), 157 mQM.queryPatternObjectNameSet( pat ) ); 158 159 checkAMXWithObjectNames( 160 "queryPatternSet() != queryPatternObjectNameSet()", 161 mQM.queryPatternSet( domain, "*" ), 162 mQM.queryPatternObjectNameSet( domain, "*" ) ); 163 printElapsed( "testObjectNameVersusProxy", start ); 164 } 165 166 public void 167 testQueryPropsPvsON() throws ClassNotFoundException 168 { 169 final long start = now(); 170 171 final String domain = Util.getObjectName( mQM ).getDomain(); 172 final String props = Util.makeRequiredProps( XTypes.DOMAIN_ROOT, domain ); 173 checkAMXWithObjectNames( 174 "queryPropsSet() != queryPropsObjectNameSet()", 175 mQM.queryPropsSet( props ), 176 mQM.queryPropsObjectNameSet( props ) ); 177 printElapsed( "testObjectNameVersusProxy", start ); 178 } 179 180 public void 181 testQueryWildPvsON() 182 { 183 final long start = now(); 184 185 final String [] wildNames = new String [] { "*" }; 186 final String [] wildValues = new String [] { "*" }; 187 checkAMXWithObjectNames( 188 "queryWildSet() != queryWildObjectNameSet()", 189 mQM.queryWildSet( wildNames, wildValues ), 190 mQM.queryWildObjectNameSet( wildNames, wildValues ) ); 191 printElapsed( "testObjectNameVersusProxy", start ); 192 } 193 194 public void 195 testQueryInterfacePvsON() 196 throws ClassNotFoundException 197 { 198 final long start = now(); 199 200 final Set <AMX> candidates = mQM.queryAllSet(); 201 final Set <ObjectName > candidateObjectNames = Util.toObjectNames( candidates ); 202 final String interfaceName = DomainRoot.class.getName(); 203 checkAMXWithObjectNames( 204 "queryInterfaceSet() != queryInterfaceObjectNameSet()", 205 mQM.queryInterfaceSet( interfaceName, candidateObjectNames ), 206 mQM.queryInterfaceObjectNameSet( interfaceName, candidateObjectNames ) ); 207 printElapsed( "testObjectNameVersusProxy", start ); 208 } 209 210 public void 211 testQueryAll_AMXMatchesObjectName() 212 throws ClassNotFoundException 213 { 214 final long start = now(); 215 216 final Set <AMX> allSet = mQM.queryAllSet(); 217 final Set <ObjectName > allObjectNameSet = mQM.queryAllObjectNameSet(); 218 219 assert( allSet.size() == allObjectNameSet.size() ); 220 221 checkAMXWithObjectNames( 222 "queryAllSet() != queryAllObjectNameSet()", 223 allSet, allObjectNameSet ); 224 225 printElapsed( "testObjectNameVersusProxy", start ); 226 } 227 228 229 public void 230 testGetQueryMgr() 231 { 232 assert( getQueryMgr() != null ); 233 } 234 235 public void 236 testQueryAll() 237 { 238 final long start = now(); 239 final Set result = getQueryMgr().queryAllSet(); 240 241 assert( result.size() > 1 ); 242 243 printElapsed( "testQueryAll", start ); 244 } 245 246 public void 247 testGetJ2EETypeObjectNames() 248 throws Exception 249 { 250 final long start = now(); 251 252 final Set <String > j2eeTypes = getTestUtil().getAvailJ2EETypes(); 253 for( final String j2eeType : j2eeTypes ) 254 { 255 final Set <AMX> results = 256 getQueryMgr().queryJ2EETypeSet(j2eeType ); 257 assert( results.size() >= 1 ); 258 } 259 260 printElapsed( "testGetJ2EETypeObjectNames", start ); 261 } 262 263 public void 264 testGetJ2EETypeProxies() 265 throws Exception 266 { 267 final long start = now(); 268 final Set <String > j2eeTypes = getTestUtil().getAvailJ2EETypes(); 269 270 for( final String j2eeType : j2eeTypes ) 271 { 272 final Set <AMX> proxies = 273 getQueryMgr().queryJ2EETypeSet( j2eeType ); 274 275 assert( proxies != null ); 276 } 277 278 printElapsed( "testGetJ2EETypeProxies", start ); 279 } 280 281 public void 282 testQueryPatternProxies() 283 throws Exception 284 { 285 final long start = now(); 286 287 final Set proxies = getQueryMgr().queryPropsSet( "*" ); 288 289 assert proxies != null; 290 291 printElapsed( "testQueryPatternProxies", start ); 292 } 293 294 private <T extends AMX> Set <String > 295 getAllInterfaceNames( final Set <T> amxSet ) 296 { 297 final Set <String > interfaceNames = new HashSet <String >(); 298 for( final T amx : amxSet ) 299 { 300 interfaceNames.add( Util.getExtra( amx ).getInterfaceName() ); 301 } 302 303 return( interfaceNames ); 304 } 305 306 311 public void 312 testQueryInterfaceObjectNames( ) 313 throws Exception 314 { 315 final long start = now(); 316 317 final QueryMgr queryMgr = getQueryMgr(); 318 final Set <AMX> allAMX = getQueryMgr().queryAllSet(); 319 final Set <ObjectName > allAMXObjectNames = Util.toObjectNames( allAMX ); 320 final Set <String > interfaceNames = getAllInterfaceNames( allAMX ); 321 322 for( final String interfaceName : interfaceNames ) 323 { 324 final Set amxs = queryMgr.queryInterfaceSet( interfaceName, allAMXObjectNames ); 325 326 final Iterator amxIter = amxs.iterator(); 327 while ( amxIter.hasNext() ) 328 { 329 final AMX amx = Util.asAMX(amxIter.next()); 330 assert( interfaceName.equals( Util.getExtra( amx ).getInterfaceName() ) ); 331 } 332 } 333 334 printElapsed( "testQueryInterfaceObjectNames", start ); 335 } 336 337 338 } 339 340 341 342 343 344 345 | Popular Tags |