KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > integrationtests > tests > RedeploymentTest


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
5 package com.tctest.spring.integrationtests.tests;
6
7 import com.tctest.spring.bean.RedeploymentBean;
8 import com.tctest.spring.integrationtests.framework.AbstractDeploymentTest;
9 import com.tctest.spring.integrationtests.framework.Deployment;
10 import com.tctest.spring.integrationtests.framework.Server;
11 import com.tctest.spring.integrationtests.framework.TestCallback;
12 import com.tctest.spring.integrationtests.framework.WebApplicationServer;
13
14 import java.util.Date JavaDoc;
15
16
17 /**
18  * Test ApplicationContext definition
19  *
20  * LKC-1753: Test: Dynamic WAR deployment
21  * https://jira.terracotta.lan/jira//browse/LKC-1753
22  *
23  * LKC-2340: Redeployed web applications will almost certainly run into ClassCastExceptions for shared app level objects
24  * https://jira.terracotta.lan/jira/browse/LKC-2340
25  *
26  * Hot deploy war
27  * Undeploy war
28  * Re-deploy war
29  *
30  * Investigate how to do this - Cargo/tomcat does not support hot deployment
31  *
32  * TODO currently it is not possible to hot deploy or undeploy wars on Tomcat
33  */

34 public class RedeploymentTest extends AbstractDeploymentTest {
35
36   public RedeploymentTest() {
37     disableAllUntil("2007-09-20");
38   }
39
40   public void testRedeployment() throws Throwable JavaDoc {
41     Deployment deployment11 = createWarWithService("redeployment1.war", "redeploymentBean1");
42     Deployment deployment21 = createWarWithService("redeployment2.war", "redeploymentBean1");
43
44     long l1 = deployment11.getFileSystemPath().getFile().lastModified();
45     logger.info(deployment11.getFileSystemPath()+" "+new Date JavaDoc(l1));
46
47     final WebApplicationServer server1 = createServer(deployment11);
48     final WebApplicationServer server2 = createServer(deployment21);
49
50     verifyClustered("redeploymentBean1", 15, server1, server2);
51
52     Deployment deployment12 = createWarWithService("redeployment1a.war", "redeploymentBean1");
53     long l2 = deployment12.getFileSystemPath().getFile().lastModified();
54     logger.info(deployment12.getFileSystemPath()+" "+new Date JavaDoc(l2));
55
56     server1.undeployWar(deployment11, "redeployment");
57     server1.deployWar(deployment12, "redeployment");
58
59     try {
60       server1.ping("/redeployment");
61     } catch (Throwable JavaDoc e) {
62       // ignore
63
}
64     try {
65       Thread.sleep(1000L * 120);
66     } catch(Exception JavaDoc ex) {
67       // ignore
68
}
69
70     waitForSuccess(60, new TestCallback() {
71         public void check() throws Exception JavaDoc {
72           server1.getProxy(RedeploymentBean.class, "redeploymentBean1");
73         }
74       });
75
76     verifyClustered("redeploymentBean1", 16, server1, server2);
77   }
78
79   private void verifyClustered(String JavaDoc serviceName, int n, Server server1, Server server2) throws Exception JavaDoc {
80     RedeploymentBean bean1 = (RedeploymentBean) server1.getProxy(RedeploymentBean.class, serviceName);
81     RedeploymentBean bean2 = (RedeploymentBean) server2.getProxy(RedeploymentBean.class, serviceName);
82
83     bean1.setValue(n);
84     assertEquals("Expected shared value", n, bean2.getValue());
85
86     bean2.setValue(n+12);
87     assertEquals("Expected shared value", n+12, bean1.getValue());
88   }
89
90   public Deployment createWarWithService(String JavaDoc warName, String JavaDoc serviceName) throws Exception JavaDoc {
91     return makeDeploymentBuilder(warName)
92         .addDirectoryOrJARContainingClass(RedeploymentBean.class)
93         .addDirectoryContainingResource("/tc-config-files/redeployment-tc-config.xml")
94         .addBeanDefinitionFile("classpath:/com/tctest/spring/redeployment.xml")
95         .addRemoteService(serviceName, "redeploymentBean", RedeploymentBean.class)
96         .makeDeployment();
97   }
98
99
100   private WebApplicationServer createServer(Deployment deployment) throws Exception JavaDoc {
101     WebApplicationServer server = makeWebApplicationServer("/tc-config-files/redeployment-tc-config.xml");
102
103     server.addWarDeployment(deployment, "redeployment");
104     server.start();
105
106     return server;
107   }
108
109 }
110
111
Popular Tags