KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > JmxSupport_Test


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
19 import javax.management.ObjectName JavaDoc;
20
21 /**
22  * Test case for Spring JMX support (require Java 5 to run)
23  */

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"); //covered by system test
31
}
32
33   protected void setUp() throws Exception JavaDoc {
34     super.setUp();
35     getTransparentAppConfig()
36         .setClientCount(NODE_COUNT)
37         .setApplicationInstancePerClientCount(EXECUTION_COUNT)
38         .setIntensity(LOOP_ITERATIONS);
39     initializeTestRunner();
40   }
41
42   protected Class JavaDoc getApplicationClass() {
43     return JmxSupportApp.class;
44   }
45   
46
47   public static class JmxSupportApp extends AbstractTransparentApp {
48     
49     public JmxSupportApp(String JavaDoc 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 JavaDoc beanServer = (MBeanServer JavaDoc) ctx.getBean("mbeanServer");
63           
64           moveToStageAndWait(2);
65
66           Integer JavaDoc counter = (Integer JavaDoc) beanServer.getAttribute(new ObjectName JavaDoc("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 JavaDoc 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); // app name used by testing framework
80
springConfig.addConfigPattern("*/beanfactory-jmx.xml");
81       springConfig.addBean("singleton");
82       config.addDSOSpringConfig(springConfig);
83     }
84     
85   }
86
87 }
88
89
Popular Tags