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