KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > client > ProxyFactoryTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 /*
25  * $Header: /cvs/glassfish/admin/mbeanapi-impl/tests/com/sun/enterprise/management/client/ProxyFactoryTest.java,v 1.4 2006/03/09 20:30:52 llc Exp $
26  * $Revision: 1.4 $
27  * $Date: 2006/03/09 20:30:52 $
28  */

29 package com.sun.enterprise.management.client;
30
31 import java.util.Set JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Collections JavaDoc;
36 import java.util.logging.Level JavaDoc;
37
38 import javax.management.ObjectName JavaDoc;
39 import javax.management.MBeanServerConnection JavaDoc;
40 import javax.management.AttributeList JavaDoc;
41 import javax.management.MBeanInfo JavaDoc;
42 import javax.management.MBeanAttributeInfo JavaDoc;
43 import javax.management.MBeanOperationInfo JavaDoc;
44 import javax.management.InstanceNotFoundException JavaDoc;
45 import javax.management.Notification JavaDoc;
46 import javax.management.NotificationListener JavaDoc;
47 import javax.management.AttributeChangeNotification JavaDoc;
48
49 import com.sun.appserv.management.base.AMX;
50 import com.sun.appserv.management.base.Util;
51 import com.sun.appserv.management.base.NotificationServiceMgr;
52 import com.sun.appserv.management.base.NotificationService;
53 import com.sun.appserv.management.helper.NotificationServiceHelper;
54 import com.sun.appserv.management.base.QueryMgr;
55 import com.sun.appserv.management.client.ProxyFactory;
56 import com.sun.appserv.management.util.misc.ExceptionUtil;
57
58
59 import com.sun.enterprise.management.AMXTestBase;
60 import com.sun.enterprise.management.Capabilities;
61
62
63 /**
64  */

65 public final class ProxyFactoryTest extends AMXTestBase
66 {
67         public
68     ProxyFactoryTest( )
69     {
70     }
71         public static Capabilities
72     getCapabilities()
73     {
74         return getOfflineCapableCapabilities( false );
75     }
76     
77
78     /**
79         Verify that when an MBean is removed, the ProxyFactory
80         detects this, and removes any proxy from its cache.
81      */

82         public void
83     testProxyFactoryDetectsMBeanRemoved()
84         throws InstanceNotFoundException JavaDoc
85     {
86         // use the NotificationServiceMgr as a convenient way of making
87
// an MBean (a NotificationService) come and go.
88
final NotificationServiceMgr mgr = getDomainRoot().getNotificationServiceMgr();
89         final NotificationService ns = mgr.createNotificationService( "UserData", 10 );
90         final ObjectName JavaDoc nsObjectName = Util.getObjectName( ns );
91         assert( ns.getUserData().equals( "UserData" ) );
92         
93         final ProxyFactory factory = getProxyFactory();
94         final NotificationService proxy =
95             factory.getProxy( nsObjectName, NotificationService.class, false );
96         assert( proxy == ns ) : "proxies differ: " + ns + "\n" + proxy;
97         
98         mgr.removeNotificationService( ns.getName() );
99
100         int iterations = 0;
101         long sleepMillis = 10;
102         while( factory.getProxy( nsObjectName, NotificationService.class, false ) != null )
103         {
104             mySleep( sleepMillis );
105             if ( sleepMillis >= 400 )
106             {
107                 trace( "testProxyFactoryDetectsMBeanRemoved: waiting for proxy to be removed" );
108             }
109             sleepMillis *= 2;
110         }
111     }
112 }
113
114
115
116
117
118
119
120
121
122
Popular Tags