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.tctest;
006:
007: import org.apache.commons.io.CopyUtils;
008:
009: import com.tc.config.schema.builder.InstrumentedClassConfigBuilder;
010: import com.tc.config.schema.setup.FatalIllegalConfigurationChangeHandler;
011: import com.tc.config.schema.setup.L1TVSConfigurationSetupManager;
012: import com.tc.config.schema.setup.TestTVSConfigurationSetupManagerFactory;
013: import com.tc.config.schema.test.InstrumentedClassConfigBuilderImpl;
014: import com.tc.config.schema.test.L2ConfigBuilder;
015: import com.tc.config.schema.test.TerracottaConfigBuilder;
016: import com.tc.object.config.StandardDSOClientConfigHelperImpl;
017: import com.tc.util.Assert;
018: import com.tc.util.PortChooser;
019: import com.tctest.runner.AbstractTransparentApp;
020: import com.tctest.runner.TransparentAppConfig;
021:
022: import java.io.File;
023: import java.io.FileOutputStream;
024:
025: public class JMXHeartBeatTest extends TransparentTestBase {
026:
027: private static final int NODE_COUNT = 1;
028: private int port;
029: private File configFile;
030: private int adminPort;
031:
032: public JMXHeartBeatTest() {
033: //this.disableAllUntil("2007-06-25");
034: }
035:
036: public void doSetUp(TransparentTestIface t) throws Exception {
037: t.getTransparentAppConfig().setClientCount(NODE_COUNT);
038: t.initializeTestRunner();
039: TransparentAppConfig cfg = t.getTransparentAppConfig();
040: cfg.setAttribute(JMXHeartBeatTestApp.CONFIG_FILE, configFile
041: .getAbsolutePath());
042: cfg.setAttribute(JMXHeartBeatTestApp.PORT_NUMBER, String
043: .valueOf(port));
044: cfg.setAttribute(JMXHeartBeatTestApp.HOST_NAME, "localhost");
045: cfg.setAttribute(JMXHeartBeatTestApp.JMX_PORT, String
046: .valueOf(adminPort));
047: }
048:
049: protected Class getApplicationClass() {
050: return JMXHeartBeatTestApp.class;
051: }
052:
053: public void setUp() throws Exception {
054: PortChooser pc = new PortChooser();
055: port = pc.chooseRandomPort();
056: adminPort = pc.chooseRandomPort();
057: configFile = getTempFile("config-file.xml");
058: writeConfigFile();
059: TestTVSConfigurationSetupManagerFactory factory = new TestTVSConfigurationSetupManagerFactory(
060: TestTVSConfigurationSetupManagerFactory.MODE_DISTRIBUTED_CONFIG,
061: null, new FatalIllegalConfigurationChangeHandler());
062:
063: factory.addServerToL1Config(null, port, adminPort);
064: L1TVSConfigurationSetupManager manager = factory
065: .createL1TVSConfigurationSetupManager();
066: setUpControlledServer(factory,
067: new StandardDSOClientConfigHelperImpl(manager), port,
068: adminPort, configFile.getAbsolutePath());
069: doSetUp(this );
070: }
071:
072: private synchronized void writeConfigFile() {
073: try {
074: TerracottaConfigBuilder builder = createConfig(port,
075: adminPort);
076: FileOutputStream out = new FileOutputStream(configFile);
077: CopyUtils.copy(builder.toString(), out);
078: out.close();
079: } catch (Exception e) {
080: throw Assert.failure("Can't create config file", e);
081: }
082: }
083:
084: public static TerracottaConfigBuilder createConfig(int port,
085: int adminPort) {
086: String testClassName = JMXHeartBeatTestApp.class.getName();
087: String testClassSuperName = AbstractTransparentApp.class
088: .getName();
089:
090: TerracottaConfigBuilder out = new TerracottaConfigBuilder();
091:
092: out.getServers().getL2s()[0].setDSOPort(port);
093: out.getServers().getL2s()[0].setJMXPort(adminPort);
094: out.getServers().getL2s()[0]
095: .setPersistenceMode(L2ConfigBuilder.PERSISTENCE_MODE_PERMANENT_STORE);
096:
097: InstrumentedClassConfigBuilder instrumented1 = new InstrumentedClassConfigBuilderImpl();
098: instrumented1.setClassExpression(testClassName + "*");
099:
100: InstrumentedClassConfigBuilder instrumented2 = new InstrumentedClassConfigBuilderImpl();
101: instrumented2.setClassExpression(testClassSuperName + "*");
102:
103: out.getApplication().getDSO().setInstrumentedClasses(
104: new InstrumentedClassConfigBuilder[] { instrumented1,
105: instrumented2 });
106:
107: return out;
108: }
109: }
|