Search in sources :

Example 1 with TaskQueue

use of org.apache.archiva.components.taskqueue.TaskQueue in project archiva by apache.

the class RepositoryTaskAdministrationTest method testScanStatusWithId.

@Test
public void testScanStatusWithId() throws RepositoryAdminException, TaskQueueException {
    TaskQueue queue = mock(TaskQueue.class);
    TaskQueue indexQueue = mock(TaskQueue.class);
    List<RepositoryTask> scanList = new ArrayList<>();
    RepositoryTask scanTask1 = new RepositoryTask();
    scanTask1.setRepositoryId("abcde");
    scanTask1.setScanAll(true);
    scanTask1.setResourceFile(null);
    scanList.add(scanTask1);
    RepositoryTask scanTask2 = new RepositoryTask();
    scanTask2.setRepositoryId("testrepo2");
    scanTask2.setScanAll(true);
    scanTask2.setResourceFile(null);
    scanList.add(scanTask1);
    List<ArtifactIndexingTask> indexList = new ArrayList<>();
    ArtifactIndexingTask indexTask1 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
    when(indexTask1.getRepository().getId()).thenReturn("indexrepo1");
    when(indexTask1.isExecuteOnEntireRepo()).thenReturn(true);
    when(indexTask1.getResourceFile()).thenReturn(null);
    indexList.add(indexTask1);
    ArtifactIndexingTask indexTask2 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
    when(indexTask2.getRepository().getId()).thenReturn("indexrepo2");
    when(indexTask2.isExecuteOnEntireRepo()).thenReturn(true);
    when(indexTask2.getResourceFile()).thenReturn(null);
    indexList.add(indexTask2);
    when(scanningTaskExecutor.getQueue()).thenReturn(queue);
    when(indexingTaskExecutor.getQueue()).thenReturn(indexQueue);
    when(queue.getQueueSnapshot()).thenReturn(scanList);
    when(indexQueue.getQueueSnapshot()).thenReturn(indexList);
    when(registry.getManagedRepository("indexrepo2")).thenReturn(mock(ManagedRepository.class));
    ScanStatus currentScanStatus = taskAdministration.getCurrentScanStatus("indexrepo2");
    assertNotNull(currentScanStatus);
    assertNotNull(currentScanStatus.getIndexingQueue());
    assertNotNull(currentScanStatus.getScanQueue());
    assertEquals(0, currentScanStatus.getScanQueue().size());
    assertEquals(1, currentScanStatus.getIndexingQueue().size());
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) ArtifactIndexingTask(org.apache.archiva.scheduler.indexing.ArtifactIndexingTask) ScanStatus(org.apache.archiva.admin.model.beans.ScanStatus) ArrayList(java.util.ArrayList) TaskQueue(org.apache.archiva.components.taskqueue.TaskQueue) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) Test(org.junit.jupiter.api.Test)

Example 2 with TaskQueue

use of org.apache.archiva.components.taskqueue.TaskQueue in project archiva by apache.

the class RepositoryTaskAdministrationTest method cancelAllTasks.

@Test
void cancelAllTasks() throws TaskQueueException, RepositoryAdminException {
    TaskQueue queue = mock(TaskQueue.class);
    TaskQueue indexQueue = mock(TaskQueue.class);
    List<RepositoryTask> scanList = new ArrayList<>();
    RepositoryTask scanTask1 = new RepositoryTask();
    scanTask1.setRepositoryId("abcde");
    scanTask1.setScanAll(true);
    scanTask1.setResourceFile(null);
    scanList.add(scanTask1);
    RepositoryTask scanTask2 = new RepositoryTask();
    scanTask2.setRepositoryId("testrepo2");
    scanTask2.setScanAll(true);
    scanTask2.setResourceFile(null);
    scanList.add(scanTask1);
    List<ArtifactIndexingTask> indexList = new ArrayList<>();
    ArtifactIndexingTask indexTask1 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
    when(indexTask1.getRepository().getId()).thenReturn("indexrepo1");
    when(indexTask1.isExecuteOnEntireRepo()).thenReturn(true);
    when(indexTask1.getResourceFile()).thenReturn(null);
    indexList.add(indexTask1);
    ArtifactIndexingTask indexTask2 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
    when(indexTask2.getRepository().getId()).thenReturn("indexrepo2");
    when(indexTask2.isExecuteOnEntireRepo()).thenReturn(true);
    when(indexTask2.getResourceFile()).thenReturn(null);
    indexList.add(indexTask2);
    when(scanningTaskExecutor.getQueue()).thenReturn(queue);
    when(indexingTaskExecutor.getQueue()).thenReturn(indexQueue);
    when(queue.getQueueSnapshot()).thenReturn(scanList);
    when(indexQueue.getQueueSnapshot()).thenReturn(indexList);
    taskAdministration.cancelTasks("indexrepo1");
    ArgumentCaptor<List> scanCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<List> indexCaptor = ArgumentCaptor.forClass(List.class);
    verify(queue).removeAll(scanCaptor.capture());
    verify(indexQueue).removeAll(indexCaptor.capture());
    List scanCancelList = scanCaptor.getValue();
    List indexCancelList = indexCaptor.getValue();
    assertEquals(0, scanCancelList.size());
    assertEquals(1, indexCancelList.size());
    assertEquals("indexrepo1", ((ArtifactIndexingTask) indexCancelList.get(0)).getRepository().getId());
}
Also used : ArtifactIndexingTask(org.apache.archiva.scheduler.indexing.ArtifactIndexingTask) ArrayList(java.util.ArrayList) TaskQueue(org.apache.archiva.components.taskqueue.TaskQueue) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) Test(org.junit.jupiter.api.Test)

Example 3 with TaskQueue

use of org.apache.archiva.components.taskqueue.TaskQueue in project archiva by apache.

the class RepositoryTaskAdministrationTest method testScanStatus.

@Test
public void testScanStatus() throws RepositoryAdminException, TaskQueueException {
    TaskQueue queue = mock(TaskQueue.class);
    TaskQueue indexQueue = mock(TaskQueue.class);
    List<RepositoryTask> scanList = new ArrayList<>();
    RepositoryTask scanTask1 = new RepositoryTask();
    scanTask1.setRepositoryId("abcde");
    scanTask1.setScanAll(true);
    scanTask1.setResourceFile(null);
    scanList.add(scanTask1);
    RepositoryTask scanTask2 = new RepositoryTask();
    scanTask2.setRepositoryId("testrepo2");
    scanTask2.setScanAll(true);
    scanTask2.setResourceFile(null);
    scanList.add(scanTask1);
    List<ArtifactIndexingTask> indexList = new ArrayList<>();
    ArtifactIndexingTask indexTask1 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
    when(indexTask1.getRepository().getId()).thenReturn("indexrepo1");
    when(indexTask1.isExecuteOnEntireRepo()).thenReturn(true);
    when(indexTask1.getResourceFile()).thenReturn(null);
    indexList.add(indexTask1);
    ArtifactIndexingTask indexTask2 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
    when(indexTask2.getRepository().getId()).thenReturn("indexrepo2");
    when(indexTask2.isExecuteOnEntireRepo()).thenReturn(true);
    when(indexTask2.getResourceFile()).thenReturn(null);
    indexList.add(indexTask2);
    when(scanningTaskExecutor.getQueue()).thenReturn(queue);
    when(indexingTaskExecutor.getQueue()).thenReturn(indexQueue);
    when(queue.getQueueSnapshot()).thenReturn(scanList);
    when(indexQueue.getQueueSnapshot()).thenReturn(indexList);
    ScanStatus currentScanStatus = taskAdministration.getCurrentScanStatus();
    assertNotNull(currentScanStatus);
    assertNotNull(currentScanStatus.getIndexingQueue());
    assertNotNull(currentScanStatus.getScanQueue());
    assertEquals(2, currentScanStatus.getScanQueue().size());
    assertEquals(2, currentScanStatus.getIndexingQueue().size());
}
Also used : ArtifactIndexingTask(org.apache.archiva.scheduler.indexing.ArtifactIndexingTask) ScanStatus(org.apache.archiva.admin.model.beans.ScanStatus) ArrayList(java.util.ArrayList) TaskQueue(org.apache.archiva.components.taskqueue.TaskQueue) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) Test(org.junit.jupiter.api.Test)

Example 4 with TaskQueue

use of org.apache.archiva.components.taskqueue.TaskQueue in project archiva by apache.

the class RepositoryTaskJob method execute.

/**
 * Execute the discoverer and the indexer.
 *
 * @param context
 * @throws org.quartz.JobExecutionException
 */
@SuppressWarnings("unchecked")
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap dataMap = context.getJobDetail().getJobDataMap();
    setJobDataMap(dataMap);
    TaskQueue taskQueue = (TaskQueue) dataMap.get(DefaultRepositoryArchivaTaskScheduler.TASK_QUEUE);
    String repositoryId = (String) dataMap.get(DefaultRepositoryArchivaTaskScheduler.TASK_REPOSITORY);
    RepositoryTask task = new RepositoryTask();
    task.setRepositoryId(repositoryId);
    try {
        taskQueue.put(task);
    } catch (TaskQueueException e) {
        throw new JobExecutionException(e);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException) TaskQueue(org.apache.archiva.components.taskqueue.TaskQueue) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) TaskQueueException(org.apache.archiva.components.taskqueue.TaskQueueException)

Aggregations

TaskQueue (org.apache.archiva.components.taskqueue.TaskQueue)4 RepositoryTask (org.apache.archiva.scheduler.repository.model.RepositoryTask)4 ArrayList (java.util.ArrayList)3 ArtifactIndexingTask (org.apache.archiva.scheduler.indexing.ArtifactIndexingTask)3 Test (org.junit.jupiter.api.Test)3 ScanStatus (org.apache.archiva.admin.model.beans.ScanStatus)2 List (java.util.List)1 TaskQueueException (org.apache.archiva.components.taskqueue.TaskQueueException)1 ManagedRepository (org.apache.archiva.repository.ManagedRepository)1 JobDataMap (org.quartz.JobDataMap)1 JobExecutionException (org.quartz.JobExecutionException)1