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.integrationtests.tests;
006:
007: import com.tc.test.server.appserver.deployment.Deployment;
008: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
009: import com.tc.test.server.appserver.deployment.Server;
010: import com.tc.test.server.appserver.deployment.ServerTestSetup;
011: import com.tc.test.server.appserver.deployment.WebApplicationServer;
012: import com.tctest.spring.bean.FooService;
013: import com.tctest.spring.bean.ISingleton;
014: import com.tctest.spring.integrationtests.SpringDeploymentTest;
015:
016: import junit.framework.Test;
017:
018: /**
019: * Verify various issues with deploying applications
020: */
021: public class DeploymentTest extends SpringDeploymentTest {
022:
023: private static final String FOO_SERVICE_NAME = "Foo";
024: private static final String SINGLETON_SERVICE_NAME = "Singleton";
025: private Deployment singletonWAR;
026: private Deployment fooServiceWAR;
027:
028: public static Test suite() {
029: return new ServerTestSetup(DeploymentTest.class);
030: }
031:
032: protected void setUp() throws Exception {
033: super .setUp();
034: singletonWAR = makeSingletonWAR();
035: fooServiceWAR = makeFooServiceWAR();
036: }
037:
038: protected void runTest() throws Throwable {
039: System.err.println("Running test method: " + this .getName());
040: super .runTest();
041: }
042:
043: private Deployment makeSingletonWAR() throws Exception {
044: DeploymentBuilder builder = makeDeploymentBuilder("test-singleton.war");
045: builder
046: .addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory.xml");
047: builder.addRemoteService(SINGLETON_SERVICE_NAME, "singleton",
048: ISingleton.class);
049: builder.addDirectoryOrJARContainingClass(ISingleton.class);
050: builder
051: .addDirectoryContainingResource("/tc-config-files/singleton-tc-config.xml");
052: return builder.makeDeployment();
053: }
054:
055: private Deployment makeFooServiceWAR() throws Exception {
056: DeploymentBuilder builder = makeDeploymentBuilder("test-parent-child.war");
057: builder
058: .addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory-parent-child.xml");
059: builder.addRemoteService(FOO_SERVICE_NAME, "service1",
060: FooService.class);
061: builder.addDirectoryOrJARContainingClass(FooService.class);
062: builder
063: .addDirectoryContainingResource("/tc-config-files/singleton-tc-config.xml");
064: return builder.makeDeployment();
065: }
066:
067: public void testStartAndStopOneWebAppAndThenStartAnother()
068: throws Exception {
069: startPingAndStop("test-singleton", singletonWAR,
070: "/tc-config-files/singleton-tc-config.xml",
071: new TestServerCallback() {
072: public void test(Server server) throws Exception {
073: ISingleton singleton1 = (ISingleton) server
074: .getProxy(ISingleton.class,
075: SINGLETON_SERVICE_NAME);
076: singleton1.incrementCounter();
077:
078: }
079: });
080:
081: startPingAndStop("test-parent-child", fooServiceWAR,
082: "/tc-config-files/parent-child-tc-config.xml",
083: new TestServerCallback() {
084: public void test(Server server) throws Exception {
085: FooService foo = (FooService) server.getProxy(
086: FooService.class, FOO_SERVICE_NAME);
087: foo.serviceMethod();
088: }
089: });
090: }
091:
092: private void startPingAndStop(String context, Deployment warFile,
093: String tcConfigPath, TestServerCallback testCallback)
094: throws Exception {
095: WebApplicationServer server = makeWebApplicationServer(tcConfigPath);
096: server.addWarDeployment(warFile, context);
097: server.start();
098:
099: testCallback.test(server);
100:
101: server.stopIgnoringExceptions();
102: }
103:
104: public void testDeployingTwoWARsOneDistributedOneNot()
105: throws Exception {
106: Server server1 = makeServerWithTwoWARsOneDistributed();
107: Server server2 = makeServerWithTwoWARsOneDistributed();
108:
109: server1.start();
110: server2.start();
111:
112: SingletonStateUtil.assertSingletonShared(server1, server2,
113: SINGLETON_SERVICE_NAME);
114:
115: assertFooServiceTransient(server1, server2);
116:
117: server1.stopIgnoringExceptions();
118: server2.stopIgnoringExceptions();
119: }
120:
121: private void assertFooServiceTransient(Server server1,
122: Server server2) throws Exception {
123: FooService foo1a = (FooService) server1.getProxy(
124: FooService.class, FOO_SERVICE_NAME);
125: FooService foo2a = (FooService) server2.getProxy(
126: FooService.class, FOO_SERVICE_NAME);
127: int count = foo1a.getCounter();
128: assertEquals("rawValue-" + count, foo1a.serviceMethod());
129: assertEquals("rawValue-" + count, foo2a.serviceMethod());
130: }
131:
132: private Server makeServerWithTwoWARsOneDistributed()
133: throws Exception {
134: return makeWebApplicationServer(
135: "/tc-config-files/singleton-tc-config.xml")
136: .addWarDeployment(singletonWAR, "test-singleton")
137: .addWarDeployment(fooServiceWAR, "test-parent-child");
138: }
139:
140: public void testDeployingTwoDistributedWARs() throws Exception {
141: Server server1 = makeServerWithTwoDistributedWARs();
142: Server server2 = makeServerWithTwoDistributedWARs();
143:
144: server1.start();
145: server2.start();
146:
147: SingletonStateUtil.assertSingletonShared(server1, server2,
148: SINGLETON_SERVICE_NAME);
149:
150: assertFooServiceShared(server1, server2);
151:
152: server1.stopIgnoringExceptions();
153: server2.stopIgnoringExceptions();
154: }
155:
156: private void assertFooServiceShared(Server server1, Server server2)
157: throws Exception {
158: FooService foo1a = (FooService) server1.getProxy(
159: FooService.class, FOO_SERVICE_NAME);
160: FooService foo2a = (FooService) server2.getProxy(
161: FooService.class, FOO_SERVICE_NAME);
162: int counter = foo1a.getCounter();
163:
164: assertEquals("rawValue-" + (counter), foo1a.serviceMethod());
165: assertEquals("rawValue-" + (counter + 1), foo2a.serviceMethod());
166: }
167:
168: private Server makeServerWithTwoDistributedWARs() throws Exception {
169: return makeWebApplicationServer(
170: "/tc-config-files/singleton-parent-child-tc-config.xml")
171: .addWarDeployment(singletonWAR, "test-singleton")
172: .addWarDeployment(fooServiceWAR, "test-parent-child");
173: }
174:
175: }
|