2020
2121import java .util .concurrent .TimeUnit ;
2222
23- import junit .framework .AssertionFailedError ;
24-
2523import org .junit .AfterClass ;
2624import org .junit .BeforeClass ;
2725import org .junit .Test ;
2826import org .strongback .Logger .Level ;
29- import org .strongback .Strongback .Configurator .TimerMode ;
27+
28+ import junit .framework .AssertionFailedError ;
3029
3130/**
3231 * This test attempts to measure the timing of the {@link Strongback#executor() Strongback Executor} instance at various periods
33- * using the system clock and various {@link TimerMode}s. On OS X 10.10.3, the {@link TimerMode#BUSY} is clearly the most
34- * accurate down to 1 millisecond, whereas {@link TimerMode#PARK} and {@link TimerMode#SLEEP} are relatively inaccurate and
35- * imprecise for intervals even as high as 20ms.
3632 * <p>
3733 * The code committed into Git are small execution rates and sample sizes to minimize the time required to run the tests. As
3834 * such, the results are probably not terribly meaningful. To obtain more meaningful results on your own platform, simply adjust
@@ -44,28 +40,22 @@ public class ExecutableTimerTest {
4440
4541 @ BeforeClass
4642 public static void beforeAll () {
47- Strongback .configure ().useSystemLogger (Level .ERROR ).recordNoData ().recordNoEvents ().initialize ();
48- Strongback .start ();
43+ Strongback .configure ().setLogLevel (Level .ERROR ).recordNoData ().recordNoEvents ().initialize ();
4944 }
5045
5146 @ AfterClass
5247 public static void afterAll () {
53- Strongback .shutdown ();
54- }
55-
56- @ Test
57- public void shouldMeasureAndPrintTimingHistogramUsingBusyMode () throws InterruptedException {
58- runTimer (TimerMode .BUSY , 4 , 2000 );
48+ Strongback .stop ();
5949 }
6050
6151 @ Test
62- public void shouldMeasureAndPrintTimingHistogramUsingParkMode () throws InterruptedException {
63- runTimer (TimerMode . PARK , 5 , 2000 );
52+ public void shouldMeasureAndPrintTimingHistogramFor4MillisecondPeriod () throws InterruptedException {
53+ runTimer (4 , 2000 );
6454 }
6555
6656 @ Test
67- public void shouldMeasureAndPrintTimingHistogramUsingSleepMode () throws InterruptedException {
68- runTimer (TimerMode . SLEEP , 6 , 2000 );
57+ public void shouldMeasureAndPrintTimingHistogramFor10MillisecondPeriod () throws InterruptedException {
58+ runTimer (10 , 2000 );
6959 }
7060
7161 /**
@@ -75,14 +65,14 @@ public void shouldMeasureAndPrintTimingHistogramUsingSleepMode() throws Interrup
7565 * @param millisecondExecutionPeriod the execution period in milliseconds
7666 * @param sampleTimeInMilliseconds the sample time in milliseconds
7767 */
78- protected void runTimer (TimerMode mode , int millisecondExecutionPeriod , int sampleTimeInMilliseconds ) {
68+ protected void runTimer (int millisecondExecutionPeriod , int sampleTimeInMilliseconds ) {
7969 try {
70+ Strongback .stop ();
8071 Strongback .configure ()
81- .useExecutionTimerMode (mode )
82- .useExecutionPeriod (millisecondExecutionPeriod , TimeUnit .MILLISECONDS )
83- .initialize ();
72+ .useExecutionPeriod (millisecondExecutionPeriod , TimeUnit .MILLISECONDS );
73+ Strongback .start ();
8474 assertThat (ExecutableTimer .measureTimingAndPrint (Strongback .executor (),
85- mode . toString () + " for " + millisecondExecutionPeriod + " ms" ,
75+ " for " + millisecondExecutionPeriod + " ms" ,
8676 sampleTimeInMilliseconds / millisecondExecutionPeriod )
8777 .await (10 , TimeUnit .SECONDS )
8878 .isComplete ());
0 commit comments