Search in sources :

Example 1 with EsClient

use of org.sonar.server.es.EsClient in project sonarqube by SonarSource.

the class EsMonitorTest method attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails.

@Test
public void attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails() {
    EsClient esClientMock = mock(EsClient.class);
    EsMonitor underTest = new EsMonitor(esClientMock);
    when(esClientMock.prepareClusterStats()).thenThrow(new RuntimeException("RuntimeException with ES cause", new ElasticsearchException("some cause message")));
    Map<String, Object> attributes = underTest.attributes();
    assertThat(attributes).hasSize(1);
    assertThat(attributes.get("State")).isEqualTo("some cause message");
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) EsClient(org.sonar.server.es.EsClient) Test(org.junit.Test)

Example 2 with EsClient

use of org.sonar.server.es.EsClient in project sonarqube by SonarSource.

the class PermissionIndexer method index.

private void index(Collection<PermissionIndexerDao.Dto> authorizations, AuthorizationScope scope, Size bulkSize) {
    IndexType indexType = scope.getIndexType();
    BulkIndexer bulkIndexer = new BulkIndexer(esClient, indexType.getIndex());
    bulkIndexer.setSize(bulkSize);
    bulkIndexer.start();
    authorizations.stream().filter(scope.getProjectPredicate()).map(dto -> newIndexRequest(dto, indexType)).forEach(bulkIndexer::add);
    bulkIndexer.stop();
}
Also used : Arrays(java.util.Arrays) Collection(java.util.Collection) Set(java.util.Set) Collectors(org.sonar.core.util.stream.Collectors) HashMap(java.util.HashMap) Collectors.toSet(org.sonar.core.util.stream.Collectors.toSet) BulkIndexer(org.sonar.server.es.BulkIndexer) DbSession(org.sonar.db.DbSession) EsClient(org.sonar.server.es.EsClient) DbClient(org.sonar.db.DbClient) List(java.util.List) IndexRequest(org.elasticsearch.action.index.IndexRequest) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Stream(java.util.stream.Stream) DateUtils(org.sonar.api.utils.DateUtils) Dto(org.sonar.server.permission.index.PermissionIndexerDao.Dto) Map(java.util.Map) Size(org.sonar.server.es.BulkIndexer.Size) ProjectIndexer(org.sonar.server.es.ProjectIndexer) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StartupIndexer(org.sonar.server.es.StartupIndexer) IndexType(org.sonar.server.es.IndexType) IndexType(org.sonar.server.es.IndexType) BulkIndexer(org.sonar.server.es.BulkIndexer)

Example 3 with EsClient

use of org.sonar.server.es.EsClient in project sonarqube by SonarSource.

the class EsMonitorTest method attributes_displays_exception_message_when_cause_is_not_ElasticSearchException_when_client_fails.

@Test
public void attributes_displays_exception_message_when_cause_is_not_ElasticSearchException_when_client_fails() {
    EsClient esClientMock = mock(EsClient.class);
    EsMonitor underTest = new EsMonitor(esClientMock);
    when(esClientMock.prepareClusterStats()).thenThrow(new RuntimeException("RuntimeException with cause not ES", new IllegalArgumentException("some cause message")));
    Map<String, Object> attributes = underTest.attributes();
    assertThat(attributes).hasSize(1);
    assertThat(attributes.get("State")).isEqualTo("RuntimeException with cause not ES");
}
Also used : EsClient(org.sonar.server.es.EsClient) Test(org.junit.Test)

Example 4 with EsClient

use of org.sonar.server.es.EsClient in project sonarqube by SonarSource.

the class EsMonitorTest method attributes_displays_exception_message_when_cause_null_when_client_fails.

@Test
public void attributes_displays_exception_message_when_cause_null_when_client_fails() {
    EsClient esClientMock = mock(EsClient.class);
    EsMonitor underTest = new EsMonitor(esClientMock);
    when(esClientMock.prepareClusterStats()).thenThrow(new RuntimeException("RuntimeException with no cause"));
    Map<String, Object> attributes = underTest.attributes();
    assertThat(attributes).hasSize(1);
    assertThat(attributes.get("State")).isEqualTo("RuntimeException with no cause");
}
Also used : EsClient(org.sonar.server.es.EsClient) Test(org.junit.Test)

Aggregations

EsClient (org.sonar.server.es.EsClient)4 Test (org.junit.Test)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1 DateUtils (org.sonar.api.utils.DateUtils)1 Collectors (org.sonar.core.util.stream.Collectors)1 Collectors.toSet (org.sonar.core.util.stream.Collectors.toSet)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 BulkIndexer (org.sonar.server.es.BulkIndexer)1 Size (org.sonar.server.es.BulkIndexer.Size)1