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.tc.test.server.appserver.deployment;
006:
007: import org.apache.commons.logging.Log;
008: import org.apache.commons.logging.LogFactory;
009:
010: import com.tc.test.server.appserver.StandardAppServerParameters;
011: import com.tc.test.server.util.TcConfigBuilder;
012:
013: import junit.framework.Test;
014: import junit.framework.TestSuite;
015:
016: public abstract class AbstractTwoServerDeploymentTest extends
017: AbstractDeploymentTest {
018: public WebApplicationServer server0;
019: public WebApplicationServer server1;
020:
021: public void setServer0(WebApplicationServer server0) {
022: this .server0 = server0;
023: }
024:
025: public void setServer1(WebApplicationServer server1) {
026: this .server1 = server1;
027: }
028:
029: protected boolean shouldKillAppServersEachRun() {
030: return false;
031: }
032:
033: public static abstract class TwoServerTestSetup extends
034: ServerTestSetup {
035: private Log logger = LogFactory.getLog(getClass());
036:
037: private final Class testClass;
038: private final String context;
039: private final TcConfigBuilder tcConfigBuilder;
040:
041: private boolean start = true;
042:
043: protected WebApplicationServer server0;
044: protected WebApplicationServer server1;
045:
046: protected TwoServerTestSetup(Class testClass, String context) {
047: this (testClass, new TcConfigBuilder(), context);
048: }
049:
050: protected TwoServerTestSetup(Class testClass,
051: String tcConfigFile, String context) {
052: this (testClass, new TcConfigBuilder(tcConfigFile), context);
053: }
054:
055: protected TwoServerTestSetup(Class testClass,
056: TcConfigBuilder configBuilder, String context) {
057: super (testClass);
058: this .testClass = testClass;
059: this .context = context;
060: this .tcConfigBuilder = configBuilder;
061: }
062:
063: protected void setStart(boolean start) {
064: this .start = start;
065: }
066:
067: protected void setUp() throws Exception {
068: if (shouldDisable())
069: return;
070: super .setUp();
071: try {
072: getServerManager();
073:
074: long l1 = System.currentTimeMillis();
075: Deployment deployment = makeWAR();
076: long l2 = System.currentTimeMillis();
077: logger.info("### WAR build " + (l2 - l1) / 1000f
078: + " at " + deployment.getFileSystemPath());
079:
080: configureTcConfig(tcConfigBuilder);
081: server0 = createServer(deployment);
082: server1 = createServer(deployment);
083:
084: TestSuite suite = (TestSuite) getTest();
085: for (int i = 0; i < suite.testCount(); i++) {
086: Test t = suite.testAt(i);
087: if (t instanceof AbstractTwoServerDeploymentTest) {
088: AbstractTwoServerDeploymentTest test = (AbstractTwoServerDeploymentTest) t;
089: test.setServer0(server0);
090: test.setServer1(server1);
091: }
092: }
093: } catch (Exception e) {
094: e.printStackTrace();
095: throw e;
096: }
097: }
098:
099: private WebApplicationServer createServer(Deployment deployment)
100: throws Exception {
101: WebApplicationServer server = getServerManager()
102: .makeWebApplicationServer(tcConfigBuilder);
103: configureServerParamers(server.getServerParameters());
104: server.addWarDeployment(deployment, context);
105: if (start) {
106: server.start();
107: }
108: return server;
109: }
110:
111: private Deployment makeWAR() throws Exception {
112: DeploymentBuilder builder = makeDeploymentBuilder(this .context
113: + ".war");
114: builder.addDirectoryOrJARContainingClass(testClass);
115: configureWar(builder);
116: return builder.makeDeployment();
117: }
118:
119: protected abstract void configureWar(DeploymentBuilder builder);
120:
121: protected void configureTcConfig(TcConfigBuilder clientConfig) {
122: // override this method to modify tc-config.xml
123: }
124:
125: protected void configureServerParamers(
126: StandardAppServerParameters params) {
127: // override this method to modify jvm args for app server
128: }
129: }
130:
131: }
|