continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r732266 - in /continuum/branches/continuum-parallel-builds: continuum-api/src/main/java/org/apache/continuum/taskqueue/ continuum-core/src/main/java/org/apache/continuum/buildmanager/ continuum-core/src/main/java/org/apache/continuum/taskqu...
Date Wed, 07 Jan 2009 08:15:58 GMT
Author: oching
Date: Wed Jan  7 00:15:58 2009
New Revision: 732266

URL: http://svn.apache.org/viewvc?rev=732266&view=rev
Log:
-fixed and ported overall build queue tests to jmock

Modified:
    continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java
    continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java
    continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java
    continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java
    continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java

Modified: continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java?rev=732266&r1=732265&r2=732266&view=diff
==============================================================================
--- continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java
(original)
+++ continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java
Wed Jan  7 00:15:58 2009
@@ -82,7 +82,7 @@
      * @return
      * @throws TaskQueueException TODO
      */
-    List /* CheckOutTask */getCheckOutTasksInQueue()
+    List /* CheckOutTask */getProjectsInCheckoutQueue()
         throws TaskQueueException;
 
     /**

Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java?rev=732266&r1=732265&r2=732266&view=diff
==============================================================================
--- continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java
(original)
+++ continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java
Wed Jan  7 00:15:58 2009
@@ -737,7 +737,7 @@
                 }
 
                 tasks = overallBuildQueue.getProjectsInBuildQueue();
-                checkoutTasks = overallBuildQueue.getCheckOutTasksInQueue();
+                checkoutTasks = overallBuildQueue.getProjectsInCheckoutQueue();
 
                 overallBuildQueue.getBuildQueue().removeAll( tasks );
                 overallBuildQueue.getCheckoutQueue().removeAll( checkoutTasks );
@@ -896,7 +896,7 @@
                 OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
                 try
                 {
-                    queuedCheckouts.put( overallBuildQueue.getName(), overallBuildQueue.getCheckOutTasksInQueue()
);
+                    queuedCheckouts.put( overallBuildQueue.getName(), overallBuildQueue.getProjectsInCheckoutQueue()
);
                 }
                 catch ( TaskQueueException e )
                 {

Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java?rev=732266&r1=732265&r2=732266&view=diff
==============================================================================
--- continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java
(original)
+++ continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java
Wed Jan  7 00:15:58 2009
@@ -109,9 +109,9 @@
     }
 
     /**
-     * @see OverallBuildQueue#getCheckOutTasksInQueue()
+     * @see OverallBuildQueue#getProjectsInCheckoutQueue()
      */
