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

📄 forumloadtest.java

📁 如题ServletJSP.rar 为网络收集的JSP网站源文件
💻 JAVA
字号:
package org.redsoft.forum;

import com.meterware.httpunit.*;
import java.io.IOException;
import org.xml.sax.*;
import org.w3c.dom.*;
import java.net.MalformedURLException;
import java.util.*;
import java.io.*;
import java.lang.Thread;

/**
 * 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");
System.out.println(" login = " + login );
        while( true ){
        try{
System.out.println("here");
			HttpUnitOptions.setDefaultCharacterSet("gb2312");
            WebRequest request = new GetMethodWebRequest( "http://202.104.57.170/forum/index.jsp" );
System.out.println("here1");
            WebResponse response = conversation.getResponse( request );
System.out.println( response.getText() );
            WebForm form = response.getForms()[0];
System.out.println("here2");
            request = form.getRequest();
            request.setParameter( "userName", "charles" );
            request.setParameter( "password", "charles" );
System.out.println("here3");
            response = conversation.getResponse( request );
System.out.println( response.getText() );
            /*request = new GetMethodWebRequest( main );
            response = conversation.getResponse( request );
            long begin = System.currentTimeMillis();
            request = new GetMethodWebRequest( uri );
            response = conversation.getResponse( request );
            long end = System.currentTimeMillis();
            request = new GetMethodWebRequest(main );
            response = conversation.getResponse( request );
            request = new GetMethodWebRequest( logout );
            response = conversation.getResponse( request );*/
            sleep( 500 );
        }catch (InterruptedException e){}
         catch ( Exception e ){ e.printStackTrace();}
        }
    }
}
//EOC

⌨️ 快捷键说明

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