All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lordofthejars.nosqlunit.elasticsearch2.LowLevelElasticSearchOperations Maven / Gradle / Ivy

The newest version!
package com.lordofthejars.nosqlunit.elasticsearch2;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

public class LowLevelElasticSearchOperations {
	private static final int NUM_RETRIES_TO_CHECK_SERVER_UP = 3;

	public boolean assertThatConnectionToElasticsearchIsPossible(String host, int port) throws InterruptedException {
		final InetSocketAddress address = new InetSocketAddress(host, port);

		try (TransportClient transportClient = TransportClient.builder().build()) {
			transportClient.addTransportAddress(new InetSocketTransportAddress(address));
			for (int i = 0; i < NUM_RETRIES_TO_CHECK_SERVER_UP; i++) {
				try {
					transportClient.admin().cluster().prepareState().execute().actionGet();
					return true;
				} catch (Exception e) {
					TimeUnit.SECONDS.sleep(7);
				}
			}
		}

		return false;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy