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 LockStatisticsJMXTest extends TransparentTestBase {
026:
027: private static final int NODE_COUNT = 3;
028: private int port;
029: private File configFile;
030: private int adminPort;
031:
032: public void doSetUp(TransparentTestIface t) throws Exception {
033: t.getTransparentAppConfig().setClientCount(NODE_COUNT);
034: t.initializeTestRunner();
035: TransparentAppConfig cfg = t.getTransparentAppConfig();
036: cfg.setAttribute(LockStatisticsJMXTestApp.CONFIG_FILE,
037: configFile.getAbsolutePath());
038: cfg.setAttribute(LockStatisticsJMXTestApp.PORT_NUMBER, String
039: .valueOf(port));
040: cfg.setAttribute(LockStatisticsJMXTestApp.HOST_NAME,
041: "localhost");
042: cfg.setAttribute(LockStatisticsJMXTestApp.JMX_PORT, String
043: .valueOf(adminPort));
044: }
045:
046: protected Class getApplicationClass() {
047: return LockStatisticsJMXTestApp.class;
048: }
049:
050: public void setUp() throws Exception {
051: PortChooser pc = new PortChooser();
052: port = pc.chooseRandomPort();
053: adminPort = pc.chooseRandomPort();
054: configFile = getTempFile("config-file.xml");
055: writeConfigFile();
056: TestTVSConfigurationSetupManagerFactory factory = new TestTVSConfigurationSetupManagerFactory(
057: TestTVSConfigurationSetupManagerFactory.MODE_DISTRIBUTED_CONFIG,
058: null, new FatalIllegalConfigurationChangeHandler());
059:
060: factory.addServerToL1Config(null, port, adminPort);
061: L1TVSConfigurationSetupManager manager = factory
062: .createL1TVSConfigurationSetupManager();
063: setUpControlledServer(factory,
064: new StandardDSOClientConfigHelperImpl(manager), port,
065: adminPort, configFile.getAbsolutePath());
066: doSetUp(this );
067: }
068:
069: private synchronized void writeConfigFile() {
070: try {
071: TerracottaConfigBuilder builder = createConfig(port,
072: adminPort);
073: FileOutputStream out = new FileOutputStream(configFile);
074: CopyUtils.copy(builder.toString(), out);
075: out.close();
076: } catch (Exception e) {
077: throw Assert.failure("Can't create config file", e);
078: }
079: }
080:
081: public static TerracottaConfigBuilder createConfig(int port,
082: int adminPort) {
083: String testClassName = LockStatisticsJMXTestApp.class.getName();
084: String testClassSuperName = AbstractTransparentApp.class
085: .getName();
086:
087: TerracottaConfigBuilder out = new TerracottaConfigBuilder();
088:
089: out.getServers().getL2s()[0].setDSOPort(port);
090: out.getServers().getL2s()[0].setJMXPort(adminPort);
091: out.getServers().getL2s()[0]
092: .setPersistenceMode(L2ConfigBuilder.PERSISTENCE_MODE_TEMPORARY_SWAP_ONLY);
093:
094: InstrumentedClassConfigBuilder instrumented1 = new InstrumentedClassConfigBuilderImpl();
095: instrumented1.setClassExpression(testClassName + "*");
096:
097: InstrumentedClassConfigBuilder instrumented2 = new InstrumentedClassConfigBuilderImpl();
098: instrumented2.setClassExpression(testClassSuperName + "*");
099:
100: out.getApplication().getDSO().setInstrumentedClasses(
101: new InstrumentedClassConfigBuilder[] { instrumented1,
102: instrumented2 });
103:
104: return out;
105: }
106: }
|