-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/add functionality to support async measurement tracking (#44)
* Refactoring ExecutionContext to add is async identifier * Adding Test context to support async metrics measurement * Adding no op stats collector for async stats evalutaion * Adding JUnitPerfAsyncRule * Adding example Async test * Updating readme instructions * Stepping version to 1.12.0
- Loading branch information
Showing
20 changed files
with
677 additions
and
60 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
63 changes: 63 additions & 0 deletions
63
src/main/java/com/github/noconnor/junitperf/JUnitPerfAsyncRule.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,63 @@ | ||
package com.github.noconnor.junitperf; | ||
|
||
import com.github.noconnor.junitperf.data.EvaluationContext; | ||
import com.github.noconnor.junitperf.data.NoOpTestContext; | ||
import com.github.noconnor.junitperf.data.TestContext; | ||
import com.github.noconnor.junitperf.reporting.ReportGenerator; | ||
import com.github.noconnor.junitperf.reporting.providers.HtmlReportGenerator; | ||
import com.github.noconnor.junitperf.statistics.StatisticsCalculator; | ||
import com.github.noconnor.junitperf.statistics.providers.DescriptiveStatisticsCalculator; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
import static java.lang.System.currentTimeMillis; | ||
import static java.lang.System.nanoTime; | ||
import static java.util.Objects.nonNull; | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
public class JUnitPerfAsyncRule extends JUnitPerfRule { | ||
|
||
private long measurementsStartTimeMs; | ||
|
||
public JUnitPerfAsyncRule() { | ||
this(new DescriptiveStatisticsCalculator(), new HtmlReportGenerator()); | ||
} | ||
|
||
public JUnitPerfAsyncRule(ReportGenerator... reportGenerator) { | ||
this(new DescriptiveStatisticsCalculator(), reportGenerator); | ||
} | ||
|
||
public JUnitPerfAsyncRule(StatisticsCalculator statisticsCalculator) { | ||
this(statisticsCalculator, new HtmlReportGenerator()); | ||
} | ||
|
||
public JUnitPerfAsyncRule(StatisticsCalculator statisticsCalculator, ReportGenerator... reportGenerator) { | ||
super(statisticsCalculator, reportGenerator); | ||
} | ||
|
||
public TestContext newContext() { | ||
return hasMeasurementPeriodStarted() ? new TestContext(statisticsCalculator) : NoOpTestContext.INSTANCE; | ||
} | ||
|
||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
setMeasurementsStartTime(description.getAnnotation(JUnitPerfTest.class)); | ||
return super.apply(base, description); | ||
} | ||
|
||
@Override | ||
EvaluationContext createEvaluationContext(Description description) { | ||
return new EvaluationContext(description.getMethodName(), nanoTime(), true); | ||
} | ||
|
||
private void setMeasurementsStartTime(JUnitPerfTest perfTestAnnotation) { | ||
if (nonNull(perfTestAnnotation)) { | ||
measurementsStartTimeMs = currentTimeMillis() + perfTestAnnotation.warmUpMs(); | ||
} | ||
} | ||
|
||
private boolean hasMeasurementPeriodStarted() { | ||
return currentTimeMillis() >= measurementsStartTimeMs; | ||
} | ||
|
||
} |
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
Oops, something went wrong.