1 4 package com.tc.test.restart; 5 6 import com.tc.objectserver.control.ServerControl; 7 8 9 public class RestartTestHelper { 10 11 private final RestartTestEnvironment env; 12 private final ServerCrasherConfigImpl serverCrasherConfig; 13 private final boolean isCrashy; 14 private final ServerControl server; 15 16 public RestartTestHelper(boolean isCrashy, RestartTestEnvironment env) throws Exception { 17 this.isCrashy = isCrashy; 18 this.env = env; 19 serverCrasherConfig = new ServerCrasherConfigImpl(); 20 21 env.choosePorts(); 22 env.setIsPersistent(true); 23 initRestartEnv(); 24 env.setUp(); 25 server = env.newExtraProcessServer(); 26 serverCrasherConfig.setServer(server); 27 } 28 29 public ServerControl getServerControl() { 30 return this.server; 31 } 32 33 public int getServerPort() { 34 return env.getServerPort(); 35 } 36 37 private void initRestartEnv() { 38 if (isCrashy) { 39 initRestartEnvCrashy(); 40 } else { 41 initRestartEnvNotCrashy(); 42 } 43 } 44 45 private void initRestartEnvNotCrashy() { 46 System.err.println("INITIALIZING TEST AS A RESTART (CLEAN SHUTDOWN) TEST"); 47 env.setIsParanoid(false); 48 serverCrasherConfig.setIsCrashy(false); 49 } 50 51 private void initRestartEnvCrashy() { 52 System.err.println("INITIALIZING TEST AS A CRASHY (NOT CLEAN SHUTDOWN) TEST"); 53 env.setIsParanoid(true); 54 serverCrasherConfig.setIsCrashy(true); 55 } 56 57 58 public ServerCrasherConfig getServerCrasherConfig() { 59 return serverCrasherConfig; 60 } 61 62 public static final class ServerCrasherConfigImpl implements ServerCrasherConfig { 63 64 private ServerControl serverControl; 65 private boolean isCrashy = true; 66 private long restartInterval = 30 * 1000; 67 68 public ServerCrasherConfigImpl() { 69 return; 70 } 71 72 public void setServer(ServerControl serverControl) { 73 this.serverControl = serverControl; 74 } 75 76 public ServerControl getServerControl() { 77 return serverControl; 78 } 79 80 public void setIsCrashy(boolean b) { 81 this.isCrashy = b; 82 } 83 84 public boolean isCrashy() { 85 return this.isCrashy; 86 } 87 88 public void setRestartInterval(long l) { 89 this.restartInterval = l; 90 } 91 92 public long getRestartInterval() { 93 return this.restartInterval; 94 } 95 96 } 97 98 } 99 | Popular Tags |