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