Search in sources :

Example 1 with StatsService

use of com.searchcode.app.service.StatsService in project searchcode-server by boyter.

the class IndexDocumentsJob method execute.

public void execute(JobExecutionContext context) throws JobExecutionException {
    if (!Singleton.getSharedService().getBackgroundJobsEnabled()) {
        return;
    }
    try {
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY + 1);
        int codeIndexQueueSize = Singleton.getCodeIndexQueue().size();
        if (codeIndexQueueSize != 0) {
            StatsService statsService = new StatsService();
            Singleton.getLogger().info("Documents to index: " + codeIndexQueueSize);
            Singleton.getLogger().info("Lines to index: " + Singleton.getSharedService().getCodeIndexLinesCount());
            Singleton.getLogger().info("Memory Usage: " + statsService.getMemoryUsage(", "));
            Singleton.getCodeIndexer().indexDocuments(Singleton.getCodeIndexQueue());
        }
    } catch (Exception ex) {
        // Continue at all costs
        Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + "\n with message: " + ex.getMessage());
    }
}
Also used : StatsService(com.searchcode.app.service.StatsService) IOException(java.io.IOException)

Example 2 with StatsService

use of com.searchcode.app.service.StatsService in project searchcode-server by boyter.

the class IndexBaseAndGitRepoJobTest method testShouldJobTerminate.

public void testShouldJobTerminate() {
    IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
    StatsService statsServiceMock = Mockito.mock(StatsService.class);
    when(statsServiceMock.getLoadAverage()).thenReturn("0.0");
    Singleton.setStatsService(statsServiceMock);
    assertThat(gitRepoJob.shouldJobPauseOrTerminate()).isFalse();
    Singleton.getSharedService().setBackgroundJobsEnabled(false);
    assertThat(gitRepoJob.shouldJobPauseOrTerminate()).isTrue();
    Singleton.getSharedService().setBackgroundJobsEnabled(true);
    assertThat(gitRepoJob.shouldJobPauseOrTerminate()).isFalse();
    Singleton.getSharedService().setPauseBackgroundJobs(true);
    Singleton.getSharedService().setBackgroundJobsEnabled(false);
    assertThat(gitRepoJob.shouldJobPauseOrTerminate()).isTrue();
}
Also used : StatsService(com.searchcode.app.service.StatsService) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 3 with StatsService

use of com.searchcode.app.service.StatsService in project searchcode-server by boyter.

the class IndexServiceTest method testShouldNotBackOffWhenLoadZero.

public void testShouldNotBackOffWhenLoadZero() {
    Data dataMock = mock(Data.class);
    StatsService statsServiceMock = mock(StatsService.class);
    when(statsServiceMock.getLoadAverage()).thenReturn("0.0");
    when(dataMock.getDataByName(Values.BACKOFFVALUE, Values.DEFAULTBACKOFFVALUE)).thenReturn("1");
    this.indexService = new IndexService(dataMock, statsServiceMock, null, Singleton.getLogger(), Singleton.getHelpers(), new ConcurrentLinkedQueue<>(), null);
    assertThat(this.indexService.shouldPause(IIndexService.JobType.REPO_PARSER)).isFalse();
}
Also used : StatsService(com.searchcode.app.service.StatsService) Data(com.searchcode.app.dao.Data) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 4 with StatsService

use of com.searchcode.app.service.StatsService in project searchcode-server by boyter.

the class IndexServiceTest method testShouldBackOffWhenLoadVeryHigh.

public void testShouldBackOffWhenLoadVeryHigh() {
    Data dataMock = mock(Data.class);
    StatsService statsServiceMock = mock(StatsService.class);
    when(statsServiceMock.getLoadAverage()).thenReturn("10000000.0");
    when(dataMock.getDataByName(Values.BACKOFFVALUE, Values.DEFAULTBACKOFFVALUE)).thenReturn("1");
    this.indexService = new IndexService(dataMock, statsServiceMock, null, Singleton.getLogger(), Singleton.getHelpers(), null, null);
    assertThat(this.indexService.shouldPause(IIndexService.JobType.REPO_PARSER)).isTrue();
}
Also used : StatsService(com.searchcode.app.service.StatsService) Data(com.searchcode.app.dao.Data)

Example 5 with StatsService

use of com.searchcode.app.service.StatsService in project searchcode-server by boyter.

the class IndexServiceTest method testShouldBackOffWhenLoadHigherThanValue.

public void testShouldBackOffWhenLoadHigherThanValue() {
    Data dataMock = mock(Data.class);
    StatsService statsServiceMock = mock(StatsService.class);
    when(statsServiceMock.getLoadAverage()).thenReturn("0.21");
    when(dataMock.getDataByName(Values.BACKOFFVALUE, Values.DEFAULTBACKOFFVALUE)).thenReturn("0.2");
    this.indexService = new IndexService(dataMock, statsServiceMock, null, Singleton.getLogger(), Singleton.getHelpers(), null, null);
    assertThat(this.indexService.shouldPause(IIndexService.JobType.REPO_PARSER)).isTrue();
}
Also used : StatsService(com.searchcode.app.service.StatsService) Data(com.searchcode.app.dao.Data)

Aggregations

StatsService (com.searchcode.app.service.StatsService)6 Data (com.searchcode.app.dao.Data)3 IndexGitRepoJob (com.searchcode.app.jobs.repository.IndexGitRepoJob)1 IndexService (com.searchcode.app.service.index.IndexService)1 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)1 IOException (java.io.IOException)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 JobExecutionContext (org.quartz.JobExecutionContext)1