Hey, you might want to read: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/testing-framework.html
should help you to create tests which have a whole elasticsearch cluster running in the background. --Alex On Thu, Feb 13, 2014 at 7:37 PM, joergpra...@gmail.com < joergpra...@gmail.com> wrote: > I admit the code is confusing and too short, sorry. > > What you want is just exactly what I do. > > I start a test elasticsearch test cluster by doing this > > > @BeforeMethod > public void create() throws Exception { > startNode("1"); > NodesInfoRequest nodesInfoRequest = new > NodesInfoRequest().transport(true); > NodesInfoResponse response = > client("1").admin().cluster().nodesInfo(nodesInfoRequest).actionGet(); > InetSocketTransportAddress address = > (InetSocketTransportAddress)response.iterator().next() > .getTransport().getAddress().publishAddress(); > PORT = address.address().getPort(); > addresses.put("1", address); > .... > } > > ... > > protected URI getAddress() { > return URI.create("es://localhost:" + PORT + "?es.cluster.name=" > + CLUSTER); > } > > > and now I can tell a TransportClient to use the server. For this I keep a > map of adresses of the server nodes in form of an URI. > > Look at this code, which is trivially extending the abstract test code > > @Test > public void testBulkClient() { > final BulkClient es = new BulkClient() > .newClient(getAddress()); > es.shutdown(); > if (es.hasErrors()) { > logger.error("error", es.getThrowable()); > } > assertFalse(es.hasErrors()); > } > > I use "getAddress()" for the address of the elasticseach test cluster that > is currently running, and the "BulkClient" (which is my custom client > wrapping a TransportClient together with a BulkProcessor) is connecting to > the embedded test cluster with "newClient(...)". In this method I build a > Settings object that contains all the required info for the TransportClient > to connect. > > The Setting object is something like > > settingsBuilder() > .put("cluster.name", findClusterName(uri)) > .put("network.server", false) > .put("node.client", true) > .put("client.transport.sniff", false) > .put("client.transport.ignore_cluster_name", false) > .put("client.transport.ping_timeout", "30s") > .put("client.transport.nodes_sampler_interval", "30s") > .build(); > > where "findClusterName()" is a routine to get the cluster name from the > parameters of the test. > > The @AfterMethod shuts everything down, the "BulkClient" and the test > cluster. > > If i want more nodes, I add "startNode("2")", "startNode("3")", to the > @BeforeMethod > > Does this help? > > Jörg > > > -- > You received this message because you are subscribed to the Google Groups > "elasticsearch" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to elasticsearch+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEL2w5kJby8PddkvHRdZNtAima3E1vAaEYOW%3D3mQN2_og%40mail.gmail.com > . > > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9J7g23LTiDwci6xu5wcTKyTMxpsCancLLdjdKteur6tw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.