-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring reporters to allow sharing across multiple JUnitPerfRule … (
#48) * Refactoring reporters to allow sharing across multiple JUnitPerfRule instances
- Loading branch information
Showing
6 changed files
with
151 additions
and
55 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
55 changes: 55 additions & 0 deletions
55
src/test/examples/com/github/noconnor/junitperf/examples/ExampleCommonReporter.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,55 @@ | ||
package com.github.noconnor.junitperf.examples; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.Socket; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Suite; | ||
import com.github.noconnor.junitperf.JUnitPerfRule; | ||
import com.github.noconnor.junitperf.JUnitPerfTest; | ||
import com.github.noconnor.junitperf.JUnitPerfTestRequirement; | ||
import com.github.noconnor.junitperf.reporting.providers.HtmlReportGenerator; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(Suite.class) | ||
@Suite.SuiteClasses({ | ||
ExampleCommonReporter.TestClassOne.class, | ||
ExampleCommonReporter.TestClassTwo.class | ||
}) | ||
public class ExampleCommonReporter { | ||
|
||
// Both test classes should report to the same HTML file | ||
private static final HtmlReportGenerator REPORTER = new HtmlReportGenerator(); | ||
|
||
public static class TestClassOne { | ||
@Rule | ||
public JUnitPerfRule perfRule = new JUnitPerfRule(REPORTER); | ||
|
||
@Test | ||
@JUnitPerfTest(threads = 10, durationMs = 10_000, warmUpMs = 1_000, rampUpPeriodMs = 2_000, maxExecutionsPerSecond = 100) | ||
public void whenNoRequirementsArePresent_thenTestShouldAlwaysPass() throws IOException { | ||
try (Socket socket = new Socket()) { | ||
socket.connect(new InetSocketAddress("www.google.com", 80), 1000); | ||
assertTrue(socket.isConnected()); | ||
} | ||
} | ||
} | ||
|
||
public static class TestClassTwo { | ||
@Rule | ||
public JUnitPerfRule perfRule = new JUnitPerfRule(REPORTER); | ||
|
||
@Test(expected = AssertionError.class) | ||
@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); | ||
} | ||
} | ||
|
||
|
||
} |
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