ElasticsearchConnectionManager implements ElasticsearchClientResolver, ElasticsearchConfigurationObserver { public void addElasticsearchConnection( ElasticsearchConnection elasticsearchConnection) { String connectionId = elasticsearchConnection.getConnectionId(); if (connectionId == null) { if (_log.isWarnEnabled()) { _log.warn("Skipping connection because connection ID is null"); } return; } if (elasticsearchConnection.isActive()) { try { elasticsearchConnection.connect(); } catch (RuntimeException runtimeException) { if (connectionId.equals( ConnectionConstants.SIDECAR_CONNECTION_ID)) { _log.error( StringBundler.concat( "Elasticsearch sidecar could not be started. ", "Search will be unavailable. Manual installation ", "of Elasticsearch and activation of remote mode ", "is recommended."), runtimeException); } throw runtimeException; } } _elasticsearchConnections.put(connectionId, elasticsearchConnection); }  void addElasticsearchConnection(
		ElasticsearchConnection elasticsearchConnection); @Override int compareTo(
		ElasticsearchConfigurationObserver elasticsearchConfigurationObserver); ElasticsearchConnection getElasticsearchConnection(); ElasticsearchConnection getElasticsearchConnection(
		boolean preferLocalCluster); ElasticsearchConnection getElasticsearchConnection(
		String connectionId); String getLocalClusterConnectionId(); @Override int getPriority(); @Override RestHighLevelClient getRestHighLevelClient(); @Override RestHighLevelClient getRestHighLevelClient(String connectionId); @Override RestHighLevelClient getRestHighLevelClient(
		String connectionId, boolean preferLocalCluster); boolean isCrossClusterReplicationEnabled(); @Override void onElasticsearchConfigurationUpdate(); void removeElasticsearchConnection(String connectionId);  }
@Test public void testAddConnectionNoConnectionIdAndIsActive() { ElasticsearchConnection elasticsearchConnection = Mockito.mock( ElasticsearchConnection.class); Mockito.when( elasticsearchConnection.getConnectionId() ).thenReturn( null ); Mockito.when( elasticsearchConnection.isActive() ).thenReturn( true ); _elasticsearchConnectionManager.addElasticsearchConnection( elasticsearchConnection); Mockito.verify( elasticsearchConnection, Mockito.never() ).isActive(); Mockito.verify( elasticsearchConnection, Mockito.never() ).connect(); }
@Test public void testAddConnectionNoConnectionIdAndIsNotActive() { ElasticsearchConnection elasticsearchConnection = Mockito.mock( ElasticsearchConnection.class); Mockito.when( elasticsearchConnection.getConnectionId() ).thenReturn( null ); Mockito.when( elasticsearchConnection.isActive() ).thenReturn( false ); _elasticsearchConnectionManager.addElasticsearchConnection( elasticsearchConnection); Mockito.verify( elasticsearchConnection, Mockito.never() ).isActive(); Mockito.verify( elasticsearchConnection, Mockito.never() ).connect(); }
@Test public void testAddConnectionWithConnectionIdAndIsActive() { ElasticsearchConnection elasticsearchConnection = Mockito.mock( ElasticsearchConnection.class); Mockito.when( elasticsearchConnection.getConnectionId() ).thenReturn( "test" ); Mockito.when( elasticsearchConnection.isActive() ).thenReturn( true ); _elasticsearchConnectionManager.addElasticsearchConnection( elasticsearchConnection); Mockito.verify( elasticsearchConnection ).isActive(); Mockito.verify( elasticsearchConnection ).connect(); }
@Test public void testAddConnectionWithConnectionIdAndIsNotActive() { ElasticsearchConnection elasticsearchConnection = Mockito.mock( ElasticsearchConnection.class); Mockito.when( elasticsearchConnection.getConnectionId() ).thenReturn( "test" ); Mockito.when( elasticsearchConnection.isActive() ).thenReturn( false ); _elasticsearchConnectionManager.addElasticsearchConnection( elasticsearchConnection); Mockito.verify( elasticsearchConnection ).isActive(); Mockito.verify( elasticsearchConnection, Mockito.never() ).connect(); }