Source Code Cross Referenced for GarbageCollectorMXBeanImplTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » lang » management » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.lang.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         * 
019:         */
020:
021:        package org.apache.harmony.lang.management;
022:
023:        import java.lang.management.GarbageCollectorMXBean;
024:        import java.lang.management.ManagementFactory;
025:        import java.util.ArrayList;
026:        import java.util.Hashtable;
027:        import java.util.Iterator;
028:        import java.util.List;
029:
030:        import javax.management.Attribute;
031:        import javax.management.AttributeList;
032:        import javax.management.AttributeNotFoundException;
033:        import javax.management.MBeanAttributeInfo;
034:        import javax.management.MBeanConstructorInfo;
035:        import javax.management.MBeanInfo;
036:        import javax.management.MBeanNotificationInfo;
037:        import javax.management.MBeanOperationInfo;
038:
039:        import org.apache.harmony.lang.management.DynamicMXBeanImpl;
040:        import org.apache.harmony.lang.management.GarbageCollectorMXBeanImpl;
041:
042:        public class GarbageCollectorMXBeanImplTest extends
043:                MultiInstanceDynamicMXBeanImplTestBase {
044:
045:            protected void setUp() throws Exception {
046:                super .setUp();
047:                List<GarbageCollectorMXBean> allBeans = ManagementFactory
048:                        .getGarbageCollectorMXBeans();
049:                mbList = new ArrayList<DynamicMXBeanImpl>();
050:                for (GarbageCollectorMXBean bean : allBeans) {
051:                    mbList.add((GarbageCollectorMXBeanImpl) bean);
052:                }// end for
053:            }
054:
055:            protected void tearDown() throws Exception {
056:                super .tearDown();
057:            }
058:
059:            // -----------------------------------------------------------------
060:            // DynamicMBean behaviour tests follow ....
061:            // -----------------------------------------------------------------
062:
063:            public final void testGetAttributes() throws Exception {
064:                for (DynamicMXBeanImpl mb : mbList) {
065:                    AttributeList attributes = mb.getAttributes(attribs
066:                            .keySet().toArray(new String[] {}));
067:                    assertNotNull(attributes);
068:                    assertTrue(attributes.size() <= attribs.size());
069:
070:                    // Check through the returned values
071:                    Iterator<?> it = attributes.iterator();
072:                    while (it.hasNext()) {
073:                        Attribute element = (Attribute) it.next();
074:                        assertNotNull(element);
075:                        String name = element.getName();
076:                        Object value = element.getValue();
077:                        if (name.equals("Valid")) {
078:                            // This could be true or false - just so long as we don't
079:                            // get an exception raised...
080:                            boolean validVal = ((Boolean) value).booleanValue();
081:                        } else if (name.equals("Name")) {
082:                            assertNotNull(value);
083:                            assertTrue(value instanceof  String);
084:                            assertTrue(((String) value).length() > 0);
085:                        } else if (name.equals("MemoryPoolNames")) {
086:                            assertNotNull(value);
087:                            assertTrue(value instanceof  String[]);
088:                            String[] strVals = (String[]) value;
089:                            for (int i = 0; i < strVals.length; i++) {
090:                                String poolName = strVals[i];
091:                                assertNotNull(poolName);
092:                                assertTrue(poolName.length() > 0);
093:                            }// end for
094:                        } else if (name.equals("CollectionCount")) {
095:                            assertNotNull(value);
096:                            assertTrue(value instanceof  Long);
097:                            // It is possible for this count to be -1 if undefined for
098:                            // this garbage collector
099:                            assertTrue((Long) value > -2);
100:                        } else if (name.equals("CollectionTime")) {
101:                            assertNotNull(value);
102:                            assertTrue(value instanceof  Long);
103:                            // It is possible for this time to be -1 if undefined for
104:                            // this garbage collector
105:                            assertTrue((Long) value > -2);
106:                        }
107:                    }// end while
108:                }// end for
109:            }
110:
111:            public final void testSetAttributes() {
112:                // No writable attributes for this type
113:                for (DynamicMXBeanImpl mb : mbList) {
114:                    AttributeList badList = new AttributeList();
115:                    Attribute garbage = new Attribute("Name", "Bez");
116:                    badList.add(garbage);
117:                    AttributeList setAttrs = mb.setAttributes(badList);
118:                    assertNotNull(setAttrs);
119:                    assertTrue(setAttrs.size() == 0);
120:                }// end for
121:            }
122:
123:            public final void testGetMBeanInfo() {
124:                for (DynamicMXBeanImpl mb : mbList) {
125:                    MBeanInfo mbi = mb.getMBeanInfo();
126:                    assertNotNull(mbi);
127:
128:                    // Now make sure that what we got back is what we expected.
129:
130:                    // Class name
131:                    assertTrue(mbi.getClassName().equals(
132:                            mb.getClass().getName()));
133:
134:                    // No public constructors
135:                    MBeanConstructorInfo[] constructors = mbi.getConstructors();
136:                    assertNotNull(constructors);
137:                    assertTrue(constructors.length == 0);
138:
139:                    // No public operations
140:                    MBeanOperationInfo[] operations = mbi.getOperations();
141:                    assertNotNull(operations);
142:                    assertTrue(operations.length == 0);
143:
144:                    // No notifications
145:                    MBeanNotificationInfo[] notifications = mbi
146:                            .getNotifications();
147:                    assertNotNull(notifications);
148:                    assertTrue(notifications.length == 0);
149:
150:                    // Description is just the class name
151:                    assertTrue(mbi.getDescription().equals(
152:                            mb.getClass().getName()));
153:
154:                    // 5 standard attributes - none is writable.
155:                    MBeanAttributeInfo[] attributes = mbi.getAttributes();
156:                    assertNotNull(attributes);
157:                    assertTrue(attributes.length == 5);
158:                    for (int i = 0; i < attributes.length; i++) {
159:                        MBeanAttributeInfo info = attributes[i];
160:                        assertNotNull(info);
161:                        validateAttributeInfo(info);
162:                    }// end for
163:                }// end for
164:            }
165:
166:            public final void testGetAttribute() throws Exception {
167:                for (DynamicMXBeanImpl mb : mbList) {
168:                    // The good attributes...
169:                    assertTrue(mb.getAttribute("MemoryPoolNames") instanceof  String[]);
170:                    String[] arr = (String[]) mb
171:                            .getAttribute("MemoryPoolNames");
172:                    for (int i = 0; i < arr.length; i++) {
173:                        String element = arr[i];
174:                        assertNotNull(element);
175:                        assertTrue(element.length() > 0);
176:                    }// end for
177:
178:                    assertTrue(mb.getAttribute("Name") instanceof  String);
179:                    assertTrue(((String) mb.getAttribute("Name")).length() > 0);
180:
181:                    // This could be true or false - just so long as we don't get an
182:                    // exception raised...
183:                    boolean validVal = ((Boolean) (mb.getAttribute("Valid")));
184:
185:                    assertTrue(mb.getAttribute("CollectionCount") instanceof  Long);
186:                    // It is possible for this count to be -1 if undefined for
187:                    // this garbage collector
188:                    assertTrue(((Long) mb.getAttribute("CollectionCount")) > -2);
189:
190:                    assertTrue(mb.getAttribute("CollectionTime") instanceof  Long);
191:                    // It is possible for this time to be -1 if undefined for
192:                    // this garbage collector
193:                    assertTrue(((Long) mb.getAttribute("CollectionTime")) > -2);
194:
195:                    // A nonexistent attribute should throw an
196:                    // AttributeNotFoundException
197:                    try {
198:                        long rpm = ((Long) (mb.getAttribute("RPM")));
199:                        fail("Should have thrown an AttributeNotFoundException.");
200:                    } catch (AttributeNotFoundException ignore) {
201:                    }
202:
203:                    // Type mismatch should result in a casting exception
204:                    try {
205:                        String bad = (String) (mb
206:                                .getAttribute("CollectionTime"));
207:                        fail("Should have thrown a ClassCastException");
208:                    } catch (ClassCastException ignore) {
209:                    }
210:                }// end for
211:            }
212:
213:            public final void testSetAttribute() throws Exception {
214:                for (DynamicMXBeanImpl mb : mbList) {
215:
216:                    // Let's try and set some non-writable attributes.
217:                    Attribute attr = new Attribute("Name", "Dando");
218:                    try {
219:                        mb.setAttribute(attr);
220:                        fail("Should have thrown an AttributeNotFoundException.");
221:                    } catch (AttributeNotFoundException ignore) {
222:                    }
223:
224:                    attr = new Attribute("Valid", new Boolean(true));
225:                    try {
226:                        mb.setAttribute(attr);
227:                        fail("Should have thrown an AttributeNotFoundException.");
228:                    } catch (AttributeNotFoundException ignore) {
229:                    }
230:
231:                    attr = new Attribute("MemoryPoolNames", new String[] { "X",
232:                            "Y", "Z" });
233:                    try {
234:                        mb.setAttribute(attr);
235:                        fail("Should have thrown an AttributeNotFoundException.");
236:                    } catch (AttributeNotFoundException ignore) {
237:                    }
238:
239:                    attr = new Attribute("CollectionCount", new Long(233));
240:                    try {
241:                        mb.setAttribute(attr);
242:                        fail("Should have thrown an AttributeNotFoundException.");
243:                    } catch (AttributeNotFoundException ignore) {
244:                    }
245:
246:                    attr = new Attribute("CollectionTime", new Long(233));
247:                    try {
248:                        mb.setAttribute(attr);
249:                        fail("Should have thrown an AttributeNotFoundException.");
250:                    } catch (AttributeNotFoundException ignore) {
251:                    }
252:                }// end for
253:            }
254:
255:            @Override
256:            protected void populateTestAttributes() {
257:                attribs = new Hashtable<String, AttributeData>();
258:                attribs.put("MemoryPoolNames", new AttributeData(
259:                        "[Ljava.lang.String;", true, false, false));
260:                attribs.put("Name", new AttributeData(String.class.getName(),
261:                        true, false, false));
262:                attribs.put("Valid", new AttributeData(Boolean.TYPE.getName(),
263:                        true, false, true));
264:                attribs.put("CollectionCount", new AttributeData(Long.TYPE
265:                        .getName(), true, false, false));
266:                attribs.put("CollectionTime", new AttributeData(Long.TYPE
267:                        .getName(), true, false, false));
268:            }
269:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.