maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject git commit: Add a test for parsing the thread configuration with the core multiplier
Date Fri, 14 Feb 2014 16:47:43 GMT
Updated Branches:
  refs/heads/master 0f1fcd706 -> 87bdfe516


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


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/87bdfe51
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/87bdfe51
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/87bdfe51

Branch: refs/heads/master
Commit: 87bdfe5168e06ca0fe0181835515ddc7df7b6dd5
Parents: 0f1fcd7
Author: Jason van Zyl <jason@tesla.io>
Authored: Fri Feb 14 11:47:20 2014 -0500
Committer: Jason van Zyl <jason@tesla.io>
Committed: Fri Feb 14 11:47:20 2014 -0500

----------------------------------------------------------------------
 .../java/org/apache/maven/cli/MavenCli.java     |  7 ++++-
 .../java/org/apache/maven/cli/MavenCliTest.java | 32 ++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/87bdfe51/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index f7d72d7..f670284 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -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 )

http://git-wip-us.apache.org/repos/asf/maven/blob/87bdfe51/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
new file mode 100644
index 0000000..db6da2f
--- /dev/null
+++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
@@ -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
+        }        
+    }    
+}


Mime
View raw message