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());
}
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());
}
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());
}
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);
}
}
Aggregations