Search in sources :

Example 11 with EsConnector

use of org.sonar.application.es.EsConnector in project sonarqube by SonarSource.

the class EsManagedProcessTest method isOperational_should_return_false_if_ElasticsearchException_with_connection_refused_thrown.

@Test
public void isOperational_should_return_false_if_ElasticsearchException_with_connection_refused_thrown() {
    EsConnector esConnector = mock(EsConnector.class);
    when(esConnector.getClusterHealthStatus()).thenThrow(new ElasticsearchException("Connection refused"));
    EsManagedProcess underTest = new EsManagedProcess(mock(Process.class), ProcessId.ELASTICSEARCH, esConnector, WAIT_FOR_UP_TIMEOUT);
    assertThat(underTest.isOperational()).isFalse();
}
Also used : EsConnector(org.sonar.application.es.EsConnector) ElasticsearchException(org.elasticsearch.ElasticsearchException) Test(org.junit.Test)

Example 12 with EsConnector

use of org.sonar.application.es.EsConnector in project sonarqube by SonarSource.

the class ClusterAppStateImplTest method check_if_elasticsearch_is_operational_on_cluster.

@Test
public void check_if_elasticsearch_is_operational_on_cluster() {
    AppStateListener listener = mock(AppStateListener.class);
    EsConnector esConnectorMock = mock(EsConnector.class);
    when(esConnectorMock.getClusterHealthStatus()).thenReturn(Optional.empty()).thenReturn(Optional.of(ClusterHealthStatus.RED)).thenReturn(Optional.of(ClusterHealthStatus.GREEN));
    try (ClusterAppStateImpl underTest = createClusterAppState(esConnectorMock)) {
        underTest.addListener(listener);
        underTest.isOperational(ProcessId.ELASTICSEARCH, false);
        // wait until undergoing thread marks ES as operational
        verify(listener, timeout(20_000)).onAppStateOperational(ProcessId.ELASTICSEARCH);
    }
}
Also used : EsConnector(org.sonar.application.es.EsConnector) AppStateListener(org.sonar.application.AppStateListener) Test(org.junit.Test)

Example 13 with EsConnector

use of org.sonar.application.es.EsConnector in project sonarqube by SonarSource.

the class AppStateFactory method create.

public AppState create() {
    if (ClusterSettings.shouldStartHazelcast(settings)) {
        EsConnector esConnector = createEsConnector(settings.getProps());
        HazelcastMember hzMember = createHzMember(settings.getProps());
        AppNodesClusterHostsConsistency appNodesClusterHostsConsistency = AppNodesClusterHostsConsistency.setInstance(hzMember, settings);
        return new ClusterAppStateImpl(settings, hzMember, esConnector, appNodesClusterHostsConsistency);
    }
    return new AppStateImpl();
}
Also used : EsConnector(org.sonar.application.es.EsConnector) AppNodesClusterHostsConsistency(org.sonar.application.cluster.AppNodesClusterHostsConsistency) ClusterAppStateImpl(org.sonar.application.cluster.ClusterAppStateImpl) HazelcastMember(org.sonar.process.cluster.hz.HazelcastMember) ClusterAppStateImpl(org.sonar.application.cluster.ClusterAppStateImpl)

Aggregations

EsConnector (org.sonar.application.es.EsConnector)13 Test (org.junit.Test)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 ConnectException (java.net.ConnectException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)1 AppStateListener (org.sonar.application.AppStateListener)1 AppNodesClusterHostsConsistency (org.sonar.application.cluster.AppNodesClusterHostsConsistency)1 ClusterAppStateImpl (org.sonar.application.cluster.ClusterAppStateImpl)1 HazelcastMember (org.sonar.process.cluster.hz.HazelcastMember)1