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.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.TransparentTestIface;
018: import com.tctest.runner.AbstractTransparentApp;
019: import com.tctest.spring.bean.CrashSingleton;
020:
021: import java.util.Date;
022:
023: /**
024: * Spring singleton tests
025: */
026: public class SingletonCrashTest extends TransparentTestBase {
027: private static final int NODE_COUNT = 2;
028:
029: private static final long TEST_DURATION = 20L * 1000L;
030: private static final long INTERVAL = 1000L;
031:
032: public SingletonCrashTest() {
033: // DEV-755 MNK-259
034: if (Vm.isIBM()) {
035: disableAllUntil(new Date(Long.MAX_VALUE));
036: }
037: }
038:
039: protected boolean canRunCrash() {
040: return true;
041: }
042:
043: public void doSetUp(TransparentTestIface t) throws Exception {
044: t.getTransparentAppConfig().setClientCount(NODE_COUNT);
045: t.initializeTestRunner();
046: }
047:
048: protected Class getApplicationClass() {
049: return SingletonApp.class;
050: }
051:
052: public static class SingletonApp extends AbstractTransparentApp {
053: public SingletonApp(String appId, ApplicationConfig cfg,
054: ListenerProvider listenerProvider) {
055: super (appId, cfg, listenerProvider);
056: }
057:
058: public void run() {
059: long total = TEST_DURATION / INTERVAL;
060: long timeout = System.currentTimeMillis() + TEST_DURATION;
061:
062: try {
063: moveToStageAndWait(1);
064: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
065: "com/tctest/spring/singleton-crash-beanfactory.xml");
066: CrashSingleton singleton = (CrashSingleton) ctx
067: .getBean("singleton");
068:
069: for (int i = 1; i < total; i++) {
070: System.err.println("Loop counter: " + i);
071:
072: singleton.incrementCounter();
073: moveToStageAndWait(i * 10);
074: assertEquals(NODE_COUNT * i, singleton.getCounter());
075: moveToStageAndWait(i * 10 + 1);
076:
077: try {
078: Thread.sleep(INTERVAL);
079: } catch (InterruptedException ex) {
080: }
081: }
082: System.err.println("Closing context ... ");
083: ctx.close();
084: System.err.println("Context closed. ");
085: } catch (Throwable e) {
086: notifyError(e);
087: } finally {
088: for (int i = 1; i < total; i++) {
089: moveToStageAndWait(i * 10);
090: moveToStageAndWait(i * 10 + 1);
091: }
092: }
093:
094: System.err.println("Exiting ... ");
095: }
096:
097: public static void visitL1DSOConfig(ConfigVisitor visitor,
098: DSOClientConfigHelper config) {
099: DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper();
100: springConfig
101: .addApplicationNamePattern("com.tc.object.loaders.IsolationClassLoader"); // app name used by testing
102: // framework
103: springConfig
104: .addConfigPattern("*/singleton-crash-beanfactory.xml");
105: springConfig.addBean("singleton");
106: config.addDSOSpringConfig(springConfig);
107: }
108: }
109: }
|