1 23 package com.sun.enterprise.management.config; 24 25 import java.io.IOException ; 26 import java.util.Set ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 30 import javax.management.Attribute ; 31 32 33 import com.sun.appserv.management.base.DottedNames; 34 import com.sun.appserv.management.config.ConfigDottedNames; 35 import com.sun.appserv.management.monitor.MonitoringDottedNames; 36 import com.sun.appserv.management.util.stringifier.SmartStringifier; 37 38 39 import com.sun.enterprise.management.AMXTestBase; 40 import com.sun.enterprise.management.Capabilities; 41 42 44 public final class DottedNamesTest extends AMXTestBase 45 { 46 public 47 DottedNamesTest( ) 48 { 49 } 50 51 private void 52 checkAttribute( final Attribute attr ) 53 { 54 assert( attr != null ); 55 56 final Object value = attr.getValue(); 57 if ( value instanceof Attribute ) 58 { 59 warning( "Is value of " + attr.getName() + " really another Attribute? => " + 60 toString( value ) ); 61 } 62 } 63 64 private void 65 checkResultsFromWildGet( 66 final Object [] results ) 67 { 68 for( int i = 0; i < results.length; ++i ) 69 { 70 final Object result = results[ i ]; 71 72 if ( result == null ) 73 { 74 warning( "null result from dottedNameGet( \"*\" )" ); 75 } 76 else if ( ! (result instanceof Attribute ) ) 77 { 78 warning( "non-Attribute result from dottedNameGet( \"*\" ): " + result ); 79 } 80 else 81 { 82 final Attribute attr = (Attribute )result; 84 checkAttribute( (Attribute )result ); 85 } 86 } 87 } 88 89 private void 90 checkResultsFromGet( 91 final String [] names, 92 final Object [] results ) 93 { 94 for( int i = 0; i < results.length; ++i ) 95 { 96 final Object result = results[ i ]; 97 98 if ( result == null ) 99 { 100 warning( "Dotted name has null result: " + names[ i ] ); 101 } 102 else if ( ! (result instanceof Attribute ) ) 103 { 104 warning( "Dotted name " + names[ i ] + " could not be obtained: " + result ); 105 } 106 } 107 } 108 109 private String [] 110 getAllNames( final DottedNames dottedNames ) 111 { 112 final Attribute [] attrs = (Attribute [])dottedNames.dottedNameGet( "*" ); 113 final String [] names = new String [ attrs.length ]; 114 for( int i = 0; i < names.length; ++i ) 115 { 116 names[ i ] = attrs[ i ].getName(); 117 } 118 119 return( names ); 120 } 121 122 123 public void 124 testGetAllConfigDottedNames() 125 { 126 final long start = now(); 127 final ConfigDottedNames dottedNames = getDomainRoot().getConfigDottedNames(); 128 129 final String [] names = getAllNames( dottedNames ); 130 131 final Object [] results = dottedNames.dottedNameGet( names ); 132 133 checkResultsFromGet( names, results ); 134 printElapsed( "testGetAllConfigDottedNames", start ); 135 } 136 137 public void 138 testGetAllMonitoringDottedNames() 139 { 140 if ( checkNotOffline( "testMonitoringRefresh" ) ) 141 { 142 final MonitoringDottedNames dottedNames = getDomainRoot().getMonitoringDottedNames(); 143 final long start = now(); 144 final String [] names = getAllNames( dottedNames ); 145 146 final Object [] results = dottedNames.dottedNameGet( names ); 147 148 checkResultsFromGet( names, results ); 149 printElapsed( "testGetAllMonitoringDottedNames", start ); 150 } 151 } 152 153 public void 154 testWildGetAllConfigDottedNames() 155 { 156 final long start = now(); 157 final ConfigDottedNames dottedNames = getDomainRoot().getConfigDottedNames(); 158 159 final Attribute [] results = (Attribute [])dottedNames.dottedNameGet( "*" ); 160 checkResultsFromWildGet( results ); 161 printElapsed( "testWildGetAllConfigDottedNames", start ); 162 } 163 164 165 public void 166 testWildGetAllMonitoringDottedNames() 167 { 168 if ( checkNotOffline( "testMonitoringRefresh" ) ) 169 { 170 final long start = now(); 171 final MonitoringDottedNames dottedNames = getDomainRoot().getMonitoringDottedNames(); 172 final Attribute [] results = (Attribute [])dottedNames.dottedNameGet( "*" ); 173 checkResultsFromWildGet( results ); 174 printElapsed( "testWildGetAllMonitoringDottedNames", start ); 175 } 176 } 177 178 181 public void 182 testConfigDottedNameSet() 183 { 184 final long start = now(); 185 186 final ConfigDottedNames dottedNames = getDomainRoot().getConfigDottedNames(); 187 188 final String target = "domain.locale"; 189 final Object result = dottedNames.dottedNameGet( target ); 190 191 final Attribute localeAttr = (Attribute )dottedNames.dottedNameGet( target ); 192 checkAttribute( localeAttr ); 193 194 final String locale = (String )localeAttr.getValue(); 195 196 Object [] results = dottedNames.dottedNameSet( new String [] { target + "=dummy_locale" } ); 198 assert( results.length == 1 ); 199 checkAttribute( (Attribute )results[ 0 ] ); 200 201 final String restoreString = target + "=" + (locale == null ? "" : locale); 203 results = dottedNames.dottedNameSet( new String [] { restoreString } ); 204 205 final Attribute finalAttr = (Attribute )dottedNames.dottedNameGet( target ); 206 assert( (finalAttr.getValue() == null && localeAttr.getValue() == null) || 207 finalAttr.getValue().equals( localeAttr.getValue() ) ); 208 printElapsed( "testConfigDottedNameSet", start ); 209 } 210 211 public void 212 testConfigRefresh() 213 { 214 final long start = now(); 215 getDomainRoot().getConfigDottedNames().refresh(); 216 printElapsed( "testConfigRefresh", start ); 217 } 218 219 public void 220 testMonitoringRefresh() 221 { 222 if ( checkNotOffline( "testMonitoringRefresh" ) ) 223 { 224 final MonitoringDottedNames dottedNames = getDomainRoot().getMonitoringDottedNames(); 225 226 final long start = now(); 227 dottedNames.refresh(); 228 printElapsed( "testMonitoringRefresh", start ); 229 } 230 } 231 232 private int 233 testList( final DottedNames dottedNames, final String dottedName ) 234 { 235 final Object [] results = dottedNames.dottedNameList( new String [] { dottedName } ); 236 237 for( int i = 0; i < results.length; ++i ) 239 { 240 testList( dottedNames, (String )results[ i ] ); 241 } 242 243 return( results.length ); 244 } 245 246 public void 247 testRecursiveConfigDottedNameList() 248 { 249 final long start = now(); 250 final ConfigDottedNames dottedNames = getDomainRoot().getConfigDottedNames(); 251 252 final int numFound = testList( dottedNames, "domain" ); 253 assert( numFound >= 4 ); printElapsed( "testRecursiveConfigDottedNameList", start ); 255 } 256 257 public void 258 testRecursiveMonitoringDottedNameList() 259 { 260 if ( checkNotOffline( "testRecursiveMonitoringDottedNameList" ) ) 261 { 262 final MonitoringDottedNames dottedNames = getDomainRoot().getMonitoringDottedNames(); 263 264 final long start = now(); 265 266 final int numFound = testList( dottedNames, "server" ); 267 assert( numFound >= 4 ); 269 testList( dottedNames, "*" ); 270 271 printElapsed( "testRecursiveMonitoringDottedNameList", start ); 272 } 273 } 274 } 275 276 277 278 279 280 281 282 283 284 285 286 | Popular Tags |