use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.
the class IndexBaseRepoJobTest method testExecuteHasMethodInQueueNewRepository.
public void testExecuteHasMethodInQueueNewRepository() throws JobExecutionException {
SharedService sharedServiceMock = mock(SharedService.class);
when(sharedServiceMock.getPauseBackgroundJobs()).thenReturn(false);
when(sharedServiceMock.getBackgroundJobsEnabled()).thenReturn(true);
IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob(sharedServiceMock);
IndexGitRepoJob spy = spy(indexGitRepoJob);
spy.haveRepoResult = false;
UniqueRepoQueue uniqueRepoQueue = new UniqueRepoQueue();
uniqueRepoQueue.add(new RepoResult(1, "name", "scm", "url", "username", "password", "source", "branch", "{}"));
when(spy.getNextQueuedRepo()).thenReturn(uniqueRepoQueue);
when(spy.isEnabled()).thenReturn(true);
when(spy.getNewRepository(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean())).thenReturn(new RepositoryChanged(false, null, null));
when(mockCodeIndexer.shouldPauseAdding()).thenReturn(false);
spy.codeIndexer = mockCodeIndexer;
spy.execute(this.mockContext);
assertThat(spy.haveRepoResult).isTrue();
assertThat(spy.LOWMEMORY).isTrue();
verify(spy).getNextQueuedRepo();
verify(spy, times(2)).getNewRepository(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean());
}
use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.
the class IndexBaseRepoJobTest method testExecuteNothingInQueue.
public void testExecuteNothingInQueue() throws JobExecutionException {
IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
IndexGitRepoJob spy = spy(indexGitRepoJob);
spy.haveRepoResult = false;
when(spy.getNextQueuedRepo()).thenReturn(new UniqueRepoQueue());
spy.codeIndexer = mockCodeIndexer;
spy.execute(this.mockContext);
assertThat(spy.haveRepoResult).isFalse();
}
use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.
the class IndexFileRepoJob method execute.
/**
* The main method used for finding jobs to index and actually doing the work
*/
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
if (!isEnabled()) {
return;
}
if (!this.sharedService.getBackgroundJobsEnabled()) {
return;
}
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while (Singleton.getCodeIndexer().shouldPauseAdding()) {
Singleton.getLogger().info("Pausing parser.");
return;
}
// Pull the next repo to index from the queue
UniqueRepoQueue repoQueue = this.getNextQueuedRepo();
RepoResult repoResult = repoQueue.poll();
if (repoResult != null && !Singleton.getRunningIndexRepoJobs().containsKey(repoResult.getName())) {
Singleton.getLogger().info("File Indexer Indexing " + repoResult.getName());
repoResult.getData().indexStatus = "indexing";
repoResult.getData().jobRunTime = Instant.now();
Singleton.getRepo().saveRepo(repoResult);
try {
Singleton.getRunningIndexRepoJobs().put(repoResult.getName(), new RunningIndexJob("Indexing", Singleton.getHelpers().getCurrentTimeSeconds()));
JobDataMap data = context.getJobDetail().getJobDataMap();
String repoName = repoResult.getName();
this.repoName = repoName;
String repoRemoteLocation = repoResult.getUrl();
String repoLocations = data.get("REPOLOCATIONS").toString();
this.LOWMEMORY = Boolean.parseBoolean(data.get("LOWMEMORY").toString());
Path docDir = Paths.get(repoRemoteLocation);
this.indexDocsByPath(docDir, repoName, repoLocations, repoRemoteLocation, true);
int runningTime = Singleton.getHelpers().getCurrentTimeSeconds() - Singleton.getRunningIndexRepoJobs().get(repoResult.getName()).startTime;
repoResult.getData().averageIndexTimeSeconds = (repoResult.getData().averageIndexTimeSeconds + runningTime) / 2;
repoResult.getData().indexStatus = "success";
repoResult.getData().jobRunTime = Instant.now();
Singleton.getRepo().saveRepo(repoResult);
} finally {
// Clean up the job
Singleton.getRunningIndexRepoJobs().remove(repoResult.getName());
}
}
}
use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoDeleteAuthReponameNoPub.
public void testRepoDeleteAuthReponameNoPub() {
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
UniqueRepoQueue uniqueRepoQueue = new UniqueRepoQueue(new ConcurrentLinkedQueue<>());
when(mockRepo.getRepoByName("unit-test")).thenReturn(new RepoResult());
ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, null, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = true;
when(mockRequest.queryParams("reponame")).thenReturn("unit-test");
ApiResponse apiResponse = apiRouteService.repoDelete(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("pub is a required parameter");
assertThat(apiResponse.isSucessful()).isFalse();
assertThat(uniqueRepoQueue.size()).isEqualTo(0);
}
use of com.searchcode.app.util.UniqueRepoQueue in project searchcode-server by boyter.
the class JobServiceTest method testEnqueueByReporesultBackgroundDisabledReturnsFalse.
public void testEnqueueByReporesultBackgroundDisabledReturnsFalse() {
UniqueRepoQueue repoGitQueue = Singleton.getUniqueGitRepoQueue();
UniqueRepoQueue repoSvnQueue = Singleton.getUniqueSvnRepoQueue();
UniqueRepoQueue repoFileQueue = Singleton.getUniqueFileRepoQueue();
repoGitQueue.clear();
repoSvnQueue.clear();
repoFileQueue.clear();
JobService jobService = new JobService();
Singleton.getSharedService().setBackgroundJobsEnabled(true);
assertThat(jobService.forceEnqueue(new RepoResult(0, "name", "git", "url", "username", "password", "source", "branch", ""))).isTrue();
assertThat(jobService.forceEnqueue(new RepoResult(1, "name", "svn", "url", "username", "password", "source", "branch", ""))).isTrue();
assertThat(jobService.forceEnqueue(new RepoResult(2, "name", "file", "url", "username", "password", "source", "branch", ""))).isTrue();
assertThat(repoGitQueue.size()).isEqualTo(1);
assertThat(repoSvnQueue.size()).isEqualTo(1);
assertThat(repoFileQueue.size()).isEqualTo(1);
assertThat(repoGitQueue.poll().getRowId()).isEqualTo(0);
assertThat(repoSvnQueue.poll().getRowId()).isEqualTo(1);
assertThat(repoFileQueue.poll().getRowId()).isEqualTo(2);
}
Aggregations