OkHttpDebug.java 2.18 KB
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.taover.util.UtilHttpByOkHttp;

public class OkHttpDebug {
	public static void main(String args[]) {
		//loadRequestPerMinute(10);
				
		//testWarePushOrder(100);
		
		multiRequest(10);
	}

	private static void multiRequest(int count) {
		for(int sequence=0; sequence<count; ++sequence) {
			new RequestThread(sequence).start();
		}
	}
	
	private static void testWarePushOrder(int pushCount) {
		Map<String, Object> params = new HashMap<String, Object>();		
		for(int i=0; i<pushCount; ++i) {
			try {
				if(i%2 == 0) {
					params.put("wareId", 20);
				}else {
					params.put("wareId", 34);
				}				
				Thread.sleep(3000);
				long starTime = System.currentTimeMillis();
				String response = UtilHttpByOkHttp.sendPostForm("http://localhost/api/schedule/ware/order", null, params);
				long endTime = System.currentTimeMillis();
				System.out.println("success["+i+"]["+(endTime-starTime)+"]:"+response);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	private static void loadRequestPerMinute(int i) {
		double gapSecond = 60.0/i;
		int sequence = 0;
		while(true) {
			++sequence;
			new RequestThread(sequence).start();
			try {
				Thread.sleep((long)(gapSecond*1000));
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}


class RequestThread extends Thread{
	int sequence = 0;
	public RequestThread(int sequence) {
		this.sequence = sequence;
	}
	
	@Override
	public void run() {
		try {
			long starTime = System.currentTimeMillis();
			UtilHttpByOkHttp.sendGet("http://api.wxorder.taover.com/v1/wxorderorder?page=1&size=100&controlStatus=", Collections.singletonMap("Authorization", "bearer;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0ZW5hbnQiOiIxNiIsInVzZXJuYW1lIjoiMTM2MjEwNTEyMzAiLCJ1c2VyaWQiOiIxNyIsImlzcyI6ImFkbWluIiwiYXVkIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJleHAiOjE2MDI4NDM5MzIsIm5iZiI6MTYwMjY3MTEzMn0.PbXwPqpFYQB7dwAeB9ELr6dho29k_YZCtcVoECeo-wM"), 60);
			Thread.sleep(2000);
			long endTime = System.currentTimeMillis();
			System.out.println("success["+this.sequence+"]:"+(endTime-starTime));
		} catch (Exception e) {
			System.out.println("fail");
		}
	}
}