01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04:
05: package com.tctest.spring.integrationtests.tests;
06:
07: import com.tc.test.server.appserver.deployment.Deployment;
08: import com.tc.test.server.appserver.deployment.Server;
09: import com.tc.test.server.appserver.deployment.ServerTestSetup;
10: import com.tctest.spring.bean.ISingleton;
11: import com.tctest.spring.integrationtests.SpringDeploymentTest;
12:
13: import junit.framework.Test;
14:
15: public class StartServersStopDSOStartServersAgainTest extends
16: SpringDeploymentTest {
17: private static final String REMOTE_SERVICE_NAME = "Singleton";
18: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory.xml";
19: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
20:
21: public static Test suite() {
22: return new ServerTestSetup(
23: StartServersStopDSOStartServersAgainTest.class, true);
24: }
25:
26: public StartServersStopDSOStartServersAgainTest() {
27: //disableAllUntil("2010-03-01");
28: }
29:
30: public void testStartServersStopDSOStartServersAgain()
31: throws Exception {
32:
33: Deployment warPath = makeDeploymentBuilder("test-singleton.war")
34: .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST)
35: .addRemoteService(REMOTE_SERVICE_NAME, "singleton",
36: ISingleton.class)
37: .addDirectoryOrJARContainingClass(ISingleton.class)
38: .addDirectoryContainingResource(CONFIG_FILE_FOR_TEST)
39: .makeDeployment();
40:
41: Server server1 = makeWebApplicationServer(CONFIG_FILE_FOR_TEST)
42: .addWarDeployment(warPath, "test-singleton");
43: Server server2 = makeWebApplicationServer(CONFIG_FILE_FOR_TEST)
44: .addWarDeployment(warPath, "test-singleton");
45: server1.start();
46: logger.info("*** Started server1");
47: server2.start();
48: logger.info("*** Started server2");
49:
50: ISingleton singleton1 = (ISingleton) server1.getProxy(
51: ISingleton.class, REMOTE_SERVICE_NAME);
52: ISingleton singleton2 = (ISingleton) server2.getProxy(
53: ISingleton.class, REMOTE_SERVICE_NAME);
54:
55: assertCounterShared(singleton1, singleton2);
56: logger.info("*** Assertion1 passed");
57:
58: restartDSO();
59: logger.info("*** DSO restarted");
60:
61: Server server3 = makeWebApplicationServer(CONFIG_FILE_FOR_TEST)
62: .addWarDeployment(warPath, "test-singleton");
63: server3.start();
64: logger.info("*** Started server3");
65:
66: Server server4 = makeWebApplicationServer(CONFIG_FILE_FOR_TEST)
67: .addWarDeployment(warPath, "test-singleton");
68: server4.start();
69: logger.info("*** Started server4");
70:
71: ISingleton singleton3 = (ISingleton) server3.getProxy(
72: ISingleton.class, REMOTE_SERVICE_NAME);
73: ISingleton singleton4 = (ISingleton) server4.getProxy(
74: ISingleton.class, REMOTE_SERVICE_NAME);
75:
76: assertCounterShared(singleton3, singleton4);
77:
78: logger.info("*** Test completed");
79: }
80:
81: private void assertCounterShared(ISingleton singleton1,
82: ISingleton singleton2) {
83: assertEquals(singleton1.getCounter(), singleton2.getCounter());
84:
85: singleton1.incrementCounter();
86: assertEquals(singleton1.getCounter(), singleton2.getCounter());
87:
88: singleton2.incrementCounter();
89: assertEquals(singleton2.getCounter(), singleton1.getCounter());
90: }
91:
92: public boolean isWithPersistentStore() {
93: return true;
94: }
95:
96: }
|