archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r703316 - in /archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src: main/java/org/apache/archiva/web/xmlrpc/services/ test/java/org/apache/archiva/web/xmlrpc/services/
Date Fri, 10 Oct 2008 02:27:32 GMT
Author: oching
Date: Thu Oct  9 19:27:32 2008
New Revision: 703316

URL: http://svn.apache.org/viewvc?rev=703316&view=rev
Log:
- implemented executeDatabaseScanner() and executeRepositoryScanner() for admin service
- activated and added tests for these 2 methods

Modified:
    archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
    archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java

Modified: archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java?rev=703316&r1=703315&r2=703316&view=diff
==============================================================================
--- archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
(original)
+++ archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
Thu Oct  9 19:27:32 2008
@@ -38,6 +38,11 @@
 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
 import org.apache.maven.archiva.database.updater.DatabaseConsumers;
 import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
+import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
+import org.apache.maven.archiva.scheduled.DefaultArchivaTaskScheduler;
+import org.apache.maven.archiva.scheduled.tasks.ArchivaTask;
+import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
+import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
 import org.codehaus.plexus.registry.RegistryException;
 
 /**
@@ -63,7 +68,10 @@
      */
     private DatabaseConsumers dbConsumersUtil;
     
-    private String requestUrl;    
+    /**
+     * @plexus.requirement
+     */
+    private ArchivaTaskScheduler taskScheduler;
     
     /**
      * @see AdministrationService#configureDatabaseConsumer(String, boolean)
@@ -195,8 +203,18 @@
      */
     public boolean executeDatabaseScanner() throws Exception
     {
-        // TODO Auto-generated method stub
-        return false;
+        if ( taskScheduler.isProcessingDatabaseTask() )
+        {
+            return false;
+        }
+
+        DatabaseTask task = new DatabaseTask();
+        task.setName( DefaultArchivaTaskScheduler.DATABASE_JOB + ":user-requested-via-web-service"
);
+        task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
+        
+        taskScheduler.queueDatabaseTask( task );            
+        
+        return true;
     }
 
     /**
@@ -204,8 +222,28 @@
      */
     public boolean executeRepositoryScanner( String repoId ) throws Exception
     {
-        // TODO Auto-generated method stub
-        return false;
+        Configuration config = archivaConfiguration.getConfiguration();
+        if( config.findManagedRepositoryById( repoId ) == null )
+        {
+            throw new Exception( "Repository does not exist." );
+        }
+        
+        if ( taskScheduler.isProcessingAnyRepositoryTask() )
+        {
+            if ( taskScheduler.isProcessingRepositoryTask( repoId ) )
+            {
+                return false;
+            }
+        }
+
+        RepositoryTask task = new RepositoryTask();
+        task.setRepositoryId( repoId );
+        task.setName( DefaultArchivaTaskScheduler.REPOSITORY_JOB + ":" + repoId );
+        task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
+
+        taskScheduler.queueRepositoryTask( task );            
+        
+        return true;
     }
 
     /**
@@ -327,5 +365,10 @@
     public void setDbConsumersUtil( DatabaseConsumers consumerUtil )
     {
         this.dbConsumersUtil = consumerUtil;
+    }
+
+    public void setTaskScheduler( ArchivaTaskScheduler taskScheduler )
+    {
+        this.taskScheduler = taskScheduler;
     }   
 }

Modified: archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java?rev=703316&r1=703315&r2=703316&view=diff
==============================================================================
--- archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
(original)
+++ archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
Thu Oct  9 19:27:32 2008
@@ -142,6 +142,7 @@
         service.setArchivaConfiguration( archivaConfig );
         service.setRepoConsumersUtil( repoConsumersUtil );     
         service.setDbConsumersUtil( dbConsumersUtil );
+        service.setTaskScheduler( taskScheduler );
     }
   
 /* Tests for database consumers  */
@@ -496,10 +497,11 @@
         archivaConfigControl.verify();
         configControl.verify();
     }
+    */
     
-// REPO SCANNING
+/* Tests for repository scanning  */
     
-    public void testExecuteRepoScannerRepoExists()
+    public void testExecuteRepoScannerRepoExistsAndNotBeingScanned()
         throws Exception
     {        
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
@@ -508,7 +510,7 @@
         
         RepositoryTask task = new RepositoryTask();
         
-        taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingAnyRepositoryTask(),
false );
+        taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingAnyRepositoryTask(),
true );
         taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingRepositoryTask( "internal"
), false );
         
         taskScheduler.queueRepositoryTask( task );
@@ -534,6 +536,35 @@
         taskSchedulerControl.verify();
     }
     
+    public void testExecuteRepoScannerRepoExistsButBeingScanned()
+        throws Exception
+    {        
+        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+        configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
+                                       createManagedRepo( "internal", "default", "Internal
Repository", true, false ) );
+        
+        taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingAnyRepositoryTask(),
true );
+        taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingRepositoryTask( "internal"
), true);
+        
+        archivaConfigControl.replay();
+        configControl.replay();
+        taskSchedulerControl.replay();
+    
+        try
+        {
+            boolean success = service.executeRepositoryScanner( "internal" );
+            assertFalse( success );
+        }
+        catch ( Exception e )
+        {
+            fail( "An exception should not have been thrown." );
+        }
+        
+        archivaConfigControl.verify();
+        configControl.verify();
+        taskSchedulerControl.verify();
+    }
+    
     public void testExecuteRepoScannerRepoDoesNotExist()
         throws Exception
     {
@@ -557,9 +588,9 @@
         configControl.verify();
     }
     
- // DATABASE SCANNING
+/* Tests for db scanning  */
     
-    public void testExecuteDbScanner()
+    public void testExecuteDbScannerDbNotBeingScanned()
         throws Exception
     {
         DatabaseTask task = new DatabaseTask();
@@ -578,8 +609,21 @@
         
         assertTrue( success );
     }
- */
     
+    public void testExecuteDbScannerDbIsBeingScanned()
+        throws Exception
+    {        
+        taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingDatabaseTask(), true
);
+                
+        taskSchedulerControl.replay();
+
+        boolean success = service.executeDatabaseScanner();
+        
+        taskSchedulerControl.verify();        
+        
+        assertFalse( success );
+    }
+     
 /* Tests for querying repositories  */
     
     public void testGetAllManagedRepositories()



Mime
View raw message