-    public List<CheckOutTask> getCheckOutTasksInQueue()
+    public List<CheckOutTask> getProjectsInCheckoutQueue()
         throws TaskQueueException
     {
         return getCheckoutQueue().getQueueSnapshot();
@@ -123,7 +123,7 @@
     public boolean isInCheckoutQueue( int projectId )
         throws TaskQueueException
     {
-        List<CheckOutTask> queue = getCheckOutTasksInQueue();
+        List<CheckOutTask> queue = getProjectsInCheckoutQueue();
 
         for ( CheckOutTask task : queue )
         {
@@ -141,7 +141,7 @@
     public boolean removeProjectFromCheckoutQueue( int projectId )
         throws TaskQueueException
     {
-        List<CheckOutTask> queue = getCheckOutTasksInQueue();
+        List<CheckOutTask> queue = getProjectsInCheckoutQueue();
 
         for ( CheckOutTask task : queue )
         {
@@ -167,7 +167,7 @@
         {
             return false;
         }
-        List<CheckOutTask> queue = getCheckOutTasksInQueue();
+        List<CheckOutTask> queue = getProjectsInCheckoutQueue();
 
         List<CheckOutTask> tasks = new ArrayList<CheckOutTask>();
 
@@ -194,7 +194,7 @@
     public void removeTasksFromCheckoutQueueWithHashCodes( int[] hashCodes )
         throws TaskQueueException
     {
-        List<CheckOutTask> queue = getCheckOutTasksInQueue();
+        List<CheckOutTask> queue = getProjectsInCheckoutQueue();
 
         for ( CheckOutTask task : queue )
         {
@@ -442,4 +442,19 @@
     {
         return checkoutTaskQueueExecutor;
     }
+
+    public void setBuildDefinitionDao( BuildDefinitionDao buildDefinitionDao )
+    {
+        this.buildDefinitionDao = buildDefinitionDao;
+    }
+
+    public void setBuildTaskQueueExecutor( TaskQueueExecutor buildTaskQueueExecutor )
+    {
+        this.buildTaskQueueExecutor = buildTaskQueueExecutor;
+    }
+
+    public void setCheckoutTaskQueueExecutor( TaskQueueExecutor checkoutTaskQueueExecutor
)
+    {
+        this.checkoutTaskQueueExecutor = checkoutTaskQueueExecutor;
+    }
 }

Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java?rev=732266&r1=732265&r2=732266&view=diff
==============================================================================
--- continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java
(original)
+++ continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java
Wed Jan  7 00:15:58 2009
@@ -56,7 +56,7 @@
 {
     private ParallelBuildsManager buildsManager;
 
-    Mockery context;
+    private Mockery context;
 
     private BuildDefinitionDao buildDefinitionDao;
     
@@ -609,7 +609,7 @@
                 one(buildQueue).removeAll( buildTasks );
                 
              // get all queued checkout tasks & remove them
-                one(overallBuildQueue).getCheckOutTasksInQueue();
+                one(overallBuildQueue).getProjectsInCheckoutQueue();
                 will( returnValue( checkoutTasks ) );                
                 one(overallBuildQueue).getCheckoutQueue();
                 will( returnValue( checkoutQueue ) );
@@ -805,7 +805,7 @@
                 exactly(5).of( overallBuildQueue ).getName();
                 will( returnValue( "BUILD_QUEUE" ) );
                 
-                exactly(5).of( overallBuildQueue).getCheckOutTasksInQueue();
+                exactly(5).of( overallBuildQueue).getProjectsInCheckoutQueue();
                 will( returnValue( tasks ) );
             }
         });

Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java?rev=732266&r1=732265&r2=732266&view=diff
==============================================================================
--- continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java
(original)
+++ continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java
Wed Jan  7 00:15:58 2009
@@ -20,65 +20,328 @@
  */
 
 import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
 
-import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.continuum.dao.BuildDefinitionDao;
+import org.apache.continuum.taskqueueexecutor.ParallelBuildsThreadedTaskQueueExecutor;
 import org.apache.maven.continuum.buildqueue.BuildProjectTask;
+import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.scm.queue.CheckOutTask;
-import org.apache.maven.continuum.scm.queue.PrepareBuildProjectsTask;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.codehaus.plexus.taskqueue.Task;
+import org.codehaus.plexus.taskqueue.TaskQueue;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit3.JUnit3Mockery;
+import org.jmock.lib.legacy.ClassImposteriser;
 
+/**
+ * DefaultOverallBuildQueueTest
+ * 
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ *
+ */
 public class DefaultOverallBuildQueueTest
-    extends AbstractContinuumTest
-{    
-    private OverallBuildQueue overallQueue;
-    
+    extends PlexusInSpringTestCase
+{
+    private DefaultOverallBuildQueue overallQueue;
+
+    private Mockery context;
+
+    private BuildDefinitionDao buildDefinitionDao;
+
+    private ParallelBuildsThreadedTaskQueueExecutor buildTaskQueueExecutor;
+
+    private ParallelBuildsThreadedTaskQueueExecutor checkoutTaskQueueExecutor;
+
     @Override
     protected void setUp()
         throws Exception
     {
         super.setUp();
-        
-        overallQueue = ( OverallBuildQueue ) lookup( OverallBuildQueue.class );
+
+        overallQueue = new DefaultOverallBuildQueue();
+
+        context = new JUnit3Mockery();
+
+        buildDefinitionDao = context.mock( BuildDefinitionDao.class );
+        context.setImposteriser( ClassImposteriser.INSTANCE );
+
+        buildTaskQueueExecutor = context.mock( ParallelBuildsThreadedTaskQueueExecutor.class,
"build-queue-executor" );
+
+        checkoutTaskQueueExecutor =
+            context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "checkout-queue-executor"
);
+
+        overallQueue.setBuildDefinitionDao( buildDefinitionDao );
+
+        overallQueue.setBuildTaskQueueExecutor( buildTaskQueueExecutor );
+
+        overallQueue.setCheckoutTaskQueueExecutor( checkoutTaskQueueExecutor );
     }
-    
+
+    // checkout queue
+
     public void testAddToCheckoutQueue()
         throws Exception
     {
-        File workingDir = new File( getBasedir(), "target/working-dir" );
-        
-        CheckOutTask task = new CheckOutTask( 1, workingDir, "continuum-test-project", "username",
"password" );
-        overallQueue.addToCheckoutQueue( task );
-        
-        CheckOutTask queuedTask = ( CheckOutTask ) overallQueue.getCheckoutQueue().take();
-        assertNotNull( queuedTask );
-        assertEquals( 1, queuedTask.getProjectId() );
-        assertEquals( "continuum-test-project", queuedTask.getProjectName() );
+        final Task checkoutTask =
+            new CheckOutTask( 1, new File( getBasedir(), "/target/test-working-dir/1" ),
"continuum-project-test-1",
+                              "dummy", "dummypass" );
+        final TaskQueue checkoutQueue = context.mock( TaskQueue.class, "checkout-queue" );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( checkoutTaskQueueExecutor ).getQueue();
+                will( returnValue( checkoutQueue ) );
+
+                one( checkoutQueue ).put( checkoutTask );
+            }
+        } );
+
+        overallQueue.addToCheckoutQueue( checkoutTask );
+        context.assertIsSatisfied();
     }
-    
+
+    public void testGetProjectsInCheckoutQueue()
+        throws Exception
+    {
+        final TaskQueue checkoutQueue = context.mock( TaskQueue.class, "checkout-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new CheckOutTask( 1, new File( getBasedir(), "/target/test-working-dir/1"
),
+                                     "continuum-project-test-1", "dummy", "dummypass" ) );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( checkoutTaskQueueExecutor ).getQueue();
+                will( returnValue( checkoutQueue ) );
+
+                one( checkoutQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+            }
+        } );
+
+        List<CheckOutTask> returnedTasks = overallQueue.getProjectsInCheckoutQueue();
+        context.assertIsSatisfied();
+
+        assertNotNull( returnedTasks );
+        assertEquals( 1, returnedTasks.size() );
+    }
+
+    public void testIsInCheckoutQueue()
+        throws Exception
+    {
+        final TaskQueue checkoutQueue = context.mock( TaskQueue.class, "checkout-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new CheckOutTask( 1, new File( getBasedir(), "/target/test-working-dir/1"
),
+                                     "continuum-project-test-1", "dummy", "dummypass" ) );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( checkoutTaskQueueExecutor ).getQueue();
+                will( returnValue( checkoutQueue ) );
+
+                one( checkoutQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+            }
+        } );
+
+        assertTrue( overallQueue.isInCheckoutQueue( 1 ) );
+        context.assertIsSatisfied();
+    }
+
+    public void testRemoveProjectFromCheckoutQueue()
+        throws Exception
+    {
+        final Task checkoutTask =
+            new CheckOutTask( 1, new File( getBasedir(), "/target/test-working-dir/1" ),
"continuum-project-test-1",
+                              "dummy", "dummypass" );
+        final TaskQueue checkoutQueue = context.mock( TaskQueue.class, "checkout-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( checkoutTask );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( checkoutTaskQueueExecutor ).getQueue();
+                will( returnValue( checkoutQueue ) );
+
+                one( checkoutQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+
+                one( checkoutTaskQueueExecutor ).getQueue();
+                will( returnValue( checkoutQueue ) );
+
+                one( checkoutQueue ).remove( checkoutTask );
+            }
+        } );
+
+        overallQueue.removeProjectFromCheckoutQueue( 1 );
+        context.assertIsSatisfied();
+    }
+
+    // build queue
+
     public void testAddToBuildQueue()
         throws Exception
