Skip to content

Commit

Permalink
Refactroing annotation interface (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
noconnor authored Oct 29, 2017
1 parent 110daf1 commit 256aa8d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 49 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ More information on statistic calculations can be found [here](#statistics)

`@JUnitPerfTest` has the following configuration parameters:

| Property | Definition | Default value |
| ------------: |:---------------------------------------------------------------------------------------------------------------------------------:| --------------:|
| threads | The total number of threads to use during test execution | 1 |
| duration | Total time to run the test in millisecs (ms) (includes warmup period) | 60,000 |
| warmUp | Warm up period in ms, test logic will be executed during warm up, but results will not be considered during statistics evaluation | 0 |
| rateLimit | Sets the maximum number of iteration per second (disabled by default) | -1 |
| Property | Definition | Default value |
| ---------------------: |:---------------------------------------------------------------------------------------------------------------------------------:| --------------:|
| threads | The total number of threads to use during test execution | 1 |
| durationMs | Total time to run the test in millisecs (ms) (includes warmup period) | 60,000 |
| warmUpMs | Warm up period in ms, test logic will be executed during warm up, but results will not be considered during statistics evaluation | 0 |
| maxExecutionsPerSecond | Sets the maximum number of iteration per second (disabled by default) | -1 |

<br />

`@JUnitPerfTestRequirement` has the following configuration parameters:

| Property | Definition | Default value |
| -----------------:|:---------------------------------------------------------------------------------------------------------------------------:| --------------:|
| percentiles | Comma separated list of percentile targets, format: percentile1:limit,percentile2:limit (ie. 90:3.3,99:6.8) | "" |
| throughput | Target executions per second | 1 |
| allowedErrorsRate | Allowed % of errors (uncaught exceptions) during test execution (value between 0 and 1, where 1 = 100% errors allowed) | 1 |
| Property | Definition | Default value |
| ----------------------:|:---------------------------------------------------------------------------------------------------------------------------:| --------------:|
| percentiles | Comma separated list of percentile targets, format: percentile1:limit,percentile2:limit (ie. 90:3.3,99:6.8) | "" |
| executionsPerSec | Target executions per second | 1 |
| allowedErrorPercentage | Allowed % of errors (uncaught exceptions) during test execution (value between 0 and 1, where 1 = 100% errors allowed) | 1 |


## Reports
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'jacoco'

group = 'com.github.noconnor'
sourceCompatibility = 1.8
version = '1.2.0'
version = '1.3.0'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
int threads() default 1;

// Total test duration (milliseconds) after which no more evaluations will take place
int duration() default 60_000;
int durationMs() default 60_000;

// During the warm up period (milliseconds) test execution results will be ignored and will not be considered in test result evaluations
int warmUp() default 0;
int warmUpMs() default 0;

// Test will execute no more that specified "rateLimit" executions per second
// Default value is no limit
int rateLimit() default -1;
int maxExecutionsPerSecond() default -1;

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
String percentiles() default "";

// Expected test throughput (executions per second)
int throughput() default 1;
int executionsPerSec() default 1;

// Expected % of test failures. Failures are measured as test case exceptions
float allowedErrorsRate() default 1;
float allowedErrorPercentage() default 1;

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ public void loadConfiguration(JUnitPerfTest testSettings) {
// TODO: validate annotation attributes
checkNotNull(testSettings, "Test settings must not be null");
configuredThreads = testSettings.threads();
configuredDuration = testSettings.duration();
configuredWarmUp = testSettings.warmUp();
configuredRateLimit = testSettings.rateLimit();
configuredDuration = testSettings.durationMs();
configuredWarmUp = testSettings.warmUpMs();
configuredRateLimit = testSettings.maxExecutionsPerSecond();
}

public void loadRequirements(JUnitPerfTestRequirement requirements) {
validationRequired = nonNull(requirements);
if (validationRequired) {
// TODO: validate annotation attributes
validationRequired = true;
requiredThroughput = requirements.throughput();
requiredAllowedErrorsRate = requirements.allowedErrorsRate();
requiredThroughput = requirements.executionsPerSec();
requiredAllowedErrorsRate = requirements.allowedErrorPercentage();
requiredPercentiles = parsePercentileLimits(requirements.percentiles());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ public class ExampleFailureTests {
public JUnitPerfRule perfRule = new JUnitPerfRule();

@Test
@JUnitPerfTest(threads = 1, duration = 1_000, rateLimit = 1_000)
@JUnitPerfTestRequirement(throughput = 10_000)
@JUnitPerfTest(threads = 1, durationMs = 1_000, maxExecutionsPerSecond = 1_000)
@JUnitPerfTestRequirement(executionsPerSec = 10_000)
public void whenThroughputRequirementIsNotMet_thenTestShouldFail() throws InterruptedException {
// Mock some processing logic
Thread.sleep(1);
}

@Test
@JUnitPerfTest(threads = 1, duration = 1_000, rateLimit = 1_000)
@JUnitPerfTestRequirement(throughput = 10_000, percentiles = "99:1")
@JUnitPerfTest(threads = 1, durationMs = 1_000, maxExecutionsPerSecond = 1_000)
@JUnitPerfTestRequirement(executionsPerSec = 10_000, percentiles = "99:1")
public void whenLatencyRequirementIsNotMet_thenTestShouldFail() throws InterruptedException {
// Mock some processing logic
Thread.sleep(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@ private void mockJunitPerfTestRequirementAnnotationNotPresent() {
}

private void initialisePerfTestAnnotationMock() {
when(perfTestAnnotationMock.duration()).thenReturn(DURATION);
when(perfTestAnnotationMock.rateLimit()).thenReturn(RATE_LIMIT);
when(perfTestAnnotationMock.durationMs()).thenReturn(DURATION);
when(perfTestAnnotationMock.maxExecutionsPerSecond()).thenReturn(RATE_LIMIT);
when(perfTestAnnotationMock.threads()).thenReturn(THREADS);
when(perfTestAnnotationMock.warmUp()).thenReturn(WARM_UP);
when(perfTestAnnotationMock.warmUpMs()).thenReturn(WARM_UP);
}

private void initialisePerfTestRequirementAnnotationMock() {
when(requirementAnnotationMock.allowedErrorsRate()).thenReturn(ALLOWED_ERRORS);
when(requirementAnnotationMock.allowedErrorPercentage()).thenReturn(ALLOWED_ERRORS);
when(requirementAnnotationMock.percentiles()).thenReturn(PERCENTILES);
when(requirementAnnotationMock.throughput()).thenReturn(THROUGHPUT);
when(requirementAnnotationMock.executionsPerSec()).thenReturn(THROUGHPUT);
}

private void initialiseDescriptionMock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public void setup() {
@Test
public void whenLoadingJUnitPerfTestSettings_thenAppropriateContextSettingsShouldBeUpdated() {
context.loadConfiguration(perfTestAnnotation);
assertThat(context.getConfiguredDuration(), is(perfTestAnnotation.duration()));
assertThat(context.getConfiguredRateLimit(), is(perfTestAnnotation.rateLimit()));
assertThat(context.getConfiguredDuration(), is(perfTestAnnotation.durationMs()));
assertThat(context.getConfiguredRateLimit(), is(perfTestAnnotation.maxExecutionsPerSecond()));
assertThat(context.getConfiguredThreads(), is(perfTestAnnotation.threads()));
assertThat(context.getConfiguredWarmUp(), is(perfTestAnnotation.warmUp()));
assertThat(context.getConfiguredWarmUp(), is(perfTestAnnotation.warmUpMs()));
}

@Test(expected = NullPointerException.class)
Expand All @@ -57,8 +57,8 @@ public void whenLoadingJUnitPerfTestSettings_andSettingsAreNull_thenExceptionSho
public void whenLoadingJUnitPerfTestRequirements_thenAppropriateContextSettingsShouldBeUpdated() {
context.loadRequirements(perfTestRequirement);
assertThat(context.isValidationRequired(), is(true));
assertThat(context.getRequiredAllowedErrorsRate(), is(perfTestRequirement.allowedErrorsRate()));
assertThat(context.getRequiredThroughput(), is(perfTestRequirement.throughput()));
assertThat(context.getRequiredAllowedErrorsRate(), is(perfTestRequirement.allowedErrorPercentage()));
assertThat(context.getRequiredThroughput(), is(perfTestRequirement.executionsPerSec()));
assertThat(context.getRequiredPercentiles(), is(ImmutableMap.of(90, 0.5F, 95, 9F)));
}

Expand Down Expand Up @@ -93,8 +93,8 @@ public void whenRunningEvaluation_andThroughputIsBelowThreshold_thenThroughputAc
@Test
public void whenRunningEvaluation_andEvaluationCountIsGreaterThanDuration_thenThroughputShouldBeCalculatedCorrectly() {
when(statisticsMock.getEvaluationCount()).thenReturn(1000L);
when(perfTestAnnotation.duration()).thenReturn(100);
when(perfTestAnnotation.warmUp()).thenReturn(5);
when(perfTestAnnotation.durationMs()).thenReturn(100);
when(perfTestAnnotation.warmUpMs()).thenReturn(5);
initialiseContext();
context.runValidation();
assertThat(context.getThroughputQps(), is(10526L));
Expand Down Expand Up @@ -180,7 +180,7 @@ public void whenParsingPercentileLimits_andEntriesAreInvalid_thenInvalidEntriesS
@Test
public void whenCalculatingThroughputQps_thenCorrectValueShouldBeCalculated() {
initialiseContext();
long expected = (long)(statisticsMock.getEvaluationCount() / (float)(perfTestAnnotation.duration() - perfTestAnnotation.warmUp())) * 1000;
long expected = (long)(statisticsMock.getEvaluationCount() / (float)(perfTestAnnotation.durationMs() - perfTestAnnotation.warmUpMs())) * 1000;
assertThat(context.getThroughputQps(), is(expected));
}

Expand All @@ -191,15 +191,15 @@ private void initialiseContext() {
}

private void initialisePerfTestAnnotation() {
when(perfTestAnnotation.duration()).thenReturn(10);
when(perfTestAnnotation.rateLimit()).thenReturn(1_000);
when(perfTestAnnotation.durationMs()).thenReturn(10);
when(perfTestAnnotation.maxExecutionsPerSecond()).thenReturn(1_000);
when(perfTestAnnotation.threads()).thenReturn(50);
when(perfTestAnnotation.warmUp()).thenReturn(5);
when(perfTestAnnotation.warmUpMs()).thenReturn(5);
}

private void initialisePerfTestRequirementAnnotation() {
when(perfTestRequirement.throughput()).thenReturn(10_000);
when(perfTestRequirement.allowedErrorsRate()).thenReturn(0.5f);
when(perfTestRequirement.executionsPerSec()).thenReturn(10_000);
when(perfTestRequirement.allowedErrorPercentage()).thenReturn(0.5f);
when(perfTestRequirement.percentiles()).thenReturn("90:0.5,95:9");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ private StatisticsCalculator createAllFailureMock() {
}

protected void initialisePerfTestAnnotationMock() {
when(perfTestAnnotationMock.duration()).thenReturn(10_000);
when(perfTestAnnotationMock.warmUp()).thenReturn(100);
when(perfTestAnnotationMock.durationMs()).thenReturn(10_000);
when(perfTestAnnotationMock.warmUpMs()).thenReturn(100);
when(perfTestAnnotationMock.threads()).thenReturn(50);
when(perfTestAnnotationMock.rateLimit()).thenReturn(11_000);
when(perfTestAnnotationMock.maxExecutionsPerSecond()).thenReturn(11_000);
}

protected void initialisePerfTestRequirementAnnotationMock() {
when(perfTestRequirementAnnotationMock.percentiles()).thenReturn("98:3.3,99:32.6,100:46.9999");
when(perfTestRequirementAnnotationMock.allowedErrorsRate()).thenReturn(0.3F);
when(perfTestRequirementAnnotationMock.throughput()).thenReturn(13_000);
when(perfTestRequirementAnnotationMock.allowedErrorPercentage()).thenReturn(0.3F);
when(perfTestRequirementAnnotationMock.executionsPerSec()).thenReturn(13_000);
}

@SuppressWarnings("unused")
Expand Down

0 comments on commit 256aa8d

Please sign in to comment.