001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.test.stress;
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.io.StringWriter;
022:
023: import javax.servlet.ServletContextEvent;
024: import javax.servlet.ServletContextListener;
025:
026: import org.kuali.rice.config.RiceConfigurer;
027: import org.kuali.rice.database.XAPoolDataSource;
028: import org.kuali.workflow.config.KEWConfigurer;
029: import org.objectweb.jotm.Current;
030: import org.springframework.transaction.jta.JotmFactoryBean;
031:
032: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
033:
034: public class StressTestInitializer implements ServletContextListener {
035:
036: private RiceConfigurer configurer;
037:
038: public void contextInitialized(ServletContextEvent event) {
039: try {
040: this .configurer = configureEmbeddedClient();
041: configurer.start();
042: } catch (Exception e) {
043: throw new WorkflowRuntimeException(e);
044: }
045: //TestRepository repository = TestRepository.getInstance();
046: //String route1XML = loadXML("route1.xml");
047: //repository.addTest(new BasicTest("tkirkend", "StressTestDocument", route1XML, new ArrayList()));
048: }
049:
050: public void contextDestroyed(ServletContextEvent event) {
051: try {
052: configurer.stop();
053: } catch (Exception e) {
054: throw new WorkflowRuntimeException(e);
055: }
056: }
057:
058: private RiceConfigurer configureEmbeddedClient() throws Exception {
059: JotmFactoryBean jotmFactoryBean = new JotmFactoryBean();
060: jotmFactoryBean.setDefaultTimeout(600000);
061: Current jotm = (Current) jotmFactoryBean.getObject();
062:
063: // configure the datasource
064: XAPoolDataSource dataSource = new XAPoolDataSource();
065: dataSource.setTransactionManager(jotm);
066: dataSource
067: .setDriverClassName("oracle.jdbc.driver.OracleDriver");
068: dataSource.setMaxSize(70);
069: dataSource.setMinSize(20);
070: dataSource.setMaxWait(15000);
071: dataSource.setValidationQuery("select 1 from dual");
072: dataSource
073: .setUrl("jdbc:oracle:thin:@es01.uits.indiana.edu:1521:GEN2DEV");
074: dataSource.setUsername("en");
075: dataSource.setPassword("endev");
076:
077: RiceConfigurer configurer = new RiceConfigurer();
078: configurer.setEnvironment("dev");
079: configurer.setMessageEntity("StressTest");
080: configurer.setPlatform("Oracle9i");
081: configurer.setDataSource(dataSource);
082: configurer.setTransactionManager(jotm);
083: configurer.setUserTransaction(jotm);
084: KEWConfigurer kewConfig = new KEWConfigurer();
085: kewConfig
086: .setServiceServletUrl("http://localhost:8080/en-stress/remoting");
087: kewConfig.setClientProtocol("embedded");
088: configurer.getModules().add(kewConfig);
089: return configurer;
090: }
091:
092: private String loadXML(String resourceName) {
093: try {
094: InputStream inputStream = getClass().getClassLoader()
095: .getResourceAsStream(resourceName);
096: StringWriter writer = new StringWriter();
097: int data = -1;
098: while ((data = inputStream.read()) != -1) {
099: writer.write(data);
100: }
101: return writer.toString();
102: } catch (IOException e) {
103: throw new RuntimeException(
104: "Fatal error initializing Stress Tests", e);
105: }
106: }
107:
108: }
|