From b66aed05260796a53bb69de67e9c2a9adfb5bf4d Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Fri, 10 Oct 2008 02:27:32 +0000 Subject: [PATCH] - implemented executeDatabaseScanner() and executeRepositoryScanner() for admin service - activated and added tests for these 2 methods git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-124@703316 13f79535-47bb-0310-9956-ffa450edef68 --- .../services/AdministrationServiceImpl.java | 53 ++++++++++++++++-- .../AdministrationServiceImplTest.java | 56 +++++++++++++++++-- 2 files changed, 98 insertions(+), 11 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java index 8d59df21f..35ff650a1 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java @@ -38,6 +38,11 @@ import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; 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 @@ public class AdministrationServiceImpl */ private DatabaseConsumers dbConsumersUtil; - private String requestUrl; + /** + * @plexus.requirement + */ + private ArchivaTaskScheduler taskScheduler; /** * @see AdministrationService#configureDatabaseConsumer(String, boolean) @@ -195,8 +203,18 @@ public class AdministrationServiceImpl */ 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 class AdministrationServiceImpl */ 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 class AdministrationServiceImpl public void setDbConsumersUtil( DatabaseConsumers consumerUtil ) { this.dbConsumersUtil = consumerUtil; + } + + public void setTaskScheduler( ArchivaTaskScheduler taskScheduler ) + { + this.taskScheduler = taskScheduler; } } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java index f8ed311a1..29ec95215 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java @@ -142,6 +142,7 @@ public class AdministrationServiceImplTest service.setArchivaConfiguration( archivaConfig ); service.setRepoConsumersUtil( repoConsumersUtil ); service.setDbConsumersUtil( dbConsumersUtil ); + service.setTaskScheduler( taskScheduler ); } /* Tests for database consumers */ @@ -496,10 +497,11 @@ public class AdministrationServiceImplTest 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 @@ public class AdministrationServiceImplTest 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 @@ public class AdministrationServiceImplTest 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 @@ public class AdministrationServiceImplTest configControl.verify(); } - // DATABASE SCANNING +/* Tests for db scanning */ - public void testExecuteDbScanner() + public void testExecuteDbScannerDbNotBeingScanned() throws Exception { DatabaseTask task = new DatabaseTask(); @@ -578,8 +609,21 @@ public class AdministrationServiceImplTest 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() -- 2.39.5