⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forumloadtest.java

📁 Chinaxp 论坛源代码
💻 JAVA
字号:
package org.redsoft.forum;import java.io.File;import java.io.FileInputStream;import java.util.Properties;import com.meterware.httpunit.GetMethodWebRequest;import com.meterware.httpunit.HttpUnitOptions;import com.meterware.httpunit.WebConversation;import com.meterware.httpunit.WebForm;import com.meterware.httpunit.WebRequest;import com.meterware.httpunit.WebResponse;/** * A program that would keep sending http request to the online box to test * how the forum works under heavy load * * @author Charles Huang * @version 1.0 */public class ForumLoadTest{    int currentUser = -1;    public void setConcurrentUsers( int number ){        currentUser = number;    }    public ForumLoadTest() throws Exception {    	/*System.getProperties().put( "proxySet", "true" );		System.getProperties().put( "proxyHost", "proxy.compaq.com" );		System.getProperties().put( "proxyPort", "8080" );*/    }    public void bombard(){        for( int index = 1; index <=currentUser; index++ ){System.out.println("creating thread_" + index );            new HrefThread( index ).start();        }    }    public static void main(String args[]) {        try{            final ForumLoadTest loadTest = new ForumLoadTest();            loadTest.setConcurrentUsers( Integer.parseInt( args[0] ) );            loadTest.bombard();        }catch( final Exception e ){            e.printStackTrace();        }	}}/** *  A thread that simulates that a client accesses the website by click a href *  link */class HrefThread extends Thread{    String uri;    int id;    final Properties props = new Properties();    String mainScreenURI;    final WebConversation   conversation = new WebConversation();    public HrefThread( final int id ){        this.id = id;        try{            props.load( new FileInputStream( new File("loadTest.properties") ));        }catch( final Exception e ){ e.printStackTrace(); }    }    public void run(){        String uri = props.getProperty( "uri_" + id);        String login = props.getProperty( "uri_logon");        while( true ){        try{			HttpUnitOptions.setDefaultCharacterSet("gb2312");            WebRequest request = new GetMethodWebRequest( "http://localhost/forum/logon.jsp" );            WebResponse response = conversation.getResponse( request );            WebForm form = response.getForms()[0];            request = form.getRequest();            request.setParameter( "userName", "charles" );            request.setParameter( "password", "charles" );            response = conversation.getResponse( request );            String url = props.getProperty( "uri_" + id );            request = new GetMethodWebRequest( url );            System.out.println( conversation.getResponse( request ).getTitle() );            sleep( 100 );        }catch (InterruptedException e){}         catch ( Exception e ){ e.printStackTrace();}        }    }}//EOC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -