KickJava   Java API By Example, From Geeks To Geeks.

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


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.CrashSingleton;
17
18 /**
19  * Spring singleton tests
20  */

21 public class SingletonCrashTest extends TransparentTestBase {
22   private static final int LOOP_ITERATIONS = 1;
23   private static final int EXECUTION_COUNT = 1;
24   private static final int NODE_COUNT = 2;
25   
26   private static final long TEST_DURATION = 20L * 1000L;
27   private static final long INTERVAL = 1000L;
28   
29   protected boolean canRunCrash() {
30     return true;
31   }
32   
33   protected void setUp() throws Exception JavaDoc {
34     super.setUp();
35     getTransparentAppConfig().setClientCount(NODE_COUNT).setApplicationInstancePerClientCount(EXECUTION_COUNT)
36         .setIntensity(LOOP_ITERATIONS);
37     initializeTestRunner();
38   }
39
40   protected Class JavaDoc getApplicationClass() {
41     return SingletonApp.class;
42   }
43
44   public static class SingletonApp extends AbstractTransparentApp {
45     public SingletonApp(String JavaDoc appId, ApplicationConfig cfg, ListenerProvider listenerProvider) {
46       super(appId, cfg, listenerProvider);
47     }
48
49     public void run() {
50       long total = TEST_DURATION/INTERVAL;
51       long timeout = System.currentTimeMillis() + TEST_DURATION;
52
53       try {
54         moveToStageAndWait(1);
55         ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("com/tctest/spring/singleton-crash-beanfactory.xml");
56         CrashSingleton singleton = (CrashSingleton) ctx.getBean("singleton");
57         
58         for (int i=1; i < total; i++) {
59           System.err.println("Loop counter: " + i);
60           
61           singleton.incrementCounter();
62           moveToStageAndWait(i*10);
63           assertEquals(NODE_COUNT * i, singleton.getCounter());
64           moveToStageAndWait(i*10 + 1);
65           
66           try { Thread.sleep(INTERVAL); } catch(InterruptedException JavaDoc ex) {}
67         }
68         System.err.println("Closing context ... ");
69         ctx.close();
70         System.err.println("Context closed. ");
71       } catch (Throwable JavaDoc e) {
72         notifyError(e);
73       } finally {
74         for (int i=1; i < total; i++) {
75           moveToStageAndWait(i*10);
76           moveToStageAndWait(i*10 + 1);
77         }
78       }
79       
80       System.err.println("Exiting ... ");
81     }
82
83     
84     public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) {
85       DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper();
86       springConfig.addApplicationNamePattern("com.tc.object.loaders.IsolationClassLoader"); // app name used by testing framework
87
springConfig.addConfigPattern("*/singleton-crash-beanfactory.xml");
88       springConfig.addBean("singleton");
89       config.addDSOSpringConfig(springConfig);
90     }
91   }
92 }
93
94
Popular Tags