-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-utils: timer resolution added for stress tests
Signed-off-by: Ketoth Xupack <ketoth.xupack@gmail.com>
- Loading branch information
1 parent
b17e20b
commit 73fbd03
Showing
8 changed files
with
134 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
projects/test-utils/src/main/java/org/nohope/test/stress/TimerResolution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.nohope.test.stress; | ||
|
||
/** | ||
* @author <a href="mailto:ketoth.xupack@gmail.com">Ketoth Xupack</a> | ||
* @since 2013-12-27 23:51 | ||
*/ | ||
public enum TimerResolution { | ||
NANOSECONDS(1000 * 1000 * 1000, "ns") { | ||
@Override | ||
public long currentTime() { | ||
return System.nanoTime(); | ||
} | ||
}, | ||
MILLISECONDS(1000, "ms") { | ||
@Override | ||
public long currentTime() { | ||
return System.currentTimeMillis(); | ||
} | ||
}; | ||
|
||
private final double factor; | ||
private final String name; | ||
|
||
TimerResolution(final double factor, final String name) { | ||
this.factor = factor; | ||
this.name = name; | ||
} | ||
|
||
public abstract long currentTime(); | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public double getFactor() { | ||
return factor; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
projects/test-utils/src/test/java/org/nohope/test/stress/StressScenarioTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.nohope.test.stress; | ||
|
||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author <a href="mailto:ketoth.xupack@gmail.com">Ketoth Xupack</a> | ||
* @since 2013-12-28 00:10 | ||
*/ | ||
public class StressScenarioTest { | ||
|
||
@Test | ||
@Ignore("for manual tests only") | ||
public void roughTest() throws InterruptedException { | ||
final StressResult m1 = | ||
StressScenario.of(TimerResolution.MILLISECONDS) | ||
.measure(50, 1000, new NamedAction("test1") { | ||
@Override | ||
protected void doAction(final int threadId, final int operationNumber) | ||
throws Exception { | ||
Thread.sleep(10); | ||
} | ||
}); | ||
final StressResult m2 = | ||
StressScenario.of(TimerResolution.NANOSECONDS) | ||
.measure(50, 1000, new NamedAction("test2") { | ||
@Override | ||
protected void doAction(final int threadId, final int operationNumber) | ||
throws Exception { | ||
Thread.sleep(10); | ||
} | ||
}); | ||
|
||
System.err.println(m1); | ||
System.err.println(m2); | ||
} | ||
} |