continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r723707 - in /continuum/branches/continuum-parallel-builds/continuum-core/src: main/java/org/apache/continuum/buildmanager/DefaultBuildManager.java test/java/org/apache/continuum/buildmanager/DefaultBuildManagerTest.java
Date Fri, 05 Dec 2008 10:57:04 GMT
Author: oching
Date: Fri Dec  5 02:57:02 2008
New Revision: 723707

URL: http://svn.apache.org/viewvc?rev=723707&view=rev
Log:
o added parallel builds additional test cases

Modified:
    continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/DefaultBuildManager.java
    continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/DefaultBuildManagerTest.java

Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/DefaultBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/DefaultBuildManager.java?rev=723707&r1=723706&r2=723707&view=diff
==============================================================================
--- continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/DefaultBuildManager.java
(original)
+++ continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/DefaultBuildManager.java
Fri Dec  5 02:57:02 2008
@@ -36,6 +36,7 @@
 import org.codehaus.plexus.context.ContextException;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.taskqueue.TaskQueue;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
 
 /**
@@ -72,11 +73,16 @@
 
     // should be invoked before adding anything in any of the queues!
     private synchronized OverallBuildQueue getOverallBuildQueue()
-        throws ComponentLookupException
+        throws ComponentLookupException, TaskQueueException
     {
         OverallBuildQueue overallBuildQueue = null;
                 
         int parallelBuildsNum = configurationService.getNumberOfBuildsInParallel();
+        if( parallelBuildsNum <= 0 )
+        {
+            parallelBuildsNum = 1;
+        }
+        
         if( overallBuildQueuesInUse.size() < parallelBuildsNum )
         {   
             overallBuildQueue = ( OverallBuildQueue ) container.lookup( OverallBuildQueue.class
);            
@@ -85,10 +91,21 @@
             overallBuildQueuesInUse.add( overallBuildQueue );            
         }       
         else
-        {
-            // add logic for distributing work among the queues            
-            // - check whether the project is already in any of the queues
-            // - if not, always get the overall build queue with the least tasks queued to
it
+        {            
+            int size = 0;            
+            for( OverallBuildQueue overallBuildQueueInUse : overallBuildQueuesInUse )
+            {   
+                // TODO: must differentiate between checkout, prepare-build & build queues!
+                List<TaskQueue> tasks = overallBuildQueueInUse.getBuildQueue().getQueueSnapshot();
+                if( tasks != null )
+                {   
+                    if( size == 0 || tasks.size() < size )
+                    {
+                        overallBuildQueue = overallBuildQueueInUse;
+                        size = tasks.size();
+                    }                    
+                }
+            }
         }
         
         return overallBuildQueue;

Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/DefaultBuildManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/DefaultBuildManagerTest.java?rev=723707&r1=723706&r2=723707&view=diff
==============================================================================
--- continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/DefaultBuildManagerTest.java
(original)
+++ continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/DefaultBuildManagerTest.java
Fri Dec  5 02:57:02 2008
@@ -91,20 +91,82 @@
     
     public void testParallelBuildsLimitIsMaximized()
         throws Exception
-    {
-        // assert size of the overallBuildQueuesInUse!
+    {   
+        // set expectations
+        context.checking(new Expectations() {{
+            exactly( 3 ).of(configurationService).getNumberOfBuildsInParallel(); will( returnValue(
2 ) );
+        }});
+        
+        Schedule schedule = new Schedule();
+        schedule.setMaxJobExecutionTime( 100 );
+        
+        BuildDefinition buildDef = new BuildDefinition();
+        buildDef.setId( 1 );
+        buildDef.setSchedule( schedule );
+        
+        buildManager.addProjectToBuildQueue( 1, buildDef, 1, "continuum-test-project-1",
"build-def-label" );
+        
+        buildManager.addProjectToBuildQueue( 2, buildDef, 1, "continuum-test-project-2",
"build-def-label" );
+        
+        buildManager.addProjectToBuildQueue( 3, buildDef, 1, "continuum-test-project-3",
"build-def-label" );
+        
+        // verify
+        context.assertIsSatisfied();
+        
+        // assert if the project is in the correct build queue!
+        OverallBuildQueue overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued(
1 );
+        assertEquals( 1, overallBuildQueue.getId() );
+        
+        overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued( 2 );
+        assertEquals( 2, overallBuildQueue.getId() );
+        
+        overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued( 3 );
+        assertEquals( 1, overallBuildQueue.getId() );
+        
+        assertEquals( 2, buildManager.getOverallBuildQueuesInUse().size() );
     }
     
     public void testParallelBuildsBuildIsCancelled()
         throws Exception
     {
-    
+        
     }
     
+    // project must not be queued!
     public void testParallelBuildsProjectAlreadyInBuildQueue()
         throws Exception
     {
-    
+        // set expectations
+        context.checking(new Expectations() {{
+            exactly( 2 ).of(configurationService).getNumberOfBuildsInParallel(); will( returnValue(
2 ) );
+        }});
+        
+        Schedule schedule = new Schedule();
+        schedule.setMaxJobExecutionTime( 100 );
+        
+        BuildDefinition buildDef = new BuildDefinition();
+        buildDef.setId( 1 );
+        buildDef.setSchedule( schedule );
+        
+        buildManager.addProjectToBuildQueue( 1, buildDef, 1, "continuum-test-project-1",
"build-def-label" );
+        
+        buildManager.addProjectToBuildQueue( 2, buildDef, 1, "continuum-test-project-2",
"build-def-label" );
+        
+        buildManager.addProjectToBuildQueue( 1, buildDef, 1, "continuum-test-project-1",
"build-def-label" );
+        
+        // verify
+        context.assertIsSatisfied();
+        
+        // assert if the project is in the correct build queue!
+        OverallBuildQueue overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued(
1 );
+        assertEquals( 1, overallBuildQueue.getId() );
+        assertEquals( 1, overallBuildQueue.getBuildQueue().getQueueSnapshot().size() );
+        
+        overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued( 2 );
+        assertEquals( 2, overallBuildQueue.getId() );
+        assertEquals( 1, overallBuildQueue.getBuildQueue().getQueueSnapshot().size() );
+        
+        assertEquals( 2, buildManager.getOverallBuildQueuesInUse().size() );        
     }
     
     public void testParallelBuildsRemoveFromBuildQueue()
@@ -152,6 +214,68 @@
     public void testSingleBuild()
         throws Exception
     {
+        // set expectations
+        context.checking(new Expectations() {{
+            exactly( 2 ).of(configurationService).getNumberOfBuildsInParallel(); will( returnValue(
1 ) );
+        }});
+        
+        Schedule schedule = new Schedule();
+        schedule.setMaxJobExecutionTime( 100 );
+        
+        BuildDefinition buildDef = new BuildDefinition();
+        buildDef.setId( 1 );
+        buildDef.setSchedule( schedule );
+        
+        buildManager.addProjectToBuildQueue( 1, buildDef, 1, "continuum-test-project-1",
"build-def-label" );
+        
+        buildManager.addProjectToBuildQueue( 2, buildDef, 1, "continuum-test-project-2",
"build-def-label" );
+        
+        // verify
+        context.assertIsSatisfied();
+        
+        // assert if the project is in the correct build queue!
+        OverallBuildQueue overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued(
1 );
+        assertEquals( 1, overallBuildQueue.getId() );
+        
+        overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued( 2 );
+        assertEquals( 1, overallBuildQueue.getId() );
+        
+        assertEquals( 1, buildManager.getOverallBuildQueuesInUse().size() );
+        
+        assertEquals( 2, buildManager.getOverallBuildQueuesInUse().get( 0 ).getBuildQueue().getQueueSnapshot().size()
);
+    }
     
+    public void testNumberOfBuildInParallelConfigSetToZero()
+        throws Exception
+    {
+        // set expectations
+        context.checking(new Expectations() {{
+            exactly( 2 ).of(configurationService).getNumberOfBuildsInParallel(); will( returnValue(
0 ) );
+        }});
+        
+        Schedule schedule = new Schedule();
+        schedule.setMaxJobExecutionTime( 100 );
+        
+        BuildDefinition buildDef = new BuildDefinition();
+        buildDef.setId( 1 );
+        buildDef.setSchedule( schedule );
+        
+        buildManager.addProjectToBuildQueue( 1, buildDef, 1, "continuum-test-project-1",
"build-def-label" );
+        
+        buildManager.addProjectToBuildQueue( 2, buildDef, 1, "continuum-test-project-2",
"build-def-label" );
+        
+        // verify
+        context.assertIsSatisfied();
+        
+        // assert if the project is in the correct build queue!
+        OverallBuildQueue overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued(
1 );
+        assertEquals( 1, overallBuildQueue.getId() );
+        
+        overallBuildQueue = buildManager.getOverallBuildQueueWhereProjectIsQueued( 2 );
+        assertEquals( 1, overallBuildQueue.getId() );
+        
+        assertEquals( 1, buildManager.getOverallBuildQueuesInUse().size() );
+        
+        assertEquals( 2, buildManager.getOverallBuildQueuesInUse().get( 0 ).getBuildQueue().getQueueSnapshot().size()
);
     }
 }



Mime
View raw message