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.IOUtils;
008: import org.apache.tools.ant.filters.StringInputStream;
009:
010: import com.tc.config.schema.builder.InstrumentedClassConfigBuilder;
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.TerracottaConfigBuilder;
017: import com.tc.object.config.StandardDSOClientConfigHelperImpl;
018: import com.tc.util.Assert;
019: import com.tc.util.PortChooser;
020: import com.tctest.runner.AbstractTransparentApp;
021: import com.tctest.runner.TransparentAppConfig;
022:
023: import java.io.File;
024: import java.io.FileOutputStream;
025:
026: public class ClusterMembershipEventJMXTest extends TransparentTestBase {
027:
028: private static final int NODE_COUNT = 1;
029: private int port;
030: private File configFile;
031: private int adminPort;
032:
033: public ClusterMembershipEventJMXTest() {
034: // this.disableAllUntil("2007-06-25");
035: }
036:
037: public void doSetUp(TransparentTestIface t) throws Exception {
038: t.getTransparentAppConfig().setClientCount(NODE_COUNT);
039: t.initializeTestRunner();
040: TransparentAppConfig cfg = t.getTransparentAppConfig();
041: cfg.setAttribute(ClusterMembershipEventJMXTestApp.CONFIG_FILE,
042: configFile.getAbsolutePath());
043: cfg.setAttribute(ClusterMembershipEventJMXTestApp.PORT_NUMBER,
044: String.valueOf(port));
045: cfg.setAttribute(ClusterMembershipEventJMXTestApp.HOST_NAME,
046: "localhost");
047: }
048:
049: protected Class getApplicationClass() {
050: return ClusterMembershipEventJMXTestApp.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:
060: TestTVSConfigurationSetupManagerFactory factory = new TestTVSConfigurationSetupManagerFactory(
061: TestTVSConfigurationSetupManagerFactory.MODE_DISTRIBUTED_CONFIG,
062: null, new FatalIllegalConfigurationChangeHandler());
063:
064: factory.addServerToL1Config(null, port, adminPort);
065: L1TVSConfigurationSetupManager manager = factory
066: .createL1TVSConfigurationSetupManager();
067: setUpControlledServer(factory,
068: new StandardDSOClientConfigHelperImpl(manager), port,
069: adminPort, configFile.getAbsolutePath());
070:
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
080: .copy(new StringInputStream(builder.toString()),
081: out);
082: out.close();
083: } catch (Exception e) {
084: throw Assert.failure("Can't create config file", e);
085: }
086: }
087:
088: public static TerracottaConfigBuilder createConfig(int port,
089: int adminPort) {
090: String testClassName = ClusterMembershipEventJMXTestApp.class
091: .getName();
092: String testClassSuperName = AbstractTransparentApp.class
093: .getName();
094:
095: TerracottaConfigBuilder out = new TerracottaConfigBuilder();
096:
097: out.getServers().getL2s()[0].setDSOPort(port);
098: out.getServers().getL2s()[0].setJMXPort(adminPort);
099: out.getServers().getL2s()[0]
100: .setPersistenceMode(L2ConfigBuilder.PERSISTENCE_MODE_PERMANENT_STORE);
101:
102: InstrumentedClassConfigBuilder instrumented1 = new InstrumentedClassConfigBuilderImpl();
103: instrumented1.setClassExpression(testClassName + "*");
104:
105: InstrumentedClassConfigBuilder instrumented2 = new InstrumentedClassConfigBuilderImpl();
106: instrumented2.setClassExpression(testClassSuperName + "*");
107:
108: out.getApplication().getDSO().setInstrumentedClasses(
109: new InstrumentedClassConfigBuilder[] { instrumented1,
110: instrumented2 });
111:
112: return out;
113: }
114: }
|