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:
006: package com.tctest.spring.integrationtests.tests;
007:
008: import com.tc.test.server.appserver.deployment.Deployment;
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.TestCallback;
012: import com.tc.test.server.appserver.deployment.WebApplicationServer;
013: import com.tctest.spring.bean.RedeploymentBean;
014: import com.tctest.spring.integrationtests.SpringDeploymentTest;
015:
016: import java.util.Date;
017:
018: import junit.framework.Test;
019:
020: /**
021: * Test ApplicationContext definition
022: *
023: * LKC-1753: Test: Dynamic WAR deployment https://jira.terracotta.lan/jira//browse/LKC-1753
024: *
025: * LKC-2340: Redeployed web applications will almost certainly run into ClassCastExceptions for shared app level objects
026: * https://jira.terracotta.lan/jira/browse/LKC-2340
027: *
028: * Hot deploy war Undeploy war Re-deploy war
029: *
030: * Investigate how to do this - Cargo/tomcat does not support hot deployment
031: *
032: * TODO currently it is not possible to hot deploy or undeploy wars on Tomcat
033: */
034: public class RedeploymentTest extends SpringDeploymentTest {
035:
036: public static Test suite() {
037: return new ServerTestSetup(RedeploymentTest.class);
038: }
039:
040: public RedeploymentTest() {
041: disableAllUntil("2010-09-20");
042: }
043:
044: public void testRedeployment() throws Throwable {
045: Deployment deployment11 = createWarWithService(
046: "redeployment1.war", "redeploymentBean1");
047: Deployment deployment21 = createWarWithService(
048: "redeployment2.war", "redeploymentBean1");
049:
050: long l1 = deployment11.getFileSystemPath().getFile()
051: .lastModified();
052: logger.info(deployment11.getFileSystemPath() + " "
053: + new Date(l1));
054:
055: final WebApplicationServer server1 = createServer(deployment11);
056: final WebApplicationServer server2 = createServer(deployment21);
057:
058: verifyClustered("redeploymentBean1", 15, server1, server2);
059:
060: Deployment deployment12 = createWarWithService(
061: "redeployment1a.war", "redeploymentBean1");
062: long l2 = deployment12.getFileSystemPath().getFile()
063: .lastModified();
064: logger.info(deployment12.getFileSystemPath() + " "
065: + new Date(l2));
066:
067: server1.undeployWar(deployment11, "redeployment");
068: server1.deployWar(deployment12, "redeployment");
069:
070: try {
071: server1.ping("/redeployment");
072: } catch (Throwable e) {
073: // ignore
074: }
075: try {
076: Thread.sleep(1000L * 120);
077: } catch (Exception ex) {
078: // ignore
079: }
080:
081: waitForSuccess(60, new TestCallback() {
082: public void check() throws Exception {
083: server1.getProxy(RedeploymentBean.class,
084: "redeploymentBean1");
085: }
086: });
087:
088: verifyClustered("redeploymentBean1", 16, server1, server2);
089: }
090:
091: private void verifyClustered(String serviceName, int n,
092: Server server1, Server server2) throws Exception {
093: RedeploymentBean bean1 = (RedeploymentBean) server1.getProxy(
094: RedeploymentBean.class, serviceName);
095: RedeploymentBean bean2 = (RedeploymentBean) server2.getProxy(
096: RedeploymentBean.class, serviceName);
097:
098: bean1.setValue(n);
099: assertEquals("Expected shared value", n, bean2.getValue());
100:
101: bean2.setValue(n + 12);
102: assertEquals("Expected shared value", n + 12, bean1.getValue());
103: }
104:
105: public Deployment createWarWithService(String warName,
106: String serviceName) throws Exception {
107: return makeDeploymentBuilder(warName)
108: .addDirectoryOrJARContainingClass(
109: RedeploymentBean.class)
110: .addDirectoryContainingResource(
111: "/tc-config-files/redeployment-tc-config.xml")
112: .addBeanDefinitionFile(
113: "classpath:/com/tctest/spring/redeployment.xml")
114: .addRemoteService(serviceName, "redeploymentBean",
115: RedeploymentBean.class).makeDeployment();
116: }
117:
118: private WebApplicationServer createServer(Deployment deployment)
119: throws Exception {
120: WebApplicationServer server = makeWebApplicationServer("/tc-config-files/redeployment-tc-config.xml");
121:
122: server.addWarDeployment(deployment, "redeployment");
123: server.start();
124:
125: return server;
126: }
127:
128: }
|