Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #285 from sonatype/fixedrate-tc-ut
Browse files Browse the repository at this point in the history
Making FixedRateThrottleController UT more reliable.
  • Loading branch information
cstamas committed Feb 8, 2012
2 parents 5f9ff09 + 1c19871 commit 97c1afa
Showing 1 changed file with 10 additions and 25 deletions.
Expand Up @@ -34,11 +34,11 @@ public class FixedRateWalkerThrottleControllerTest
@Test
public void testDoesItHelpAtAll()
{
// set unrealistic TPS and we do "almost nothing" (1 nano) in processItem method
// set unrealistic TPS and we do "little" (1ms) in processItem method (to get the ceiling to compare with)
final int measuredTpsUnreal = performAndMeasureActualTps( 100000000, new ConstantNumberSequence( 1 ) );
// set 500 TPS and we do "little" (1 nano) in processItem method
// set 500 TPS and we do "little" (1ms) in processItem method
final int measuredTps500 = performAndMeasureActualTps( 500, new ConstantNumberSequence( 1 ) );
// set 200 TPS and we do "little" (1 nano) in processItem method
// set 200 TPS and we do "little" (1ms) in processItem method
final int measuredTps200 = performAndMeasureActualTps( 200, new ConstantNumberSequence( 1 ) );

assertThat( "TPS500 should less than Unreal one", measuredTps500, lessThan( measuredTpsUnreal ) );
Expand All @@ -54,11 +54,8 @@ protected int performAndMeasureActualTps( final int wantedTps, final NumberSeque
fixedRateWalkerThrottleController.setSliceSize( 1 );

final TestThrottleInfo info = new TestThrottleInfo();

final WalkerContext context = Mockito.mock( WalkerContext.class );

final int iterationCount = 10000;

final int iterationCount = 1000;
final long startTime = System.currentTimeMillis();
fixedRateWalkerThrottleController.walkStarted( context );
for ( int i = 0; i < iterationCount; i++ )
Expand All @@ -72,9 +69,10 @@ protected int performAndMeasureActualTps( final int wantedTps, final NumberSeque
final int measuredTps =
fixedRateWalkerThrottleController.calculateCPS( iterationCount, System.currentTimeMillis() - startTime );

System.out.println( "Measured=" + measuredTps );
System.out.println( "GlobalAvg=" + fixedRateWalkerThrottleController.getGlobalAverageTps() );
System.out.println( "GlobalMax=" + fixedRateWalkerThrottleController.getGlobalMaximumTps() );
// System.out.println( "MeasuredTps=" + measuredTps );
// System.out.println( "lastSliceTps=" + fixedRateWalkerThrottleController.getLastSliceTps() );
// System.out.println( "GlobalAvgTps=" + fixedRateWalkerThrottleController.getGlobalAverageTps() );
// System.out.println( "GlobalMaxTps=" + fixedRateWalkerThrottleController.getGlobalMaximumTps() );

return measuredTps;
}
Expand All @@ -94,19 +92,6 @@ protected static void sleep( long millis )
}
}

protected static void sleepNanos( long nanos )
{
try
{
Thread.sleep( 0, (int) nanos );
}
catch ( InterruptedException e )
{
// need to kill test too
throw new RuntimeException( e );
}
}

protected static class TestThrottleInfo
implements ThrottleInfo
{
Expand All @@ -126,8 +111,8 @@ public TestThrottleInfo()
public void simulateInvocation( final long spentTimeInProcessItem )
{
// we need to sleep to keep getTotalTimeWalking() and totalProcessItemSpentMillis aligned
sleepNanos( spentTimeInProcessItem );
totalProcessItemSpentMillis = totalProcessItemSpentMillis + ( spentTimeInProcessItem * 1000 );
sleep( spentTimeInProcessItem );
totalProcessItemSpentMillis = totalProcessItemSpentMillis + spentTimeInProcessItem;
totalProcessItemInvocationCount++;
}

Expand Down

0 comments on commit 97c1afa

Please sign in to comment.