1 23 24 29 package com.sun.enterprise.management.config; 30 31 import java.util.Map ; 32 import java.util.Collections ; 33 import java.io.Serializable ; 34 35 import java.io.IOException ; 36 import java.io.Serializable ; 37 import java.lang.reflect.Method ; 38 39 import javax.management.ObjectName ; 40 import javax.management.AttributeList ; 41 import javax.management.MBeanServerConnection ; 42 import javax.management.Notification ; 43 import javax.management.NotificationListener ; 44 45 import com.sun.appserv.management.util.jmx.JMXUtil; 46 import com.sun.appserv.management.util.misc.ExceptionUtil; 47 import com.sun.appserv.management.util.misc.ClassUtil; 48 import com.sun.appserv.management.util.misc.MapUtil; 49 50 import com.sun.appserv.management.base.AMX; 51 import com.sun.appserv.management.base.Container; 52 import com.sun.appserv.management.base.Util; 53 54 import com.sun.appserv.management.config.AMXConfig; 55 56 import com.sun.appserv.management.client.ProxyFactory; 57 58 59 import com.sun.enterprise.management.AMXTestBase; 60 import com.sun.enterprise.management.Capabilities; 61 import com.sun.enterprise.management.CreateRemoveListener; 62 63 65 public abstract class ConfigMgrTestBase extends AMXTestBase 66 { 67 protected 68 ConfigMgrTestBase() 69 { 70 super(); 71 } 72 73 74 protected String 75 getProgenyTestName() 76 { 77 return( "test-" + ClassUtil.stripPackageName( this.getClass().getName() ) ); 78 } 79 80 81 protected abstract AMXConfig createProgeny(String name, Map <String ,String > options ); 82 protected abstract Container getProgenyContainer(); 83 protected abstract String getProgenyJ2EEType(); 84 protected abstract void removeProgeny( String name ); 85 86 protected static final Map <String ,String > ILLEGAL_OPTIONS = 87 Collections.unmodifiableMap( MapUtil.newMap( new String [] 88 { 89 "IllegalParam1", "IllegalValue1", 90 "IllegalParam2", "IllegalValue2", 91 })); 92 93 public final synchronized void 94 testIllegalCreate() 95 throws Exception 96 { 97 if ( ! checkNotOffline( "testIllegalCreate" ) ) 98 { 99 return; 100 } 101 102 final String name = getProgenyTestName() + "-Illegal"; 103 104 try 105 { 106 final AMXConfig proxy = createProgeny( name, ILLEGAL_OPTIONS ); 107 fail( "Expecting failure from createProgenyIllegal for progeny type: " + getProgenyJ2EEType() ); 108 } 109 catch( Exception e ) 110 { 111 final Throwable rootCause = ExceptionUtil.getRootCause( e ); 112 if ( ! ( rootCause instanceof IllegalArgumentException ) ) 113 { 114 warning( "expecting IllegalArgumentException, got: " + rootCause.getClass().getName() + 115 ", msg = " + rootCause.getMessage() ); 116 rootCause.printStackTrace(); 117 } 118 } 119 } 120 121 public final synchronized void 122 testCreateRemove() 123 throws Exception 124 { 125 if ( ! checkNotOffline( "testCreateRemove" ) ) 126 { 127 return; 128 } 129 130 final long start = now(); 131 132 String name = getProgenyTestName(); 133 134 final String progenyJ2EEType = getProgenyJ2EEType(); 135 136 AMXConfig proxy = getProgeny( name ); 137 if ( proxy != null ) 138 { 139 final ObjectName objectName = Util.getExtra( proxy ).getObjectName(); 140 remove( name ); 141 waitUnregistered( objectName ); 142 assert( ! getConnection().isRegistered( objectName ) ); 143 assert( getProgeny( name ) == null ); 144 proxy = null; 145 } 146 147 final Container container = getProgenyContainer(); 148 final CreateRemoveListener listener = 149 new CreateRemoveListener( container, progenyJ2EEType, name ); 150 151 try 153 { 154 proxy = createProgeny( name, null ); 155 } 156 catch( Exception e ) 157 { 158 trace( getStackTrace( ExceptionUtil.getRootCause(e) ) ); 159 failure( "Can't create item of j2eeType=" + progenyJ2EEType + 160 ",name=" + name ); 161 } 162 assert( proxy.getName().equals( name ) ); 163 final ObjectName objectName = Util.getObjectName( proxy ); 164 assert( getConnection().isRegistered( objectName ) ); 165 assert( container.getContainee( progenyJ2EEType, name) != null ); 166 assert( container.getContainee( progenyJ2EEType, name) == proxy ); 167 final AMXConfig progeny = getProgeny( name ); 168 assert( progeny == proxy ); 169 170 final ProxyFactory factory = Util.getExtra( proxy ).getProxyFactory(); 172 assert( name.equals( progeny.getName() ) ); 173 remove( name ); 174 waitUnregistered( objectName ); 175 assert( ! getConnection().isRegistered( objectName ) ); 176 waitProxyGone( factory, objectName ); 177 assert( getProgeny( name ) == null ); 178 179 listener.waitNotifs(); 180 181 printElapsed( "testCreateRemove: created/remove/listen for: " + progenyJ2EEType, start ); 182 } 183 184 185 public AMXConfig 186 getProgeny( final String name ) 187 { 188 final Container container = getProgenyContainer(); 189 final String progenyType = getProgenyJ2EEType(); 190 191 final Object progeny = container.getContainee( progenyType, name ); 193 194 if ( progeny != null && ! (progeny instanceof AMXConfig) ) 195 { 196 assert( progeny instanceof AMX ); 197 failure( 198 "getProgeny: " + progenyType + "=" + name + " not an AMXConfig, interface = " + 199 Util.getExtra( Util.asAMX(progeny )).getInterfaceName() ); 200 } 201 202 return( (AMXConfig)progeny ); 203 } 204 205 206 207 protected void 208 remove( final String name) 209 { 210 removeProgeny( name ); 211 } 212 213 214 void 215 removeEx(String name) 216 { 217 final AMX proxy = getProgeny( name ); 218 if ( proxy != null ) 219 { 220 assert( proxy.getName().equals( name ) ); 221 final ObjectName objectName = Util.getObjectName( proxy ); 222 223 try 224 { 225 remove(name); 226 227 final MBeanServerConnection conn = getConnection(); 228 while ( conn.isRegistered( objectName ) ) 229 { 230 trace( "waiting for mbean to be unregistered: " + objectName ); 231 } 232 } 233 catch(Exception e) 234 { 235 trace( "error removing MBean: " + 236 objectName + " = " + ExceptionUtil.getRootCause( e ).getMessage() ); 237 } 238 } 239 else 240 { 241 } 243 } 244 } 245 246 247 | Popular Tags |