mirror of https://github.com/apache/maven.git
Add a test for parsing the thread configuration with the core multiplier
This commit is contained in:
parent
0f1fcd7066
commit
87bdfe5168
|
@ -1094,7 +1094,7 @@ public class MavenCli
|
||||||
|
|
||||||
if ( threadConfiguration.contains( "C" ) )
|
if ( threadConfiguration.contains( "C" ) )
|
||||||
{
|
{
|
||||||
request.setDegreeOfConcurrency( (int) ( Float.valueOf( threadConfiguration.replace( "C", "" ) ) * Runtime.getRuntime().availableProcessors() ) );
|
request.setDegreeOfConcurrency( calculateDegreeOfConcurrencyWithCoreMultiplier( threadConfiguration ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1113,6 +1113,11 @@ public class MavenCli
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int calculateDegreeOfConcurrencyWithCoreMultiplier( String threadConfiguration )
|
||||||
|
{
|
||||||
|
return (int) ( Float.valueOf( threadConfiguration.replace( "C", "" ) ) * Runtime.getRuntime().availableProcessors() );
|
||||||
|
}
|
||||||
|
|
||||||
static File resolveFile( File file, String workingDirectory )
|
static File resolveFile( File file, String workingDirectory )
|
||||||
{
|
{
|
||||||
if ( file == null )
|
if ( file == null )
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue