001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.performance.registration;
023:
024: import junit.framework.TestCase;
025:
026: import test.performance.PerformanceSUITE;
027:
028: import javax.management.MBeanServer;
029: import javax.management.MBeanServerFactory;
030: import javax.management.ObjectName;
031:
032: /**
033: * Tests the speed of registrion
034: *
035: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
036: */
037: public class RegistrationTEST extends TestCase {
038: // Attributes ----------------------------------------------------------------
039:
040: /**
041: * The object to register
042: */
043: private Object obj;
044:
045: /**
046: * The object name to register
047: */
048: private String name;
049:
050: /**
051: * The description of the test
052: */
053: private String desc;
054:
055: // Constructor ---------------------------------------------------------------
056:
057: /**
058: * Construct the test
059: */
060: public RegistrationTEST(String s, Object obj, String name,
061: String desc) {
062: super (s);
063: this .obj = obj;
064: this .name = name;
065: this .desc = desc;
066: }
067:
068: /**
069: * Test Registration
070: */
071: public void testIt() {
072: System.out.println("\n" + desc);
073: System.out
074: .println(PerformanceSUITE.REGISTRATION_ITERATION_COUNT
075: + " Registrations/Deregistrations, Repeat: x"
076: + PerformanceSUITE.REPEAT_COUNT);
077: System.out.println("(this may take a while...)");
078:
079: long start = 0, end = 0;
080: float avg = 0l;
081: int size = 0;
082:
083: MBeanServer server = MBeanServerFactory.createMBeanServer();
084: try {
085: ObjectName on = new ObjectName(name);
086:
087: // drop the first batch (+1)
088: for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) {
089: start = System.currentTimeMillis();
090: for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.REGISTRATION_ITERATION_COUNT; ++invocationIterations) {
091: server.registerMBean(obj, on);
092: server.unregisterMBean(on);
093: }
094: end = System.currentTimeMillis();
095:
096: if (testIterations != 0) {
097: long time = end - start;
098: System.out.print(time + " ");
099: avg += time;
100: }
101: }
102:
103: System.out.println("\nAverage: "
104: + (avg / PerformanceSUITE.REPEAT_COUNT));
105: } catch (Exception e) {
106: fail(e.toString());
107: } finally {
108: MBeanServerFactory.releaseMBeanServer(server);
109: }
110: }
111: }
|