001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tctest.spring;
005:
006: import org.springframework.context.support.ClassPathXmlApplicationContext;
007:
008: import com.tc.object.config.ConfigVisitor;
009: import com.tc.object.config.DSOClientConfigHelper;
010: import com.tc.object.config.DSOSpringConfigHelper;
011: import com.tc.object.config.StandardDSOSpringConfigHelper;
012: import com.tc.simulator.app.ApplicationConfig;
013: import com.tc.simulator.listener.ListenerProvider;
014: import com.tc.util.runtime.Vm;
015: import com.tctest.TransparentTestBase;
016: import com.tctest.runner.AbstractTransparentApp;
017: import com.tctest.spring.bean.Singleton;
018:
019: import java.util.Date;
020:
021: import javax.management.MBeanServer;
022: import javax.management.ObjectName;
023:
024: /**
025: * Test case for Spring JMX support (require Java 5 to run)
026: */
027: public class JmxSupport_Test extends TransparentTestBase {
028: private static final int LOOP_ITERATIONS = 1;
029: private static final int EXECUTION_COUNT = 1;
030: private static final int NODE_COUNT = 4;
031:
032: public JmxSupport_Test() {
033: if (Vm.isIBM()) {
034: disableAllUntil(new Date(Long.MAX_VALUE));
035: }
036: }
037:
038: protected void setUp() throws Exception {
039: super .setUp();
040: getTransparentAppConfig().setClientCount(NODE_COUNT)
041: .setApplicationInstancePerClientCount(EXECUTION_COUNT)
042: .setIntensity(LOOP_ITERATIONS);
043: initializeTestRunner();
044: }
045:
046: protected Class getApplicationClass() {
047: return JmxSupportApp.class;
048: }
049:
050: public static class JmxSupportApp extends AbstractTransparentApp {
051:
052: public JmxSupportApp(String appId, ApplicationConfig cfg,
053: ListenerProvider listenerProvider) {
054: super (appId, cfg, listenerProvider);
055: }
056:
057: public void run() {
058: try {
059: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
060: "com/tctest/spring/beanfactory-jmx.xml");
061:
062: Singleton singleton = (Singleton) ctx
063: .getBean("singleton");
064: singleton.incrementCounter();
065:
066: moveToStageAndWait(1);
067:
068: MBeanServer beanServer = (MBeanServer) ctx
069: .getBean("mbeanServer");
070:
071: moveToStageAndWait(2);
072:
073: Integer counter = (Integer) beanServer.getAttribute(
074: new ObjectName("bean:name=singleton"),
075: "Counter");
076:
077: assertEquals(
078: "Expecting multiple increments in singleton",
079: NODE_COUNT, singleton.getCounter());
080: assertEquals("Expecting multiple increments in mbean",
081: NODE_COUNT, counter.intValue());
082:
083: } catch (Throwable e) {
084: notifyError(e);
085:
086: }
087: }
088:
089: public static void visitL1DSOConfig(ConfigVisitor visitor,
090: DSOClientConfigHelper config) {
091: DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper();
092: springConfig
093: .addApplicationNamePattern(SpringTestConstants.APPLICATION_NAME); // app name used by testing framework
094: springConfig.addConfigPattern("*/beanfactory-jmx.xml");
095: springConfig.addBean("singleton");
096: config.addDSOSpringConfig(springConfig);
097: }
098:
099: }
100:
101: }
|