1 23 package com.sun.enterprise.management.base; 24 25 import java.util.Set ; 26 import java.util.HashSet ; 27 28 import javax.management.ObjectName ; 29 import javax.management.MBeanServerConnection ; 30 import javax.management.AttributeList ; 31 import javax.management.MBeanInfo ; 32 import javax.management.MBeanAttributeInfo ; 33 import javax.management.MBeanOperationInfo ; 34 35 import com.sun.appserv.management.util.jmx.JMXUtil; 36 37 import com.sun.appserv.management.util.misc.GSetUtil; 38 import com.sun.appserv.management.util.misc.ArrayUtil; 39 import com.sun.appserv.management.util.misc.CollectionUtil; 40 import com.sun.appserv.management.base.AMXAttributes; 41 42 43 import com.sun.enterprise.management.AMXTestBase; 44 import com.sun.enterprise.management.Capabilities; 45 46 48 public final class BulkAccessTest extends AMXTestBase 49 { 50 public 51 BulkAccessTest( ) 52 { 53 } 54 public static Capabilities 55 getCapabilities() 56 { 57 return getOfflineCapableCapabilities( true ); 58 } 59 60 61 public void 62 testGetBulkAccess() 63 { 64 assert( getBulkAccess() != null ); 65 } 66 67 public void 68 testBulkGetMBeanAttributeInfos() 69 throws Exception 70 { 71 final long start = now(); 72 73 final ObjectName [] objectNames = getTestUtil().getAllAMXArray(); 74 75 final Object [] infos = 77 getBulkAccess().bulkGetMBeanAttributeInfo( objectNames ); 78 79 final MBeanServerConnection conn = getConnection(); 81 for( int i = 0; i < infos.length; ++i ) 82 { 83 84 final MBeanAttributeInfo [] bulkAttributes = (MBeanAttributeInfo [])infos[ i ]; 85 86 final MBeanInfo info = conn.getMBeanInfo( objectNames[ i ] ); 87 assert( ArrayUtil.arraysEqual( info.getAttributes(), bulkAttributes ) ); 88 } 89 printElapsed( "testBulkGetMBeanAttributeInfos", objectNames.length, start ); 90 } 91 92 public void 93 testBulkGetMBeanOperationInfos() 94 throws Exception 95 { 96 final long start = now(); 97 98 final ObjectName [] objectNames = getTestUtil().getAllAMXArray(); 99 100 final Object [] infos = 101 getBulkAccess().bulkGetMBeanOperationInfo( objectNames ); 102 103 final MBeanServerConnection conn = getConnection(); 105 for( int i = 0; i < infos.length; ++i ) 106 { 107 108 final MBeanOperationInfo [] bulkOperations = (MBeanOperationInfo [])infos[ i ]; 109 110 final MBeanInfo info = conn.getMBeanInfo( objectNames[ i ] ); 111 assert( ArrayUtil.arraysEqual( info.getOperations(), bulkOperations ) ); 112 } 113 printElapsed( "testBulkGetMBeanOperationInfos", objectNames.length, start ); 114 } 115 116 public void 117 testAttributeNamesAttributeCorrect() 118 throws Exception 119 { 120 final long start = now(); 121 122 final ObjectName [] objectNames = getTestUtil().getAllAMXArray(); 123 124 final Object [] nameArrays = 125 getBulkAccess().bulkGetAttributeNames( objectNames ); 126 127 final Set <ObjectName > failed = new HashSet <ObjectName >(); 128 for( int i = 0; i < nameArrays.length; ++i ) 130 { 131 final String [] bulkNames = (String [])nameArrays[ i ]; 132 133 final String [] attrNames = (String []) 135 getConnection().getAttribute( objectNames[ i ], "AttributeNames" ); 136 137 final Set <String > bulkSet = GSetUtil.newStringSet( bulkNames ); 138 final Set <String > attrsSet = GSetUtil.newStringSet( attrNames ); 139 if (! bulkSet.equals( attrsSet ) ) 140 { 141 warning( "testAttributeNamesAttributeCorrect failed for " + objectNames[ i ] ); 142 failed.add( objectNames[ i ] ); 143 } 144 } 145 146 if ( failed.size() != 0 ) 147 { 148 assert false : "Failures: " + NEWLINE + CollectionUtil.toString( failed, NEWLINE ); 149 } 150 151 printElapsed( "testAttributeNamesAttributeCorrect", objectNames.length, start ); 152 } 153 154 public void 155 testBulkGetMBeanAttributeNames() 156 throws Exception 157 { 158 final long start = now(); 159 160 final ObjectName [] objectNames = getTestUtil().getAllAMXArray(); 161 162 final Object [] nameArrays = 163 getBulkAccess().bulkGetAttributeNames( objectNames ); 164 165 for( int i = 0; i < nameArrays.length; ++i ) 166 { 167 final String [] bulkNames = (String [])nameArrays[ i ]; 168 169 final MBeanInfo info = 170 getConnection().getMBeanInfo( objectNames[ i ] ); 171 172 final String [] names = 173 JMXUtil.getAttributeNames( info.getAttributes() ); 174 175 assert( ArrayUtil.arraysEqual( names, bulkNames ) ); 176 } 177 178 printElapsed( "testBulkGetMBeanAttributeNames", objectNames.length, start ); 179 } 180 181 public void 182 testBulkGetAttribute() 183 throws Exception 184 { 185 final long start = now(); 186 187 final String attrName = AMXAttributes.ATTR_OBJECT_NAME; 188 final ObjectName [] objectNames = getTestUtil().getAllAMXArray(); 189 190 final Object [] values = 191 getBulkAccess().bulkGetAttribute( objectNames, attrName ); 192 193 final MBeanServerConnection conn = getConnection(); 194 for( int i = 0; i < objectNames.length; ++i ) 195 { 196 final Object value = conn.getAttribute( objectNames[ i ], attrName ); 197 198 assertEquals( values[ i ], value ); 199 } 200 201 printElapsed( "testBulkGetAttribute", objectNames.length, start ); 202 } 203 204 205 public void 206 testBulkGetAttributes() 207 throws Exception 208 { 209 final long start = now(); 210 211 final String [] attrNames = new String [] { 212 "FullType", "Group", "Name", "DomainRootObjectName", "ContainerObjectName" }; 213 final ObjectName [] objectNames = getTestUtil().getAllAMXArray(); 214 215 final Object [] values = 216 getBulkAccess().bulkGetAttributes( objectNames, attrNames ); 217 218 final MBeanServerConnection conn = getConnection(); 219 for( int i = 0; i < objectNames.length; ++i ) 220 { 221 final AttributeList bulkAttrs = (AttributeList )values[ i ]; 222 223 final AttributeList attrs = (AttributeList )conn.getAttributes( objectNames[ i ], attrNames ); 224 225 assertEquals( bulkAttrs, attrs ); 226 } 227 printElapsed( "testBulkGetAttributes", objectNames.length, start ); 228 } 229 230 } 231 232 233 | Popular Tags |