001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest;
006:
007: import org.apache.commons.io.IOUtils;
008:
009: import com.tc.config.schema.builder.InstrumentedClassConfigBuilder;
010: import com.tc.config.schema.builder.RootConfigBuilder;
011: import com.tc.config.schema.setup.FatalIllegalConfigurationChangeHandler;
012: import com.tc.config.schema.setup.L1TVSConfigurationSetupManager;
013: import com.tc.config.schema.setup.TestTVSConfigurationSetupManagerFactory;
014: import com.tc.config.schema.test.InstrumentedClassConfigBuilderImpl;
015: import com.tc.config.schema.test.L2ConfigBuilder;
016: import com.tc.config.schema.test.RootConfigBuilderImpl;
017: import com.tc.config.schema.test.TerracottaConfigBuilder;
018: import com.tc.object.config.StandardDSOClientConfigHelperImpl;
019: import com.tc.util.Assert;
020: import com.tc.util.PortChooser;
021: import com.tctest.runner.AbstractTransparentApp;
022: import com.tctest.runner.TransparentAppConfig;
023:
024: import java.io.File;
025: import java.io.FileOutputStream;
026:
027: public class ClientDetectionTest extends TransparentTestBase {
028:
029: private static final int NODE_COUNT = 1;
030: private int port;
031: private File configFile;
032: private int adminPort;
033:
034: public ClientDetectionTest() {
035: //disableAllUntil("2007-09-01");
036: }
037:
038: protected Class getApplicationClass() {
039: return ClientDetectionTestApp.class;
040: }
041:
042: public void doSetUp(TransparentTestIface t) throws Exception {
043: t.getTransparentAppConfig().setClientCount(NODE_COUNT);
044: t.initializeTestRunner();
045: TransparentAppConfig cfg = t.getTransparentAppConfig();
046: cfg.setAttribute(ClientDetectionTestApp.CONFIG_FILE, configFile
047: .getAbsolutePath());
048: cfg.setAttribute(ClientDetectionTestApp.PORT_NUMBER, String
049: .valueOf(port));
050: cfg.setAttribute(ClientDetectionTestApp.HOST_NAME, "localhost");
051: cfg.setAttribute(ClientDetectionTestApp.JMX_PORT, String
052: .valueOf(adminPort));
053: }
054:
055: public void setUp() throws Exception {
056: PortChooser pc = new PortChooser();
057: port = pc.chooseRandomPort();
058: adminPort = 9520; //pc.chooseRandomPort();
059: configFile = getTempFile("tc-config.xml");
060: writeConfigFile();
061: TestTVSConfigurationSetupManagerFactory factory = new TestTVSConfigurationSetupManagerFactory(
062: TestTVSConfigurationSetupManagerFactory.MODE_DISTRIBUTED_CONFIG,
063: null, new FatalIllegalConfigurationChangeHandler());
064:
065: factory.addServerToL1Config(null, port, adminPort);
066: L1TVSConfigurationSetupManager manager = factory
067: .createL1TVSConfigurationSetupManager();
068: setUpControlledServer(factory,
069: new StandardDSOClientConfigHelperImpl(manager), port,
070: adminPort, configFile.getAbsolutePath());
071: doSetUp(this );
072: }
073:
074: private synchronized void writeConfigFile() {
075: try {
076: TerracottaConfigBuilder builder = createConfig(port,
077: adminPort);
078: FileOutputStream out = new FileOutputStream(configFile);
079: IOUtils.write(builder.toString(), out);
080: out.close();
081: } catch (Exception e) {
082: throw Assert.failure("Can't create config file", e);
083: }
084: }
085:
086: public static TerracottaConfigBuilder createConfig(int port,
087: int adminPort) {
088: String testClassName = ClientDetectionTestApp.class.getName();
089: String testClassSuperName = AbstractTransparentApp.class
090: .getName();
091:
092: TerracottaConfigBuilder out = new TerracottaConfigBuilder();
093:
094: out.getServers().getL2s()[0].setDSOPort(port);
095: out.getServers().getL2s()[0].setJMXPort(adminPort);
096: out.getServers().getL2s()[0]
097: .setPersistenceMode(L2ConfigBuilder.PERSISTENCE_MODE_PERMANENT_STORE);
098:
099: InstrumentedClassConfigBuilder instrumented1 = new InstrumentedClassConfigBuilderImpl();
100: instrumented1.setClassExpression(testClassName + "*");
101:
102: InstrumentedClassConfigBuilder instrumented2 = new InstrumentedClassConfigBuilderImpl();
103: instrumented2.setClassExpression(testClassSuperName + "*");
104:
105: out.getApplication().getDSO().setInstrumentedClasses(
106: new InstrumentedClassConfigBuilder[] { instrumented1,
107: instrumented2 });
108:
109: RootConfigBuilder testApp_barrier4 = new RootConfigBuilderImpl(
110: ClientDetectionTestApp.class, "barrier4", "barrier4");
111:
112: RootConfigBuilder L1_barrier4 = new RootConfigBuilderImpl(
113: ClientDetectionTestApp.L1Client.class, "barrier4",
114: "barrier4");
115:
116: out.getApplication().getDSO()
117: .setRoots(
118: new RootConfigBuilder[] { testApp_barrier4,
119: L1_barrier4 });
120:
121: return out;
122: }
123: }
|