1 15 package org.apache.hivemind.management.mbeans; 16 17 import java.util.HashSet ; 18 import java.util.Set ; 19 20 import junit.framework.TestCase; 21 22 import org.apache.hivemind.service.MethodSignature; 23 24 29 public class TestPerformanceMonitorMBean extends TestCase 30 { 31 35 public void testMeasurement() throws Exception 36 { 37 Set methods = new HashSet (); 38 39 MethodSignature method1 = new MethodSignature(void.class, "method1", 41 new Class [] {}, new Class [] {} ); 42 MethodSignature method2 = new MethodSignature(void.class, "method2", 43 new Class [] {}, new Class [] {} ); 44 methods.add(method1); 45 methods.add(method2); 46 47 PerformanceMonitorMBean monitor = new PerformanceMonitorMBean(methods); 48 monitor.addMeasurement(method1, 100); 49 monitor.addMeasurement(method1, 50); 50 51 monitor.addMeasurement(method2, 1000); 53 monitor.addMeasurement(method2, 500); 54 55 checkAttributeValue(monitor, method1, PerformanceMonitorMBean.DATA_TYPE_MAXIMUM_TIME, 100); 56 checkAttributeValue(monitor, method1, PerformanceMonitorMBean.DATA_TYPE_AVERAGE_TIME, 75); 57 checkAttributeValue(monitor, method1, PerformanceMonitorMBean.DATA_TYPE_MINIMUM_TIME, 50); 58 checkAttributeValue(monitor, method1, PerformanceMonitorMBean.DATA_TYPE_COUNT, 2); 59 checkAttributeValue(monitor, method1, PerformanceMonitorMBean.DATA_TYPE_LAST_TIME, 50); 60 } 61 62 private void checkAttributeValue(PerformanceMonitorMBean monitor, 63 MethodSignature method, String dataType, long expectedValue) throws Exception 64 { 65 String attrName = monitor.buildAttributeName(method, 66 dataType); 67 Long attrValue = (Long ) monitor.getAttribute(attrName); 68 assertEquals(expectedValue, attrValue.longValue() ); 69 } 70 71 } 72 | Popular Tags |