Search in sources :

Example 1 with EsConnector

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

the class EsManagedProcessTest method isOperational_must_log_once_when_master_is_not_elected.

@Test
public void isOperational_must_log_once_when_master_is_not_elected() {
    MemoryAppender<ILoggingEvent> memoryAppender = new MemoryAppender<>();
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.reset();
    memoryAppender.setContext(lc);
    memoryAppender.start();
    lc.getLogger(EsManagedProcess.class).addAppender(memoryAppender);
    EsConnector esConnector = mock(EsConnector.class);
    when(esConnector.getClusterHealthStatus()).thenThrow(new ElasticsearchStatusException("foobar[type=master_not_discovered_exception,acme]...", RestStatus.SERVICE_UNAVAILABLE));
    EsManagedProcess underTest = new EsManagedProcess(mock(Process.class), ProcessId.ELASTICSEARCH, esConnector, WAIT_FOR_UP_TIMEOUT);
    assertThat(underTest.isOperational()).isFalse();
    assertThat(memoryAppender.events).isNotEmpty();
    assertThat(memoryAppender.events).extracting(ILoggingEvent::getLevel, ILoggingEvent::getMessage).containsOnlyOnce(tuple(Level.INFO, "Elasticsearch is waiting for a master to be elected. Did you start all the search nodes ?"));
    // Second call must not log another message
    assertThat(underTest.isOperational()).isFalse();
    assertThat(memoryAppender.events).extracting(ILoggingEvent::getLevel, ILoggingEvent::getMessage).containsOnlyOnce(tuple(Level.INFO, "Elasticsearch is waiting for a master to be elected. Did you start all the search nodes ?"));
}
Also used : EsConnector(org.sonar.application.es.EsConnector) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) Test(org.junit.Test)

Example 2 with EsConnector

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

the class EsManagedProcessTest method isOperational_should_return_true_if_Elasticsearch_is_YELLOW.

@Test
public void isOperational_should_return_true_if_Elasticsearch_is_YELLOW() {
    EsConnector esConnector = mock(EsConnector.class);
    when(esConnector.getClusterHealthStatus()).thenReturn(Optional.of(ClusterHealthStatus.YELLOW));
    EsManagedProcess underTest = new EsManagedProcess(mock(Process.class), ProcessId.ELASTICSEARCH, esConnector, WAIT_FOR_UP_TIMEOUT);
    assertThat(underTest.isOperational()).isTrue();
}
Also used : EsConnector(org.sonar.application.es.EsConnector) Test(org.junit.Test)

Example 3 with EsConnector

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

the class EsManagedProcessTest method isOperational_should_return_true_if_Elasticsearch_was_GREEN_once.

@Test
public void isOperational_should_return_true_if_Elasticsearch_was_GREEN_once() {
    EsConnector esConnector = mock(EsConnector.class);
    when(esConnector.getClusterHealthStatus()).thenReturn(Optional.of(ClusterHealthStatus.GREEN));
    EsManagedProcess underTest = new EsManagedProcess(mock(Process.class), ProcessId.ELASTICSEARCH, esConnector, WAIT_FOR_UP_TIMEOUT);
    assertThat(underTest.isOperational()).isTrue();
    when(esConnector.getClusterHealthStatus()).thenReturn(Optional.of(ClusterHealthStatus.RED));
    assertThat(underTest.isOperational()).isTrue();
}
Also used : EsConnector(org.sonar.application.es.EsConnector) Test(org.junit.Test)

Example 4 with EsConnector

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

the class EsManagedProcessTest method isOperational_should_return_false_if_Elasticsearch_is_RED.

@Test
public void isOperational_should_return_false_if_Elasticsearch_is_RED() {
    EsConnector esConnector = mock(EsConnector.class);
    when(esConnector.getClusterHealthStatus()).thenReturn(Optional.of(ClusterHealthStatus.RED));
    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) Test(org.junit.Test)

Example 5 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_timeout_thrown.

@Test
public void isOperational_should_return_false_if_ElasticsearchException_with_connection_timeout_thrown() {
    EsConnector esConnector = mock(EsConnector.class);
    when(esConnector.getClusterHealthStatus()).thenThrow(new ElasticsearchException(new ExecutionException(new ConnectException("Timeout connecting to [/127.0.0.1:9001]"))));
    EsManagedProcess underTest = new EsManagedProcess(mock(Process.class), ProcessId.ELASTICSEARCH, esConnector, WAIT_FOR_UP_TIMEOUT_LONG);
    assertThat(underTest.isOperational()).isFalse();
}
Also used : EsConnector(org.sonar.application.es.EsConnector) ElasticsearchException(org.elasticsearch.ElasticsearchException) ExecutionException(java.util.concurrent.ExecutionException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

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