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: package com.tctest.spring.integrationtests.tests;
05:
06: import com.tc.test.server.appserver.deployment.Deployment;
07: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
08: import com.tc.test.server.appserver.deployment.ServerTestSetup;
09: import com.tc.test.server.appserver.deployment.WebApplicationServer;
10: import com.tctest.spring.bean.ISingleton;
11: import com.tctest.spring.integrationtests.SpringDeploymentTest;
12:
13: import junit.framework.Test;
14:
15: public class StateMaintainedTest extends SpringDeploymentTest {
16:
17: private static final String APP_NAME = "test-singleton";
18: private static final String REMOTE_SERVICE_NAME = "Singleton";
19: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory.xml";
20: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
21:
22: private WebApplicationServer server1;
23: private WebApplicationServer server2;
24:
25: public static Test suite() {
26: return new ServerTestSetup(StateMaintainedTest.class);
27: }
28:
29: protected void setUp() throws Exception {
30: super .setUp();
31: Deployment deployment = makeDeployment();
32:
33: server1 = makeWebApplicationServer(CONFIG_FILE_FOR_TEST);
34: server1.addWarDeployment(deployment, APP_NAME);
35:
36: server2 = makeWebApplicationServer(CONFIG_FILE_FOR_TEST);
37: server2.addWarDeployment(deployment, APP_NAME);
38: }
39:
40: public void testThatStatePreservedAcrossServerRestart()
41: throws Exception {
42: startServer1();
43:
44: server1.restart();
45:
46: ISingleton singleton1 = (ISingleton) server1.getProxy(
47: ISingleton.class, REMOTE_SERVICE_NAME);
48: assertEquals(1, singleton1.getCounter());
49: singleton1.resetCounter();
50: }
51:
52: private void startServer1() throws Exception {
53: server1.start();
54: ISingleton singleton1 = (ISingleton) server1.getProxy(
55: ISingleton.class, REMOTE_SERVICE_NAME);
56: assertEquals(0, singleton1.getCounter());
57: singleton1.incrementCounter();
58: assertEquals(1, singleton1.getCounter());
59: }
60:
61: public void testThatNewlyStartedServerGetsDistributedState()
62: throws Exception {
63:
64: startServer1();
65:
66: server2.start();
67: ISingleton singleton2 = (ISingleton) server2.getProxy(
68: ISingleton.class, REMOTE_SERVICE_NAME);
69: assertEquals(1, singleton2.getCounter());
70: singleton2.resetCounter();
71: }
72:
73: private Deployment makeDeployment() throws Exception {
74: DeploymentBuilder builder = makeDeploymentBuilder(APP_NAME
75: + ".war");
76: addBeanDefinitions(builder);
77: configureRemoteInterfaces(builder);
78: addClassesAndLibraries(builder);
79: return builder.makeDeployment();
80: }
81:
82: private void addBeanDefinitions(DeploymentBuilder builder) {
83: builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
84: }
85:
86: private void configureRemoteInterfaces(DeploymentBuilder builder) {
87: builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton",
88: ISingleton.class);
89: }
90:
91: private void addClassesAndLibraries(DeploymentBuilder builder) {
92: builder.addDirectoryOrJARContainingClass(ISingleton.class);
93: builder.addDirectoryContainingResource(CONFIG_FILE_FOR_TEST);
94: }
95:
96: }
|