KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > base > BulkAccessTest


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 package com.sun.enterprise.management.base;
24
25 import java.util.Set JavaDoc;
26 import java.util.HashSet JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.MBeanServerConnection JavaDoc;
30 import javax.management.AttributeList JavaDoc;
31 import javax.management.MBeanInfo JavaDoc;
32 import javax.management.MBeanAttributeInfo JavaDoc;
33 import javax.management.MBeanOperationInfo JavaDoc;
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 /**
47  */

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 JavaDoc
70     {
71         final long start = now();
72         
73         final ObjectName JavaDoc[] objectNames = getTestUtil().getAllAMXArray();
74         
75         // get everything in bulk....
76
final Object JavaDoc[] infos =
77             getBulkAccess().bulkGetMBeanAttributeInfo( objectNames );
78         
79         // now verify that getting it singly yields the same result.
80
final MBeanServerConnection JavaDoc conn = getConnection();
81         for( int i = 0; i < infos.length; ++i )
82         {
83             
84             final MBeanAttributeInfo JavaDoc[] bulkAttributes = (MBeanAttributeInfo JavaDoc[])infos[ i ];
85             
86             final MBeanInfo JavaDoc 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 JavaDoc
95     {
96         final long start = now();
97         
98         final ObjectName JavaDoc[] objectNames = getTestUtil().getAllAMXArray();
99         
100         final Object JavaDoc[] infos =
101             getBulkAccess().bulkGetMBeanOperationInfo( objectNames );
102         
103         // now verify that getting it singly yields the same result.
104
final MBeanServerConnection JavaDoc conn = getConnection();
105         for( int i = 0; i < infos.length; ++i )
106         {
107             
108             final MBeanOperationInfo JavaDoc[] bulkOperations = (MBeanOperationInfo JavaDoc[])infos[ i ];
109             
110             final MBeanInfo JavaDoc 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 JavaDoc
119     {
120         final long start = now();
121         
122         final ObjectName JavaDoc[] objectNames = getTestUtil().getAllAMXArray();
123         
124         final Object JavaDoc[] nameArrays =
125             getBulkAccess().bulkGetAttributeNames( objectNames );
126         
127         final Set JavaDoc<ObjectName JavaDoc> failed = new HashSet JavaDoc<ObjectName JavaDoc>();
128         // now verify that getting it singly yields the same result.
129
for( int i = 0; i < nameArrays.length; ++i )
130         {
131             final String JavaDoc[] bulkNames = (String JavaDoc[])nameArrays[ i ];
132             
133             // verify that the AttributeNames Attribute contains all the names
134
final String JavaDoc[] attrNames = (String JavaDoc[])
135                 getConnection().getAttribute( objectNames[ i ], "AttributeNames" );
136             
137             final Set JavaDoc<String JavaDoc> bulkSet = GSetUtil.newStringSet( bulkNames );
138             final Set JavaDoc<String JavaDoc> 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 JavaDoc
157     {
158         final long start = now();
159         
160         final ObjectName JavaDoc[] objectNames = getTestUtil().getAllAMXArray();
161         
162         final Object JavaDoc[] nameArrays =
163             getBulkAccess().bulkGetAttributeNames( objectNames );
164         
165         for( int i = 0; i < nameArrays.length; ++i )
166         {
167             final String JavaDoc[] bulkNames = (String JavaDoc[])nameArrays[ i ];
168             
169             final MBeanInfo JavaDoc info =
170                 getConnection().getMBeanInfo( objectNames[ i ] );
171                 
172             final String JavaDoc[] 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 JavaDoc
184     {
185         final long start = now();
186         
187         final String JavaDoc attrName = AMXAttributes.ATTR_OBJECT_NAME;
188         final ObjectName JavaDoc[] objectNames = getTestUtil().getAllAMXArray();
189         
190         final Object JavaDoc[] values =
191             getBulkAccess().bulkGetAttribute( objectNames, attrName );
192         
193         final MBeanServerConnection JavaDoc conn = getConnection();
194         for( int i = 0; i < objectNames.length; ++i )
195         {
196             final Object JavaDoc 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 JavaDoc
208     {
209         final long start = now();
210         
211         final String JavaDoc[] attrNames = new String JavaDoc[] {
212             "FullType", "Group", "Name", "DomainRootObjectName", "ContainerObjectName" };
213         final ObjectName JavaDoc[] objectNames = getTestUtil().getAllAMXArray();
214         
215         final Object JavaDoc[] values =
216             getBulkAccess().bulkGetAttributes( objectNames, attrNames );
217         
218         final MBeanServerConnection JavaDoc conn = getConnection();
219         for( int i = 0; i < objectNames.length; ++i )
220         {
221             final AttributeList JavaDoc bulkAttrs = (AttributeList JavaDoc)values[ i ];
222             
223             final AttributeList JavaDoc attrs = (AttributeList JavaDoc)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