TestHelpers.java

/*******************************************************************************
 * Copyright (c) 2019 Eclipse RDF4J contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Distribution License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *******************************************************************************/
package org.eclipse.rdf4j.sail.elasticsearchstore;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

public class TestHelpers {
	public static String CLUSTER = "test";
	public static int PORT = 9300;
	public static String HOST = "localhost";

	private static RestHighLevelClient CLIENT;

	public static synchronized void openClient() {
		if (CLIENT != null) {
			return;
		}

		ElasticsearchStoreTestContainerSupport.start();

		CLUSTER = ElasticsearchStoreTestContainerSupport.getClusterName();
		PORT = ElasticsearchStoreTestContainerSupport.getTransportPort();
		HOST = ElasticsearchStoreTestContainerSupport.getHost();

		CLIENT = new RestHighLevelClient(RestClient
				.builder(new HttpHost(HOST, ElasticsearchStoreTestContainerSupport.getHttpPort(), "http")));
	}

	public static RestHighLevelClient getClient() {
		return CLIENT;
	}

	public static void closeClient() throws IOException {
		if (CLIENT != null) {
			CLIENT.close();
			CLIENT = null;
		}
	}

}