001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest.spring;
006:
007: import org.springframework.context.support.ClassPathXmlApplicationContext;
008:
009: import com.tc.object.config.ConfigVisitor;
010: import com.tc.object.config.DSOClientConfigHelper;
011: import com.tc.object.config.DSOSpringConfigHelper;
012: import com.tc.object.config.Root;
013: import com.tc.object.config.StandardDSOSpringConfigHelper;
014: import com.tc.simulator.app.ApplicationConfig;
015: import com.tc.simulator.listener.ListenerProvider;
016: import com.tc.util.runtime.Vm;
017: import com.tctest.TransparentTestBase;
018: import com.tctest.runner.AbstractTransparentApp;
019: import com.tctest.spring.bean.Recorder;
020:
021: import java.util.ArrayList;
022: import java.util.Date;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: /**
027: * Test for <code>InitializingBean</code>.
028: *
029: * @see org.springframework.beans.factory.InitializingBean
030: */
031: public class InitializingBean_Test extends TransparentTestBase {
032: private static final int LOOP_ITERATIONS = 1;
033: private static final int EXECUTION_COUNT = 1;
034: private static final int NODE_COUNT = 2;
035:
036: public InitializingBean_Test() {
037: if (Vm.isIBM()) {
038: disableAllUntil(new Date(Long.MAX_VALUE));
039: }
040: }
041:
042: protected void setUp() throws Exception {
043: super .setUp();
044: getTransparentAppConfig().setClientCount(NODE_COUNT)
045: .setApplicationInstancePerClientCount(EXECUTION_COUNT)
046: .setIntensity(LOOP_ITERATIONS);
047: initializeTestRunner();
048: }
049:
050: protected Class getApplicationClass() {
051: return InitializingBeanApp.class;
052: }
053:
054: public static class InitializingBeanApp extends
055: AbstractTransparentApp {
056: private List sharedSingletons = new ArrayList();
057:
058: public InitializingBeanApp(String appId, ApplicationConfig cfg,
059: ListenerProvider listenerProvider) {
060: super (appId, cfg, listenerProvider);
061: }
062:
063: public void run() {
064: try {
065: ClassPathXmlApplicationContext ctx;
066: Recorder recorder;
067:
068: synchronized (sharedSingletons) {
069: ctx = new ClassPathXmlApplicationContext(
070: "com/tctest/spring/beanfactory-init.xml");
071: recorder = (Recorder) ctx.getBean("recorder");
072: }
073:
074: moveToStageAndWait(1);
075:
076: int localInitBeanValues = 0;
077: int distributedInitBeanValues = 0;
078: for (Iterator it = recorder.getValues().iterator(); it
079: .hasNext();) {
080: String value = (String) it.next();
081: if ("localInitBean".equals(value)) {
082: localInitBeanValues++;
083: } else if ("distributedInitBean".equals(value)) {
084: distributedInitBeanValues++;
085: }
086: }
087:
088: assertEquals(NODE_COUNT, localInitBeanValues);
089: assertEquals(NODE_COUNT, distributedInitBeanValues);
090:
091: } catch (Throwable e) {
092: moveToStage(1);
093: notifyError(e);
094:
095: }
096: }
097:
098: public static void visitL1DSOConfig(ConfigVisitor visitor,
099: DSOClientConfigHelper config) {
100: config
101: .addRoot(
102: new Root(
103: "com.tctest.spring.MultipleContexts_Test$InitializingBeanApp",
104: "sharedSingletons",
105: "sharedSingletons"), false);
106:
107: DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper();
108: springConfig
109: .addApplicationNamePattern(SpringTestConstants.APPLICATION_NAME); // app name used by testing
110: // framework
111: springConfig.addConfigPattern("*/beanfactory-init.xml");
112: springConfig.addBean("recorder");
113: springConfig.addBean("distributedInitBean");
114: config.addDSOSpringConfig(springConfig);
115: }
116:
117: }
118:
119: }
|