Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add loadProperties() #30

Merged
merged 1 commit into from
May 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,29 @@

package com.weibo.motan.benchmark;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MotanBenchmarkClient extends AbstractBenchmarkClient {

static Properties properties = new Properties();
private static boolean isMultiClient; //并发的Runable线程,是否使用相同的client进行调用。
// true:并发线程只使用一个client(bean实例)调用服务。
// false: 每个并发线程使用不同的Client调用服务
/**
* 并发的Runable线程,是否使用相同的client进行调用。
* true:并发线程只使用一个client(bean实例)调用服务。
* false: 每个并发线程使用不同的Client调用服务
*/
private static BenchmarkService benchmarkService;
private static boolean isMultiClient;


public static void main(String[] args) {
loadProperties();
int concurrents = Integer.parseInt(properties.getProperty("concurrents"));
int runtime = Integer.parseInt(properties.getProperty("runtime"));
String classname = properties.getProperty("classname");
Expand All @@ -46,14 +52,24 @@ public static void main(String[] args) {
isMultiClient = Boolean.parseBoolean(args[4]);
}

ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"classpath*:motan-benchmark-client.xml"});
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
new String[]{"classpath*:motan-benchmark-client.xml"});
benchmarkService = (BenchmarkService) applicationContext.getBean("motanBenchmarkReferer");

new MotanBenchmarkClient().start(concurrents, runtime, classname, params);
}

private static void loadProperties() {
try {
properties.load(ClassLoader.getSystemResourceAsStream("benchmark.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public ClientRunnable getClientRunnable(String classname, String params, CyclicBarrier barrier, CountDownLatch latch, long startTime, long endTime) {
public ClientRunnable getClientRunnable(String classname, String params, CyclicBarrier barrier,
CountDownLatch latch, long startTime, long endTime) {
BenchmarkService service;
if (isMultiClient) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"classpath*:motan-benchmark-client.xml"});
Expand Down