1 4 package com.tctest.spring.integrationtests.framework; 5 6 import com.tc.config.schema.test.L2ConfigBuilder; 7 import com.tc.config.schema.test.TerracottaConfigBuilder; 8 import com.tc.objectserver.control.ExtraProcessServerControl; 9 import com.tc.test.TestConfigObject; 10 11 import java.io.File ; 12 import java.io.FileOutputStream ; 13 import java.io.IOException ; 14 import java.io.PrintWriter ; 15 16 public class DSOServer extends AbstractStoppable { 17 18 private static final String SPRING_TEST_CONFIG = "spring-test-config.xml"; 19 20 private static final long DSO_SERVER_START_TIMEOUT = 240 * 1000L; 22 23 private ExtraProcessServerControl serverProc = null; 24 private final boolean withPersistentStore; 25 26 private static final int serverPort = 9510; 27 private static final int adminPort = 9999; 28 29 private final File workingDir; 30 31 32 public DSOServer(boolean withPersistentStore, File workingDir) { 33 this.withPersistentStore = withPersistentStore; 34 this.workingDir = workingDir; 35 } 36 37 protected void doStart() throws Exception { 38 File configFile = writeConfig(); 39 serverProc = new ExtraProcessServerControl("localhost", serverPort, adminPort, configFile.getAbsolutePath(), true); 40 serverProc.start(DSO_SERVER_START_TIMEOUT); 41 } 42 43 protected void doStop() throws Exception { 44 logger.debug("Stopping..."); 45 serverProc.shutdown(); 46 logger.debug("...stopped"); 47 } 48 49 private File writeConfig() throws IOException { 50 File configFile = new File (workingDir, SPRING_TEST_CONFIG); 51 52 TerracottaConfigBuilder builder = TerracottaConfigBuilder.newMinimalInstance(); 53 builder.getSystem().setConfigurationModel("development"); 54 55 L2ConfigBuilder l2 = builder.getServers().getL2s()[0]; 56 l2.setDSOPort(serverPort); 57 l2.setJMXPort(adminPort); 58 l2.setData(TestConfigObject.getInstance().tempDirectoryRoot() + File.separator + "data"); 59 l2.setLogs(TestConfigObject.getInstance().tempDirectoryRoot() + File.separator + "logs"); 60 if(withPersistentStore) { 61 l2.setPersistenceMode("permanent-store"); } 63 64 String configAsString = builder.toString(); 65 66 FileOutputStream fileOutputStream = new FileOutputStream (configFile); 67 PrintWriter out = new PrintWriter ((fileOutputStream)); 68 out.println(configAsString); 69 out.flush(); 70 out.close(); 71 return configFile; 72 } 73 74 public String toString() { 75 return "DSO server; serverport:"+serverPort+"; adminPort:"+adminPort; 76 } 77 } 78 | Popular Tags |