1 4 package com.tctest.spring.integrationtests.framework; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 import com.tc.test.TCTestCase; 10 import com.tc.test.TestConfigObject; 11 import com.tc.test.server.tcconfig.StandardTerracottaAppServerConfig; 12 13 import java.io.IOException ; 14 import java.util.ArrayList ; 15 import java.util.Date ; 16 import java.util.HashMap ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 public abstract class AbstractDeploymentTest extends TCTestCase { 21 22 protected Log logger = LogFactory.getLog(getClass()); 23 24 protected ServerManager serverManager; 25 private WatchDog watchDog; 26 27 Map disabledVariants = new HashMap (); 28 List disabledJavaVersion = new ArrayList (); 29 30 private static final int TIMEOUT_DEFAULT = 30 * 60; 31 32 protected void setUp() throws Exception { 33 super.setUp(); 34 serverManager = ServerManagerUtil.start(getClass(), isWithPersistentStore()); 35 } 36 37 public void runBare() throws Throwable { 38 watchDog = new WatchDog(getTimeout()); 39 try { 40 watchDog.startWatching(); 41 super.runBare(); 42 } finally { 43 watchDog.stopWatching(); 44 } 45 } 46 47 protected int getTimeout() throws IOException { 48 String timeout = TestConfigObject.getInstance().springTestsTimeout(); 49 if (timeout == null) { 50 return TIMEOUT_DEFAULT; 51 } else { 52 return Integer.parseInt(timeout); 53 } 54 } 55 56 protected void tearDown() throws Exception { 57 ServerManagerUtil.stop(serverManager); 58 super.tearDown(); 59 } 60 61 protected WebApplicationServer makeWebApplicationServer(String tcConfig) throws Exception { 62 return serverManager.makeWebApplicationServer(tcConfig); 63 } 64 65 protected WebApplicationServer makeWebApplicationServer(FileSystemPath tcConfigPath) throws Exception { 66 return serverManager.makeWebApplicationServer(tcConfigPath); 67 } 68 69 protected WebApplicationServer makeWebApplicationServer(StandardTerracottaAppServerConfig tcConfig) throws Exception { 70 return serverManager.makeWebApplicationServer(tcConfig); 71 } 72 73 protected void restartDSO() throws Exception { 74 serverManager.restartDSO(isWithPersistentStore()); 75 } 76 77 protected DeploymentBuilder makeDeploymentBuilder(String warFileName) { 78 return serverManager.makeDeploymentBuilder(warFileName); 79 } 80 81 86 protected void waitForSuccess(int timeoutInSeconds, TestCallback callback) throws Throwable { 87 long startingTime = System.currentTimeMillis(); 88 long timeout = timeoutInSeconds * 1000; 89 while (true) { 90 try { 91 logger.debug("checking"); 92 callback.check(); 93 logger.debug("check passed"); 94 return; 95 } catch (Throwable e) { 96 logger.debug("check failed"); 97 if ((System.currentTimeMillis() - startingTime) >= timeout) { 98 logger.debug("check timed out", e); 99 throw e; 100 } 101 } 102 logger.debug("check sleeping"); 103 Thread.sleep(100L); 104 } 105 } 106 107 protected StandardTerracottaAppServerConfig getConfigBuilder() { 108 return serverManager.getConfig(); 109 } 110 111 protected void stopAllWebServers() { 112 ServerManagerUtil.stopAllWebServers(serverManager); 113 } 114 115 public boolean isWithPersistentStore() { 116 return false; 117 } 118 119 protected void disableVariant(String variantName, String variantValue) { 120 List variantList = (List )disabledVariants.get(variantName); 121 if (variantList == null) { 122 variantList = new ArrayList (); 123 disabledVariants.put(variantName, variantList); 124 } 125 variantList.add(variantValue); 126 } 127 128 protected void disableForJavaVersion(String version) { 129 this.disabledJavaVersion.add(version); 130 } 131 132 void disableAllTests() { 133 this.disableAllUntil(new Date (Long.MAX_VALUE)); 134 } 135 } 136 | Popular Tags |