1 4 package com.tctest.spring; 5 6 import org.springframework.context.support.ClassPathXmlApplicationContext; 7 8 import com.tc.object.config.ConfigVisitor; 9 import com.tc.object.config.DSOClientConfigHelper; 10 import com.tc.object.config.DSOSpringConfigHelper; 11 import com.tc.object.config.StandardDSOSpringConfigHelper; 12 import com.tc.simulator.app.ApplicationConfig; 13 import com.tc.simulator.listener.ListenerProvider; 14 import com.tctest.TransparentTestBase; 15 import com.tctest.runner.AbstractTransparentApp; 16 import com.tctest.spring.bean.Singleton; 17 18 import javax.management.MBeanServer ; 19 import javax.management.ObjectName ; 20 21 24 public class JmxSupport_Test extends TransparentTestBase { 25 private static final int LOOP_ITERATIONS = 1; 26 private static final int EXECUTION_COUNT = 1; 27 private static final int NODE_COUNT = 4; 28 29 public JmxSupport_Test() { 30 disableAllUntil("2008-01-01"); } 32 33 protected void setUp() throws Exception { 34 super.setUp(); 35 getTransparentAppConfig() 36 .setClientCount(NODE_COUNT) 37 .setApplicationInstancePerClientCount(EXECUTION_COUNT) 38 .setIntensity(LOOP_ITERATIONS); 39 initializeTestRunner(); 40 } 41 42 protected Class getApplicationClass() { 43 return JmxSupportApp.class; 44 } 45 46 47 public static class JmxSupportApp extends AbstractTransparentApp { 48 49 public JmxSupportApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 50 super(appId, cfg, listenerProvider); 51 } 52 53 public void run() { 54 try { 55 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("com/tctest/spring/beanfactory-jmx.xml"); 56 57 Singleton singleton = (Singleton) ctx.getBean("singleton"); 58 singleton.incrementCounter(); 59 60 moveToStageAndWait(1); 61 62 MBeanServer beanServer = (MBeanServer ) ctx.getBean("mbeanServer"); 63 64 moveToStageAndWait(2); 65 66 Integer counter = (Integer ) beanServer.getAttribute(new ObjectName ("bean:name=singleton"), "Counter"); 67 68 assertEquals("Expecting multiple increments in singleton", NODE_COUNT, singleton.getCounter()); 69 assertEquals("Expecting multiple increments in mbean", NODE_COUNT, counter.intValue()); 70 71 } catch (Throwable e) { 72 notifyError(e); 73 74 } 75 } 76 77 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 78 DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper(); 79 springConfig.addApplicationNamePattern(SpringTestConstants.APPLICATION_NAME); springConfig.addConfigPattern("*/beanfactory-jmx.xml"); 81 springConfig.addBean("singleton"); 82 config.addDSOSpringConfig(springConfig); 83 } 84 85 } 86 87 } 88 89 | Popular Tags |