Node[] nodes = new Node[3];
for (int i = 0; i < nodes.length; i++) {
nodes[i] = NodeBuilder.nodeBuilder().node();
}
final TransportClient client = new TransportClient()
.addTransportAddress(new InetSocketTransportAddress("localhost", 9300))
.addTransportAddress(new InetSocketTransportAddress("localhost", 9301))
.addTransportAddress(new InetSocketTransportAddress("localhost", 9302));
final AtomicBoolean done = new AtomicBoolean();
final AtomicLong indexed = new AtomicLong();
final CountDownLatch latch = new CountDownLatch(1);
Thread indexer = new Thread(new Runnable() {
@Override public void run() {
while (!done.get()) {
try {
client.prepareIndex("test", "type").setSource("field", "value").execute().actionGet();
indexed.incrementAndGet();
} catch (Exception e) {
e.printStackTrace();
}
}
latch.countDown();
}
});
indexer.start();
for (int i = 0; i < 100; i++) {
int index = i % nodes.length;
nodes[index].close();
ClusterHealthResponse health = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
if (health.timedOut()) {
System.err.println("timed out on health");
}
nodes[index] = NodeBuilder.nodeBuilder().node();
health = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
if (health.timedOut()) {
System.err.println("timed out on health");
}
}