package org.influxdb;

import okhttp3.OkHttpClient;
import org.influxdb.dto.Pong;

import java.io.IOException;
import java.util.Map;

public class TestUtils {

    public static String getInfluxURL() {
        String ip = "http://127.0.0.1:8086";

        Map<String, String> getenv = System.getenv();
        if (getenv.containsKey("INFLUXDB_API_URL")) {
            ip = getenv.get("INFLUXDB_API_URL");
        }
        return ip;
    }
    
    
    public static String getRandomMeasurement() {
        return "measurement_" + System.nanoTime();
    }
    
    public static String defaultRetentionPolicy(String version) {
        if (version.startsWith("0.")) {
            return "default";
        } else {
            return "autogen";
        }
    }

  public static InfluxDB connectToInfluxDB() throws InterruptedException, IOException {
    return connectToInfluxDB(null);
  }

	public static InfluxDB connectToInfluxDB( final OkHttpClient.Builder client) throws InterruptedException, IOException {
    OkHttpClient.Builder clientToUse;
    if (client == null) {
      clientToUse = new OkHttpClient.Builder();
    } else {
      clientToUse = client;
    }
    InfluxDB influxDB = InfluxDBFactory.connect(
            "http://" + TestUtils.getInfluxIP() + ":" + TestUtils.getInfluxPORT(true),
            "admin", "admin", clientToUse);
    boolean influxDBstarted = false;
    do {
      Pong response;
      try {
        response = influxDB.ping();
        if (response.isGood()) {
          influxDBstarted = true;
        }
      } catch (Exception e) {
        // NOOP intentional
        e.printStackTrace();
      }
      Thread.sleep(100L);
    } while (!influxDBstarted);
    influxDB.setLogLevel(InfluxDB.LogLevel.NONE);
    System.out.println("##################################################################################");
    System.out.println("#  Connected to InfluxDB Version: " + influxDB.version() + " #");
    System.out.println("##################################################################################");
    return influxDB;
  }
}

@@ -104,16 +104,76 @@
 eption;%0A
+import java.net.MalformedURLException;%0Aimport java.net.URL;%0A
 import j
@@ -213,18 +213,16 @@
 tils %7B%0A%0A
-  
   public
@@ -496,24 +496,778 @@
  %7D%0A    %0A    
+public static String getInfluxHost() %7B%0A      URL url;%0A      try %7B%0A        url = new URL(getInfluxURL());%0A      %7D catch (MalformedURLException e) %7B%0A        return null;%0A      %7D%0A      return url.getHost();%0A    %7D%0A%0A    public static String getInfluxPORT(boolean apiPort) %7B%0A      if(apiPort) %7B   %0A        URL url;%0A        try %7B%0A          url = new URL(getInfluxURL());%0A        %7D catch (MalformedURLException e) %7B%0A          return null;%0A        %7D%0A        return Integer.toString(url.getPort());%0A      %7D%0A      else %7B%0A        Map%3CString, String%3E getenv = System.getenv();%0A        String port = %228096%22;%0A        if (getenv.containsKey(%22INFLUXDB_PORT_COLLECTD%22)) %7B%0A          port = getenv.get(%22INFLUXDB_PORT_COLLECTD%22);%0A        %7D%0A        return port;%0A      %7D%0A    %7D%0A
 %0A    public 
@@ -2028,107 +2028,23 @@
 ect(
-%0A            %22http://%22 + TestUtils.getInfluxIP() + %22:%22 + TestUtils.getInfluxPORT(true),%0A           
+getInfluxURL(),
  %22ad

fix compilation failed