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.ConfigLockLevel;
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.StandardDSOSpringConfigHelper;
013: import com.tc.simulator.app.ApplicationConfig;
014: import com.tc.simulator.listener.ListenerProvider;
015: import com.tc.util.runtime.Vm;
016: import com.tctest.TransparentTestBase;
017: import com.tctest.runner.AbstractTransparentApp;
018:
019: import java.util.Date;
020: import java.util.List;
021:
022: /**
023: * Test for logically managed beans, such as java.util.ArrayList
024: */
025: public class LogicalBean_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 LogicalBean_Test() {
031: if (Vm.isIBM()) {
032: 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 LogicalBeanApp.class;
046: }
047:
048: public static class LogicalBeanApp extends AbstractTransparentApp {
049:
050: public LogicalBeanApp(String appId, ApplicationConfig cfg,
051: ListenerProvider listenerProvider) {
052: super (appId, cfg, listenerProvider);
053: }
054:
055: public void run() {
056: try {
057: moveToStageAndWait(10);
058:
059: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
060: "com/tctest/spring/logicalbeans.xml");
061:
062: List list = (List) ctx.getBean("logicalBean");
063: synchronized (list) {
064: list.add(getApplicationId());
065: }
066:
067: moveToStageAndWait(11);
068:
069: synchronized (list) {
070: assertEquals(
071: "Expected more then one object in the collection",
072: NODE_COUNT, list.size());
073: }
074:
075: moveToStageAndWait(12);
076:
077: } catch (Throwable e) {
078: moveToStage(11);
079: moveToStage(12);
080: notifyError(e);
081:
082: }
083: }
084:
085: public static void visitL1DSOConfig(ConfigVisitor visitor,
086: DSOClientConfigHelper config) {
087: config
088: .addIncludePattern("com.tctest.spring.LogicalBean_Test$LogicalBeanApp");
089: config
090: .addAutolock(
091: "* com.tctest.spring.LogicalBean_Test$LogicalBeanApp.run()",
092: ConfigLockLevel.WRITE);
093:
094: {
095: DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper();
096: springConfig
097: .addApplicationNamePattern(SpringTestConstants.APPLICATION_NAME); // app name used by testing framework
098: springConfig.addConfigPattern("*/logicalbeans.xml");
099: springConfig.addBean("logicalBean");
100:
101: config.addDSOSpringConfig(springConfig);
102: }
103: }
104:
105: }
106:
107: }
|