Source Code Cross Referenced for RMIMarshallingTest.java in  » JMX » mx4j » test » javax » management » remote » rmi » 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 » JMX » mx4j » test.javax.management.remote.rmi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The MX4J Contributors.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the MX4J License version 1.0.
006:         * See the terms of the MX4J License in the documentation provided with this software.
007:         */
008:
009:        package test.javax.management.remote.rmi;
010:
011:        import java.io.File;
012:        import java.io.Serializable;
013:        import java.net.URL;
014:        import java.util.Set;
015:        import javax.management.Attribute;
016:        import javax.management.MBeanServer;
017:        import javax.management.MBeanServerConnection;
018:        import javax.management.Notification;
019:        import javax.management.NotificationFilter;
020:        import javax.management.NotificationListener;
021:        import javax.management.ObjectInstance;
022:        import javax.management.ObjectName;
023:        import javax.management.loading.PrivateMLet;
024:        import javax.management.remote.JMXConnector;
025:        import javax.management.remote.JMXConnectorFactory;
026:        import javax.management.remote.JMXConnectorServer;
027:        import javax.management.remote.JMXConnectorServerFactory;
028:        import javax.management.remote.JMXServiceURL;
029:
030:        import test.MX4JTestCase;
031:        import test.javax.management.remote.support.Marshalling;
032:        import test.javax.management.remote.support.Unknown;
033:
034:        /**
035:         * @version $Revision: 1.5 $
036:         */
037:        public class RMIMarshallingTest extends MX4JTestCase {
038:            private MBeanServer server = null;
039:            private MBeanServerConnection conn = null;
040:            private JMXConnectorServer cntorServer = null;
041:            private JMXConnector cntor = null;
042:            private ObjectName mbeanName;
043:            private ObjectName mbeanLoaderName;
044:
045:            public RMIMarshallingTest(String s) {
046:                super (s);
047:            }
048:
049:            public void setUp() throws Exception {
050:                super .setUp();
051:                // Create a classloader that sees only the MBean and its parameter classes (Unknown)
052:                File mbeanJar = new File("dist/test/mx4j-tests.jar");
053:                PrivateMLet mbeanLoader = new PrivateMLet(new URL[] { mbeanJar
054:                        .toURL() }, getClass().getClassLoader().getParent(),
055:                        false);
056:                mbeanLoaderName = ObjectName.getInstance("marshal:type=mlet");
057:
058:                server = newMBeanServer();
059:                server.registerMBean(mbeanLoader, mbeanLoaderName);
060:
061:                JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0);
062:                cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(
063:                        url, null, server);
064:                cntorServer.start();
065:
066:                cntor = JMXConnectorFactory.connect(cntorServer.getAddress());
067:                conn = cntor.getMBeanServerConnection();
068:                mbeanName = ObjectName.getInstance("marshal:type=mbean");
069:
070:            }
071:
072:            public void tearDown() throws Exception {
073:                if (cntor != null)
074:                    cntor.close();
075:                if (cntorServer != null)
076:                    cntorServer.stop();
077:            }
078:
079:            protected static class MockNotificationListener implements 
080:                    NotificationListener, Serializable {
081:                long numberOfNotifications = 0;
082:
083:                public void handleNotification(Notification notification,
084:                        Object handback) {
085:                    //   	 	System.out.println("[MockNotificationListener] Notification: "+notification+" Handback: "+handback);
086:                    assertEquals(notification.getSequenceNumber(),
087:                            numberOfNotifications);
088:                    assertEquals(notification.getType(), Unknown.class
089:                            .getName());
090:                    numberOfNotifications++;
091:                    synchronized (this ) {
092:                        this .notify();
093:                    }
094:                }
095:
096:                public synchronized void waitOnNotification(long timeout,
097:                        long sequence) throws InterruptedException {
098:                    long to;
099:                    if (timeout > 0)
100:                        to = System.currentTimeMillis() + timeout;
101:                    else
102:                        to = -1;
103:                    while (numberOfNotifications < sequence) // Check for missed notification
104:                    {
105:                        this .wait(timeout);
106:                        if (to > -1 && System.currentTimeMillis() >= to) // Check if waited for full timeout
107:                        {
108:                            Thread.currentThread().interrupt();
109:                            break;
110:                        }
111:                    }
112:                }
113:
114:            }
115:
116:            protected static class MockNotificationFilter implements 
117:                    NotificationFilter, Serializable {
118:
119:                public boolean isNotificationEnabled(Notification notification) {
120:                    //		System.out.println("[MockNotificationFilter] Notification: "+notification);
121:                    return true;
122:                }
123:
124:            }
125:
126:            private void createMBean() throws Exception {
127:                ObjectInstance inst = conn.createMBean(Marshalling.class
128:                        .getName(), mbeanName, new Object[] { new Unknown() },
129:                        new String[] { Unknown.class.getName() });
130:            }
131:
132:            public void testCreateMBean() throws Exception {
133:                conn.createMBean(Marshalling.class.getName(), mbeanName);
134:                checkRegistration();
135:
136:                conn.createMBean(Marshalling.class.getName(), mbeanName,
137:                        new Object[] { new Unknown() },
138:                        new String[] { Unknown.class.getName() });
139:                checkRegistration();
140:            }
141:
142:            private void checkRegistration() throws Exception {
143:                // Check registrations
144:                if (!conn.isRegistered(mbeanName))
145:                    fail();
146:                if (!server.isRegistered(mbeanName))
147:                    fail();
148:                conn.unregisterMBean(mbeanName);
149:            }
150:
151:            public void testInstanceOf() throws Exception {
152:                createMBean();
153:                // Check instanceof
154:                if (!conn.isInstanceOf(mbeanName, Marshalling.class.getName()))
155:                    fail();
156:                if (!server
157:                        .isInstanceOf(mbeanName, Marshalling.class.getName()))
158:                    fail();
159:            }
160:
161:            public void testInvocationUnknownReturn() throws Exception {
162:                createMBean();
163:                // Check invocation
164:                Object returned = conn.invoke(mbeanName, "unknownReturnValue",
165:                        new Object[0], new String[0]);
166:                if (!returned.getClass().getName().equals(
167:                        Unknown.class.getName()))
168:                    fail();
169:                returned = server.invoke(mbeanName, "unknownReturnValue",
170:                        new Object[0], new String[0]);
171:                if (!returned.getClass().getName().equals(
172:                        Unknown.class.getName()))
173:                    fail();
174:                Object remoteUnk = conn.invoke(mbeanName, "unknownArgument",
175:                        new Object[] { new Unknown() },
176:                        new String[] { Unknown.class.getName() });
177:                Object localUnk = server.invoke(mbeanName, "unknownArgument",
178:                        new Object[] { new Unknown() },
179:                        new String[] { Unknown.class.getName() });
180:                assertEquals(remoteUnk, localUnk);
181:            }
182:
183:            public void testUnregisterMBean() throws Exception {
184:                createMBean();
185:                // Check unregistration
186:                conn.unregisterMBean(mbeanName);
187:                if (conn.isRegistered(mbeanName))
188:                    fail();
189:                if (server.isRegistered(mbeanName))
190:                    fail();
191:
192:            }
193:
194:            public void testNotifications() throws Exception {
195:                createMBean();
196:                MockNotificationListener listener = new MockNotificationListener();
197:                conn.addNotificationListener(mbeanName, listener,
198:                        new MockNotificationFilter(), new Object());
199:
200:                Thread.sleep(1000L);
201:                Attribute att = new Attribute("UnknownAttribute", new Unknown());
202:
203:                conn.setAttribute(mbeanName, att);
204:
205:                Thread.sleep(1000L);
206:                // This triggers a notification
207:                try {
208:                    listener.waitOnNotification(1000L, 1);
209:                } catch (InterruptedException ignore) {
210:                }
211:
212:                assertEquals(1, listener.numberOfNotifications);
213:
214:                conn.removeNotificationListener(mbeanName, listener);
215:
216:                Thread.sleep(1000L);
217:                conn.setAttribute(mbeanName, att);
218:
219:                Thread.sleep(1000L);
220:                // This triggers a notification
221:                try {
222:                    listener.waitOnNotification(1000L, 2);
223:                } catch (InterruptedException ignore) {
224:                }
225:
226:                assertEquals(1, listener.numberOfNotifications);
227:            }
228:
229:            public void testQuery() throws Exception {
230:                createMBean();
231:                ObjectName pattern = mbeanName;
232:                ObjectName query = mbeanName;
233:                Set beans = conn.queryMBeans(pattern, query);
234:                Object[] set = beans.toArray();
235:                assertEquals(1, set.length);
236:                //	System.out.println("set[0]: "+set[0]+" class: "+set[0].getClass());
237:                ObjectInstance inst = (ObjectInstance) set[0];
238:                assertTrue(inst.getClassName().equals(
239:                        Marshalling.class.getName()));
240:
241:                beans = conn.queryNames(pattern, query);
242:                set = beans.toArray();
243:                assertEquals(1, set.length);
244:                //	System.out.println("set[0]: "+set[0]+" class: "+set[0].getClass());
245:                ObjectName nm = (ObjectName) set[0];
246:                assertTrue(nm.equals(mbeanName));
247:            }
248:
249:            public void testAttributes() throws Exception {
250:                createMBean();
251:                Unknown value = new Unknown();
252:                Attribute att = new Attribute("UnknownAttribute", value);
253:                conn.setAttribute(mbeanName, att);
254:                Object returned = conn.getAttribute(mbeanName,
255:                        "UnknownAttribute");
256:                assertTrue(returned.getClass().getName().equals(
257:                        Unknown.class.getName()));
258:            }
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.