### Question:
NodeOrTransportBasedElasticSearchClientFactoryCreator implements ElasticSearchClientFactoryCreator { @Override public ElasticSearchClientFactory getElasticSearchClientConnectionFactory(Configuration configuration) { ElasticSearchClientFactory factory; switch(configuration.getElasticSearchClientType()) { case NODE: factory = new NodeBasedElasticSearchClientFactory(configuration); break; case TRANSPORT: factory = new TransportBasedElasticSearchClientFactory(configuration); break; default: factory = new TransportBasedElasticSearchClientFactory(configuration); break; } return factory; }  @Override ElasticSearchClientFactory getElasticSearchClientConnectionFactory(Configuration configuration); static final ElasticSearchClientFactoryCreator INSTANCE; }### Answer:
@Test public void testTransportBasedClientCanConnectToES() { esServer = new ElasticSearchServer(clusterName,true); assertTrue("Unable to start in memory elastic search", esServer.isSetup()); System.setProperty(ConfigurationConstants.PROPNAME_ELASTIC_SEARCH_TRANSPORT_HOSTS, "localhost:" + esServer.getPort()); System.setProperty(ConfigurationConstants.PROPNAME_ES_CLIENT_TYPE, "transport"); Configuration config = new SystemPropertiesConfiguration(); try { ElasticSearchClientFactory factory = clientFactoryCreator.getElasticSearchClientConnectionFactory(config); Client c = factory.getClient(); assertEquals(config.getStorageClusterName(), c.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getClusterName().value()); assertNotNull(c.index(new IndexRequest("test", "test").source("name", "a")).actionGet().getId()); c.admin().indices().refresh(new RefreshRequest("test").force(true)).actionGet(); assertEquals(1,c.admin().indices().stats(new IndicesStatsRequest().indices("test")).actionGet().getTotal().docs.getCount()); } catch(Exception e) { fail("Unable to connect to elasticsearch: " + e.getMessage()); } try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } }
@Test public void testNodeBasedClientCanConnectToES() { System.setProperty(ConfigurationConstants.PROPNAME_ES_CLIENT_TYPE, "node"); Configuration config = new SystemPropertiesConfiguration(); esServer = new ElasticSearchServer(clusterName,false); assertTrue("Unable to start in memory elastic search", esServer.isSetup()); try { ElasticSearchClientFactory factory = clientFactoryCreator.getElasticSearchClientConnectionFactory(config); Client c = factory.getClient(); assertEquals(config.getStorageClusterName(), c.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getClusterName().value()); assertNotNull(c.index(new IndexRequest("test", "test").source("name", "a")).actionGet().getId()); c.admin().indices().refresh(new RefreshRequest("test").force(true)).actionGet(); assertEquals(1, c.admin().indices().stats(new IndicesStatsRequest().indices("test")).actionGet().getTotal().docs.getCount()); } catch(Exception e) { e.printStackTrace(); fail("Unable to connect to elasticsearch: " + e.getMessage()); } }