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.restart;
006:
007: import com.tc.objectserver.control.ServerControl;
008:
009: import java.util.List;
010:
011: public class RestartTestHelper {
012:
013: private final RestartTestEnvironment env;
014: private final ServerCrasherConfigImpl serverCrasherConfig;
015: private final boolean isCrashy;
016: private final ServerControl server;
017:
018: public RestartTestHelper(boolean isCrashy,
019: RestartTestEnvironment env, List jvmArgs) throws Exception {
020: this .isCrashy = isCrashy;
021: this .env = env;
022: serverCrasherConfig = new ServerCrasherConfigImpl();
023:
024: this .env.choosePorts();
025: this .env.setIsPersistent(true);
026: initRestartEnv();
027: env.setUp();
028: server = env.newExtraProcessServer(jvmArgs);
029: serverCrasherConfig.setServer(server);
030: }
031:
032: public ServerControl getServerControl() {
033: return this .server;
034: }
035:
036: public int getServerPort() {
037: return env.getServerPort();
038: }
039:
040: public int getAdminPort() {
041: return env.getAdminPort();
042: }
043:
044: private void initRestartEnv() {
045: if (isCrashy) {
046: initRestartEnvCrashy();
047: } else {
048: initRestartEnvNotCrashy();
049: }
050: }
051:
052: private void initRestartEnvNotCrashy() {
053: System.err
054: .println("INITIALIZING TEST AS A RESTART (CLEAN SHUTDOWN) TEST");
055: env.setIsParanoid(false);
056: serverCrasherConfig.setIsCrashy(false);
057: }
058:
059: private void initRestartEnvCrashy() {
060: System.err
061: .println("INITIALIZING TEST AS A CRASHY (NOT CLEAN SHUTDOWN) TEST");
062: env.setIsParanoid(true);
063: serverCrasherConfig.setIsCrashy(true);
064: }
065:
066: public ServerCrasherConfig getServerCrasherConfig() {
067: return serverCrasherConfig;
068: }
069:
070: public static final class ServerCrasherConfigImpl implements
071: ServerCrasherConfig {
072:
073: private ServerControl serverControl;
074: private boolean isCrashy = true;
075: private long restartInterval = 30 * 1000;
076:
077: public ServerCrasherConfigImpl() {
078: return;
079: }
080:
081: public void setServer(ServerControl serverControl) {
082: this .serverControl = serverControl;
083: }
084:
085: public ServerControl getServerControl() {
086: return serverControl;
087: }
088:
089: public void setIsCrashy(boolean b) {
090: this .isCrashy = b;
091: }
092:
093: public boolean isCrashy() {
094: return this .isCrashy;
095: }
096:
097: public void setRestartInterval(long l) {
098: this .restartInterval = l;
099: }
100:
101: public long getRestartInterval() {
102: return this.restartInterval;
103: }
104:
105: }
106:
107: }
|