Skip to content

Commit

Permalink
Merge pull request #30 from half-dead/pr-29
Browse files Browse the repository at this point in the history
add loadProperties()
  • Loading branch information
qdaxb committed May 6, 2016
2 parents fe16326 + e3ff970 commit 7e01953
Showing 1 changed file with 24 additions and 8 deletions.
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

0 comments on commit 7e01953

Please sign in to comment.