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.ActiveBean;
018:
019: import java.util.Date;
020: import java.util.List;
021:
022: /**
023: * ActiveBean test
024: */
025: public class ActiveBean_Test extends TransparentTestBase {
026: private static final int LOOP_ITERATIONS = 1;
027: private static final int EXECUTION_COUNT = 1;
028: private static final int NODE_COUNT = 2;
029:
030: public ActiveBean_Test() {
031: if (Vm.isIBM()) {
032: this .disableAllUntil(new Date(Long.MAX_VALUE));
033: }
034: }
035:
036: protected void setUp() throws Exception {
037: super .setUp();
038: getTransparentAppConfig().setClientCount(NODE_COUNT)
039: .setApplicationInstancePerClientCount(EXECUTION_COUNT)
040: .setIntensity(LOOP_ITERATIONS);
041: initializeTestRunner();
042: }
043:
044: protected Class getApplicationClass() {
045: return ActiveBeanApp.class;
046: }
047:
048: public static class ActiveBeanApp extends AbstractTransparentApp {
049:
050: public ActiveBeanApp(String appId, ApplicationConfig cfg,
051: ListenerProvider listenerProvider) {
052: super (appId, cfg, listenerProvider);
053: }
054:
055: public void run() {
056: testActiveBean();
057: }
058:
059: private void testActiveBean() {
060: try {
061: moveToStageAndWait(10);
062:
063: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
064: "com/tctest/spring/beanfactory-active.xml");
065:
066: ActiveBean activeBean = (ActiveBean) ctx
067: .getBean("activeBean");
068:
069: moveToStageAndWait(11);
070:
071: Thread.sleep(500L); // to make sure that thread will start
072:
073: List instances = activeBean.getInstances();
074: assertEquals("Expecting single bean instance "
075: + instances, 1, instances.size());
076:
077: moveToStageAndWait(12);
078:
079: ctx.close();
080:
081: moveToStageAndWait(13);
082:
083: instances = activeBean.getInstances();
084:
085: assertTrue("Active bean is not stopped", activeBean
086: .isStopped());
087:
088: moveToStageAndWait(14);
089:
090: assertEquals("Expecting no instances " + instances, 0,
091: instances.size());
092:
093: } catch (Throwable e) {
094: moveToStage(10);
095: moveToStage(11);
096: moveToStage(12);
097: moveToStage(13);
098: moveToStage(14);
099: notifyError(e);
100:
101: } finally {
102: //
103: }
104: }
105:
106: public static void visitL1DSOConfig(ConfigVisitor visitor,
107: DSOClientConfigHelper config) {
108: DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper();
109: springConfig
110: .addApplicationNamePattern(SpringTestConstants.APPLICATION_NAME); // app name used by testing framework
111: springConfig.addConfigPattern("*/beanfactory-active.xml");
112: springConfig.addBean("activeBean");
113:
114: config.addDSOSpringConfig(springConfig);
115: }
116:
117: }
118:
119: }
|