-    {   
-        BuildProjectTask buildTask = new BuildProjectTask( 1, 1, 1, "continuum-test-project",
"build-def-label" );
+    {
+        final Task buildTask = new BuildProjectTask( 2, 1, 1, "continuum-project-test-2",
"BUILD_DEF" );
+        final TaskQueue buildQueue = context.mock( TaskQueue.class, "build-queue" );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( buildTaskQueueExecutor ).getQueue();
+                will( returnValue( buildQueue ) );
+
+                one( buildQueue ).put( buildTask );
+            }
+        } );
+
         overallQueue.addToBuildQueue( buildTask );
-        
-        BuildProjectTask queuedTask = ( BuildProjectTask ) overallQueue.getBuildQueue().take();
-        assertNotNull( queuedTask );
-        assertEquals( 1, queuedTask.getProjectId() );
-        assertEquals( "continuum-test-project", queuedTask.getProjectName() );
-    }
-    
-    /*public void testAddToPrepareBuildQueue()
-        throws Exception
-    {
-        Map<Integer, Integer> projectsBuildDefMap = new HashMap<Integer, Integer>();
-        projectsBuildDefMap.put( new Integer( 1 ), new Integer( 1 ) ); 
-        
-        PrepareBuildProjectsTask prepareBuildTask = new PrepareBuildProjectsTask( projectsBuildDefMap,
1 );
-        overallQueue.addToPrepareBuildQueue( prepareBuildTask );
-        
-        PrepareBuildProjectsTask queuedTask = ( PrepareBuildProjectsTask ) overallQueue.getPrepareBuildQueue().take();
-        assertNotNull( queuedTask );
-        assertEquals( 1, ( ( Integer )queuedTask.getProjectsBuildDefinitionsMap().get( new
Integer( 1 ) ) ).intValue() );        
-    }*/
+        context.assertIsSatisfied();
+    }
+
+    public void testGetProjectsFromBuildQueue()
+        throws Exception
+    {
+        final TaskQueue buildQueue = context.mock( TaskQueue.class, "build-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", "BUILD_DEF"
) );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( buildTaskQueueExecutor ).getQueue();
+                will( returnValue( buildQueue ) );
+
+                one( buildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+            }
+        } );
+
+        List<Task> returnedTasks = overallQueue.getProjectsInBuildQueue();
+        context.assertIsSatisfied();
+
+        assertNotNull( returnedTasks );
+        assertEquals( 1, returnedTasks.size() );
+    }
+
+    public void testIsInBuildQueue()
+        throws Exception
+    {
+        final TaskQueue buildQueue = context.mock( TaskQueue.class, "build-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", "BUILD_DEF"
) );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( buildTaskQueueExecutor ).getQueue();
+                will( returnValue( buildQueue ) );
+
+                one( buildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+            }
+        } );
+
+        assertTrue( overallQueue.isInBuildQueue( 2 ) );
+        context.assertIsSatisfied();
+    }
+
+    public void testCancelBuildTask()
+        throws Exception
+    {
+        final Task buildTask = new BuildProjectTask( 2, 1, 1, "continuum-project-test-2",
"BUILD_DEF" );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( buildTaskQueueExecutor ).getCurrentTask();
+                will( returnValue( buildTask ) );
+
+                one( buildTaskQueueExecutor ).cancelTask( buildTask );
+            }
+        } );
+
+        overallQueue.cancelBuildTask( 2 );
+        context.assertIsSatisfied();
+    }
+
+    public void testCancelCurrentBuild()
+        throws Exception
+    {
+        final Task buildTask = new BuildProjectTask( 2, 1, 1, "continuum-project-test-2",
"BUILD_DEF" );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( buildTaskQueueExecutor ).getCurrentTask();
+                will( returnValue( buildTask ) );
+
+                one( buildTaskQueueExecutor ).cancelTask( buildTask );
+            }
+        } );
+
+        overallQueue.cancelCurrentBuild();
+        context.assertIsSatisfied();
+    }
+
+    public void testRemoveProjectFromBuildQueueWithGivenBuildDefinition()
+        throws Exception
+    {
+        final BuildDefinition buildDef = new BuildDefinition();
+        buildDef.setId( 1 );
+        buildDef.setDescription( "Test build definition" );
+
+        final TaskQueue buildQueue = context.mock( TaskQueue.class, "build-queue" );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( buildDefinitionDao ).getBuildDefinition( 1 );
+                will( returnValue( buildDef ) );
+
+                one( buildTaskQueueExecutor ).getQueue();
+                will( returnValue( buildQueue ) );
+
+                one( buildQueue ).remove( with( any( Task.class ) ) );
+            }
+        } );
+
+        overallQueue.removeProjectFromBuildQueue( 1, 1, 1, "continuum-project-test-1" );
+        context.assertIsSatisfied();
+    }
+
+    public void testRemoveProjectFromBuildQueue()
+        throws Exception
+    {
+        final Task buildTask = new BuildProjectTask( 1, 1, 1, "continuum-project-test-2",
"BUILD_DEF" );
+
+        final TaskQueue buildQueue = context.mock( TaskQueue.class, "build-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( buildTask );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( buildTaskQueueExecutor ).getQueue();
+                will( returnValue( buildQueue ) );
+
+                one( buildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+
+                one( buildTaskQueueExecutor ).getQueue();
+                will( returnValue( buildQueue ) );
+
+                one( buildQueue ).remove( buildTask );
+            }
+        } );
+
+        overallQueue.removeProjectFromBuildQueue( 1 );
+        context.assertIsSatisfied();
+    }
 }



Mime
View raw message