Skip to content

Commit

Permalink
version 2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Grove committed Dec 6, 2014
1 parent 87a3057 commit a5a6c20
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -7,7 +7,7 @@
<groupId>org.jperf</groupId>
<artifactId>jperf</artifactId>
<name>jperf</name>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.3</version>
<packaging>jar</packaging>

<licenses>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jperf/ConfigBuilder.java
Expand Up @@ -4,7 +4,9 @@ public interface ConfigBuilder {
ConfigBuilder minThreads(int minThreads);
ConfigBuilder maxThreads(int maxThreads);
ConfigBuilder threadIncrement(int threadIncrement);
ConfigBuilder duration(int duration);
@Deprecated ConfigBuilder duration(int duration);
ConfigBuilder durationPerThread(int duration);
ConfigBuilder durationTotal(int duration);
ConfigBuilder testFactory(PerfTestFactory testFactory);
ConfigBuilder resultWriter(ResultWriter resultWriter);
void run() throws Exception;
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/jperf/DefaultConfigBuilder.java
Expand Up @@ -32,8 +32,20 @@ public ConfigBuilder threadIncrement(int threadIncrement) {
}

@Override
public ConfigBuilder duration(int duration) {
config.duration = duration;
public ConfigBuilder duration(int durationPerThread) {
config.durationPerThread = durationPerThread;
return this;
}

@Override
public ConfigBuilder durationPerThread(int durationPerThread) {
config.durationPerThread = durationPerThread;
return this;
}

@Override
public ConfigBuilder durationTotal(int durationTotal) {
config.durationTotal = durationTotal;
return this;
}

Expand Down
17 changes: 15 additions & 2 deletions src/main/java/org/jperf/JPerf.java
Expand Up @@ -71,6 +71,14 @@ private static void showUsage() {

public static void run(final PerfTestConfig config) throws Exception {

// validate configs and set defaults
if (config.durationPerThread==0) {
if (config.durationTotal==0) {
throw new RuntimeException("No duration specified");
}
config.durationPerThread = config.durationTotal / config.maxThreads;
}

// create executors and test runners (one of each per thread)
final ExecutorService exec[] = new ExecutorService[config.maxThreads];
final SingleTestRunner testRunner[] = new SingleTestRunner[config.maxThreads];
Expand Down Expand Up @@ -99,7 +107,7 @@ public static void run(final PerfTestConfig config) throws Exception {
}

final long start = System.currentTimeMillis();
Thread.sleep(config.duration);
Thread.sleep(config.durationPerThread);
final long actualDuration = System.currentTimeMillis() - start;

// collect the totals
Expand Down Expand Up @@ -134,8 +142,13 @@ public static void run(final PerfTestConfig config) throws Exception {
}
}

public static ConfigBuilder newConfigBuilder() {
public static ConfigBuilder newTestRun() {
return new DefaultConfigBuilder();
}

@Deprecated
public static ConfigBuilder newConfigBuilder() {
return newTestRun();
}

}
6 changes: 4 additions & 2 deletions src/main/java/org/jperf/PerfTestConfig.java
Expand Up @@ -6,7 +6,8 @@ public class PerfTestConfig {
protected int minThreads = 1;
protected int maxThreads = 10;
protected int threadIncrement = 1;
protected int duration = 1000;
protected int durationPerThread = 0;
protected int durationTotal = 0;
protected ResultWriter resultWriter = new ResultWriterStdout();
protected PerfTestFactory testFactory;

Expand All @@ -16,7 +17,8 @@ public String toString() {
"minThreads=" + minThreads +
", maxThreads=" + maxThreads +
", threadIncrement=" + threadIncrement +
", duration=" + duration +
", durationPerThread=" + durationPerThread +
", durationTotal=" + durationTotal +
'}';
}
}

0 comments on commit a5a6c20

Please sign in to comment.