1 22 package test.performance.registration; 23 24 import junit.framework.TestCase; 25 26 import test.performance.PerformanceSUITE; 27 28 import javax.management.MBeanServer ; 29 import javax.management.MBeanServerFactory ; 30 import javax.management.ObjectName ; 31 32 37 public class RegistrationTEST 38 extends TestCase 39 { 40 42 45 private Object obj; 46 47 50 private String name; 51 52 55 private String desc; 56 57 59 62 public RegistrationTEST(String s, Object obj, String name, String desc) 63 { 64 super(s); 65 this.obj = obj; 66 this.name = name; 67 this.desc = desc; 68 } 69 70 73 public void testIt() 74 { 75 System.out.println("\n" + desc); 76 System.out.println(PerformanceSUITE.REGISTRATION_ITERATION_COUNT + " Registrations/Deregistrations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT); 77 System.out.println("(this may take a while...)"); 78 79 long start = 0, end = 0; 80 float avg = 0l; 81 int size = 0; 82 83 MBeanServer server = MBeanServerFactory.createMBeanServer(); 84 try 85 { 86 ObjectName on = new ObjectName (name); 87 88 for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) 90 { 91 start = System.currentTimeMillis(); 92 for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.REGISTRATION_ITERATION_COUNT; ++invocationIterations) 93 { 94 server.registerMBean(obj, on); 95 server.unregisterMBean(on); 96 } 97 end = System.currentTimeMillis(); 98 99 if (testIterations != 0) 100 { 101 long time = end - start; 102 System.out.print( time + " "); 103 avg += time; 104 } 105 } 106 107 System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT)); 108 } 109 catch (Exception e) 110 { 111 fail(e.toString()); 112 } 113 finally 114 { 115 MBeanServerFactory.releaseMBeanServer(server); 116 } 117 } 118 } 119 | Popular Tags |