001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.monitoring.statistics.test;
006:
007: import com.sun.portal.monitoring.*;
008: import com.sun.portal.monitoring.statistics.*;
009: import junit.framework.Test;
010: import junit.framework.TestCase;
011: import junit.framework.TestSuite;
012:
013: import javax.management.*;
014: import javax.management.j2ee.statistics.*;
015: import javax.management.openmbean.OpenDataException;
016: import java.io.IOException;
017: import java.util.Properties;
018:
019: public class StatisticMBeanServerTest extends TestCase {
020: public StatisticMBeanServerTest(String name) {
021: super (name);
022: }
023:
024: public static void main(final String[] args) {
025: junit.textui.TestRunner.run(suite());
026: }
027:
028: public static Test suite() {
029: final TestSuite suite = new TestSuite(
030: StatisticMBeanServerTest.class);
031: return suite;
032: }
033:
034: private static Subsystem subsystem;
035:
036: public void setUp() throws MonitoringException {
037: if (subsystem == null) {
038: Properties properties = new Properties();
039: properties.setProperty(
040: SubsystemProperties.HTML_ADAPTOR_PORT, "49182");
041:
042: subsystem = new SubsystemImpl(properties);
043: subsystem.start();
044: }
045: }
046:
047: public void tearDown() throws MonitoringException {
048: }
049:
050: private void registerStatisticMBeans()
051: throws MalformedObjectNameException, MonitoringException,
052: NotCompliantMBeanException {
053: StatisticImpl statistic = new StatisticImpl();
054: StandardMBean standardMBean = new StandardMBean(statistic,
055: Statistic.class);
056: ObjectName on = new ObjectName(subsystem.getNamingDomain(),
057: "type", "Statistic");
058: subsystem.registerMBean(standardMBean, on.toString());
059:
060: StatisticWrapper statisticWrapper = new StatisticWrapper();
061: OpenStatistic openStatistic = new OpenStatistic(
062: statisticWrapper);
063: on = new ObjectName(subsystem.getNamingDomain(), "type",
064: "StatisticWrapper");
065: subsystem.registerMBean(openStatistic, on.toString());
066: }
067:
068: private void registerBoundaryStatisticMBeans()
069: throws NotCompliantMBeanException,
070: MalformedObjectNameException, MonitoringException {
071: BoundaryStatisticImpl boundaryStatistic = new BoundaryStatisticImpl();
072: StandardMBean standardMBean = new StandardMBean(
073: boundaryStatistic, BoundaryStatistic.class);
074: ObjectName on = new ObjectName(subsystem.getNamingDomain(),
075: "type", "BoundaryStatistic");
076: subsystem.registerMBean(standardMBean, on.toString());
077:
078: BoundaryStatisticWrapper boundaryStatisticWrapper = new BoundaryStatisticWrapper();
079: OpenStatistic openStatistic = new OpenStatistic(
080: boundaryStatisticWrapper);
081: on = new ObjectName(subsystem.getNamingDomain(), "type",
082: "BoundaryStatisticWrapper");
083: subsystem.registerMBean(openStatistic, on.toString());
084: }
085:
086: private void registerBoundedRangeStatisticMBeans()
087: throws NotCompliantMBeanException,
088: MalformedObjectNameException, MonitoringException {
089: BoundedRangeStatisticImpl boundedRangeStatistic = new BoundedRangeStatisticImpl();
090: StandardMBean standardMBean = new StandardMBean(
091: boundedRangeStatistic, BoundedRangeStatistic.class);
092: ObjectName on = new ObjectName(subsystem.getNamingDomain(),
093: "type", "BoundedRangeStatistic");
094: subsystem.registerMBean(standardMBean, on.toString());
095:
096: BoundedRangeStatisticWrapper boundedRangeStatisticWrapper = new BoundedRangeStatisticWrapper();
097: OpenStatistic openStatistic = new OpenStatistic(
098: boundedRangeStatisticWrapper);
099: on = new ObjectName(subsystem.getNamingDomain(), "type",
100: "BoundedRangeStatisticWrapper");
101: subsystem.registerMBean(openStatistic, on.toString());
102: }
103:
104: private void registerCountStatisticMBeans()
105: throws NotCompliantMBeanException,
106: MalformedObjectNameException, MonitoringException {
107: CountStatisticImpl countStatistic = new CountStatisticImpl();
108: StandardMBean standardMBean = new StandardMBean(countStatistic,
109: CountStatistic.class);
110: ObjectName on = new ObjectName(subsystem.getNamingDomain(),
111: "type", "CountStatistic");
112: subsystem.registerMBean(standardMBean, on.toString());
113:
114: CountStatisticWrapper countStatisticWrapper = new CountStatisticWrapper();
115: OpenStatistic openStatistic = new OpenStatistic(
116: countStatisticWrapper);
117: on = new ObjectName(subsystem.getNamingDomain(), "type",
118: "CountStatisticWrapper");
119: subsystem.registerMBean(openStatistic, on.toString());
120: }
121:
122: private void registerRangeStatisticMBeans()
123: throws NotCompliantMBeanException,
124: MalformedObjectNameException, MonitoringException {
125: RangeStatisticImpl rangeStatistic = new RangeStatisticImpl();
126: StandardMBean standardMBean = new StandardMBean(rangeStatistic,
127: RangeStatistic.class);
128: ObjectName on = new ObjectName(subsystem.getNamingDomain(),
129: "type", "RangeStatistic");
130: subsystem.registerMBean(standardMBean, on.toString());
131:
132: RangeStatisticWrapper rangeStatisticWrapper = new RangeStatisticWrapper();
133: OpenStatistic openStatistic = new OpenStatistic(
134: rangeStatisticWrapper);
135: on = new ObjectName(subsystem.getNamingDomain(), "type",
136: "RangeStatisticWrapper");
137: subsystem.registerMBean(openStatistic, on.toString());
138: }
139:
140: private void registerRollingAvgTimeStatisticMBeans()
141: throws NotCompliantMBeanException,
142: MalformedObjectNameException, MonitoringException {
143: RollingAvgTimeStatisticImpl rollingAvgTimeStatistic = new RollingAvgTimeStatisticImpl();
144: StandardMBean standardMBean = new StandardMBean(
145: rollingAvgTimeStatistic, RollingAvgTimeStatistic.class);
146: ObjectName on = new ObjectName(subsystem.getNamingDomain(),
147: "type", "RollingAvgTimeStatistic");
148: subsystem.registerMBean(standardMBean, on.toString());
149:
150: RollingAvgTimeStatisticWrapper rollingAvgTimeStatisticWrapper = new RollingAvgTimeStatisticWrapper();
151: OpenStatistic openStatistic = new OpenStatistic(
152: rollingAvgTimeStatisticWrapper);
153: on = new ObjectName(subsystem.getNamingDomain(), "type",
154: "RollingAvgTimeStatisticWrapper");
155: subsystem.registerMBean(openStatistic, on.toString());
156: }
157:
158: private void registerTimeStatisticMBeans()
159: throws NotCompliantMBeanException,
160: MalformedObjectNameException, MonitoringException {
161: TimeStatisticImpl timeStatistic = new TimeStatisticImpl();
162: StandardMBean standardMBean = new StandardMBean(timeStatistic,
163: TimeStatistic.class);
164: ObjectName on = new ObjectName(subsystem.getNamingDomain(),
165: "type", "TimeStatistic");
166: subsystem.registerMBean(standardMBean, on.toString());
167:
168: TimeStatisticWrapper timeStatisticWrapper = new TimeStatisticWrapper();
169: OpenStatistic openStatistic = new OpenStatistic(
170: timeStatisticWrapper);
171: on = new ObjectName(subsystem.getNamingDomain(), "type",
172: "TimeStatisticWrapper");
173: subsystem.registerMBean(openStatistic, on.toString());
174: }
175:
176: public void testAll() throws IOException, MonitoringException,
177: MalformedObjectNameException, NotCompliantMBeanException,
178: MBeanRegistrationException, InstanceAlreadyExistsException,
179: OpenDataException {
180: registerStatisticMBeans();
181: registerBoundaryStatisticMBeans();
182: registerBoundedRangeStatisticMBeans();
183: registerCountStatisticMBeans();
184: registerRangeStatisticMBeans();
185: registerRollingAvgTimeStatisticMBeans();
186: registerTimeStatisticMBeans();
187:
188: System.out.println("Press Enter/Return to stop server...");
189: System.in.read();
190:
191: if (subsystem != null) {
192: subsystem.stop(Boolean.TRUE);
193: }
194: }
195: }
|