Add a test for parsing the thread configuration with the core multiplier

This commit is contained in:
Jason van Zyl 2014-02-14 11:47:20 -05:00
parent 0f1fcd7066
commit 87bdfe5168
2 changed files with 38 additions and 1 deletions

View File

@ -1094,7 +1094,7 @@ public class MavenCli
if ( threadConfiguration.contains( "C" ) )
{
request.setDegreeOfConcurrency( (int) ( Float.valueOf( threadConfiguration.replace( "C", "" ) ) * Runtime.getRuntime().availableProcessors() ) );
request.setDegreeOfConcurrency( calculateDegreeOfConcurrencyWithCoreMultiplier( threadConfiguration ) );
}
else
{
@ -1113,6 +1113,11 @@ public class MavenCli
return request;
}
int calculateDegreeOfConcurrencyWithCoreMultiplier( String threadConfiguration )
{
return (int) ( Float.valueOf( threadConfiguration.replace( "C", "" ) ) * Runtime.getRuntime().availableProcessors() );
}
static File resolveFile( File file, String workingDirectory )
{
if ( file == null )

View File

@ -0,0 +1,32 @@
package org.apache.maven.cli;
import junit.framework.TestCase;
public class MavenCliTest extends TestCase
{
private MavenCli cli;
protected void setUp()
{
cli = new MavenCli();
}
public void testCalculateDegreeOfConcurrencyWithCoreMultiplier()
{
int cores = Runtime.getRuntime().availableProcessors();
// -T2.2C
assertEquals((int)(cores * 2.2), cli.calculateDegreeOfConcurrencyWithCoreMultiplier("C2.2"));
// -TC2.2
assertEquals((int)(cores * 2.2), cli.calculateDegreeOfConcurrencyWithCoreMultiplier("2.2C"));
try
{
cli.calculateDegreeOfConcurrencyWithCoreMultiplier("CXXX");
fail("Should have failed with a NumberFormatException");
}
catch( NumberFormatException e)
{
// carry on
}
}
}