1 22 package test.performance.invocationhandler; 23 24 import junit.framework.TestCase; 25 import test.performance.PerformanceSUITE; 26 import test.performance.invocationhandler.support.Standard; 27 import test.performance.invocationhandler.support.StandardMBean; 28 29 import javax.management.*; 30 31 public class ThroughputTEST extends TestCase 32 { 33 34 public ThroughputTEST(String s) 35 { 36 super(s); 37 } 38 39 public void testThroughput() throws Exception 40 { 41 MyThread myThread = new MyThread(); 42 Thread t = new Thread (myThread); 43 44 Integer arg0 = new Integer (1234); 45 int arg1 = 5678; 46 Object [][][] arg2 = new Object [][][] { 47 { 48 { "1x1x1", "1x1x2", "1x1x3" }, 49 { "1x2x1", "1x2x2", "1x2x3" }, 50 { "1x3x1", "1x3x2", "1x3x3" } 51 }, 52 53 { 54 { "2x1x1", "2x1x2", "2x1x3" }, 55 { "2x2x1", "2x2x2", "2x2x3" }, 56 { "2x3x1", "2x3x2", "2x3x3" } 57 }, 58 59 { 60 { "3x1x1", "3x1x2", "3x1x3" }, 61 { "3x2x1", "3x2x2", "3x2x3" }, 62 { "3x3x1", "3x3x2", "3x3x3" } 63 } 64 }; 65 Attribute arg3 = new Attribute("attribute", "value"); 66 67 MBeanServer server = MBeanServerFactory.createMBeanServer(); 68 ObjectName name = new ObjectName("test:test=test"); 69 70 Standard test = new Standard(); 71 server.registerMBean(test, name); 72 StandardMBean proxy = (StandardMBean) MBeanServerInvocationHandler.newProxyInstance( 73 server, name, StandardMBean.class, false); 74 75 t.start(); 76 while(myThread.isKeepRunning()) 77 { 78 proxy.mixedArguments(arg0, arg1, arg2, arg3); 79 } 80 81 System.out.println("\nMBeanServerInvocationHandler Throughput: " + 82 test.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) + 83 " invocations per second."); 84 System.out.println("(Total: " + test.getCount() + ")\n"); 85 } 86 134 class MyThread implements Runnable 135 { 136 137 private boolean keepRunning = true; 138 139 public void run() 140 { 141 try 142 { 143 Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME); 144 } 145 catch (InterruptedException e) 146 { 147 148 } 149 150 keepRunning = false; 151 } 152 153 public boolean isKeepRunning() 154 { 155 return keepRunning; 156 } 157 } 158 } 159 | Popular Tags |