1 22 package test.performance.dynamic; 23 24 import junit.framework.TestCase; 25 import test.performance.PerformanceSUITE; 26 import test.performance.dynamic.support.Dyn; 27 28 import javax.management.*; 29 30 31 public class ThroughputTEST extends TestCase 32 { 33 34 public ThroughputTEST(String s) 35 { 36 super(s); 37 } 38 39 public void testInvocation() 40 { 41 try 42 { 43 MyThread myThread = new MyThread(); 44 Thread t = new Thread (myThread); 45 46 MBeanServer server = MBeanServerFactory.createMBeanServer(); 47 ObjectName name = new ObjectName("Domain:performanceTest=dynamic"); 48 Dyn mbean = new Dyn(); 49 50 String method = "mixedArguments"; 51 String [] signature = new String [] { 52 Integer .class.getName(), 53 int.class.getName(), 54 Object [][][].class.getName(), 55 Attribute.class.getName() 56 }; 57 58 Object [] args = new Object [] { 59 new Integer (1234), 60 new Integer (455617), 61 new Object [][][] { 62 { 63 { "1x1x1", "1x1x2", "1x1x3" }, 64 { "1x2x1", "1x2x2", "1x2x3" }, 65 { "1x3x1", "1x3x2", "1x3x3" } 66 }, 67 68 { 69 { "2x1x1", "2x1x2", "2x1x3" }, 70 { "2x2x1", "2x2x2", "2x2x3" }, 71 { "2x3x1", "2x3x2", "2x3x3" } 72 }, 73 74 { 75 { "3x1x1", "3x1x2", "3x1x3" }, 76 { "3x2x1", "3x2x2", "3x2x3" }, 77 { "3x3x1", "3x3x2", "3x3x3" } 78 } 79 }, 80 new Attribute("attribute", "value") 81 }; 82 83 server.registerMBean(mbean, name); 84 85 assertTrue(mbean.getCount() == 0); 86 87 t.start(); 88 while(myThread.isKeepRunning()) 89 { 90 Object o = server.invoke(name, method, args, signature); 91 } 92 93 System.out.println("\nDynamic MBean Throughput: " + 94 mbean.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) + 95 " invocations per second."); 96 System.out.println("(Total: " + mbean.getCount() + ")\n"); 97 100 } 101 catch (Throwable t) 102 { 103 t.printStackTrace(); 104 fail("Unexpected error: " + t.toString()); 105 } 106 } 107 108 109 public void testInvocationWithDefaultDomain() 110 { 111 try 112 { 113 MyThread myThread = new MyThread(); 114 Thread t = new Thread (myThread); 115 116 MBeanServer server = MBeanServerFactory.createMBeanServer(); 117 ObjectName name = new ObjectName(":performanceTest=dynamic"); 118 Dyn mbean = new Dyn(); 119 120 String method = "mixedArguments"; 121 String [] signature = new String [] { 122 Integer .class.getName(), 123 int.class.getName(), 124 Object [][][].class.getName(), 125 Attribute.class.getName() 126 }; 127 128 Object [] args = new Object [] { 129 new Integer (1234), 130 new Integer (455617), 131 new Object [][][] { 132 { 133 { "1x1x1", "1x1x2", "1x1x3" }, 134 { "1x2x1", "1x2x2", "1x2x3" }, 135 { "1x3x1", "1x3x2", "1x3x3" } 136 }, 137 138 { 139 { "2x1x1", "2x1x2", "2x1x3" }, 140 { "2x2x1", "2x2x2", "2x2x3" }, 141 { "2x3x1", "2x3x2", "2x3x3" } 142 }, 143 144 { 145 { "3x1x1", "3x1x2", "3x1x3" }, 146 { "3x2x1", "3x2x2", "3x2x3" }, 147 { "3x3x1", "3x3x2", "3x3x3" } 148 } 149 }, 150 new Attribute("attribute", "value") 151 }; 152 153 server.registerMBean(mbean, name); 154 155 assertTrue(mbean.getCount() == 0); 156 157 t.start(); 158 while(myThread.isKeepRunning()) 159 { 160 Object o = server.invoke(name, method, args, signature); 161 } 162 163 System.out.println("\nDynamic MBean Throughput (DEFAULTDOMAIN): " + 164 mbean.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) + 165 " invocations per second."); 166 System.out.println("(Total: " + mbean.getCount() + ")\n"); 167 168 } 169 catch (Throwable t) 170 { 171 t.printStackTrace(); 172 fail("Unexpected error: " + t.toString()); 173 } 174 } 175 176 class MyThread implements Runnable 177 { 178 179 private boolean keepRunning = true; 180 181 public void run() 182 { 183 try 184 { 185 Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME); 186 } 187 catch (InterruptedException e) 188 { 189 190 } 191 192 keepRunning = false; 193 } 194 195 public boolean isKeepRunning() 196 { 197 return keepRunning; 198 } 199 } 200 201 } 202 | Popular Tags |