Search in sources :

Example 1 with UniqueRepoQueue

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());
}
Also used : RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) SharedService(com.searchcode.app.service.SharedService) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 2 with UniqueRepoQueue

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();
}
Also used : IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue)

Example 3 with UniqueRepoQueue

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());
        }
    }
}
Also used : RunningIndexJob(com.searchcode.app.dto.RunningIndexJob) Path(java.nio.file.Path) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 4 with UniqueRepoQueue

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);
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse) RepoResult(com.searchcode.app.model.RepoResult)

Example 5 with UniqueRepoQueue

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);
}
Also used : UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)10 RepoResult (com.searchcode.app.model.RepoResult)8 Repo (com.searchcode.app.dao.Repo)3 ApiResponse (com.searchcode.app.dto.api.ApiResponse)3 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)3 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)3 Request (spark.Request)3 IndexGitRepoJob (com.searchcode.app.jobs.repository.IndexGitRepoJob)2 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)1 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)1 SharedService (com.searchcode.app.service.SharedService)1 Singleton (com.searchcode.app.service.Singleton)1 Path (java.nio.file.Path)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 org.quartz (org.quartz)1