Util { public static String getMachineId() { if (machineId == null) { machineId = System.getProperty(HAWKULAR_AGENT_MACHINE_ID); if (machineId != null) { log.infof("Machine ID was explicitly set to [%s]", machineId); } } if (machineId == null) { File machineIdFile = new File("/etc/machine-id"); if (machineIdFile.exists() && machineIdFile.canRead()) { try (Reader reader = new InputStreamReader(new FileInputStream(machineIdFile))) { machineId = new BufferedReader(reader).lines().collect(Collectors.joining("\n")); } catch (IOException e) { log.warnf(e, "/etc/machine-id exists and is readable, but exception was raised when reading it"); machineId = ""; } } else { log.warnf("/etc/machine-id does not exist or is unreadable"); machineId = ""; } } return (machineId.isEmpty()) ? null : machineId; }  static String toJson(Object obj); static T fromJson(String json, Class<T> clazz); static T fromJson(Reader in, TypeReference<T> typeReference); static String urlEncode(String str); static String urlEncodeQuery(String str); static StringBuilder getContextUrlString(String baseUrl, String context); static void ensureEndsWithSlash(StringBuilder str); static long copyStream(InputStream input, OutputStream output, boolean closeStreams); static String slurpStream(InputStream input, String encoding); static String read(File file); static void write(String string, File file); static String base64Encode(String plainTextString); static String getMachineId(); static String getContainerId(); static String extractDockerContainerIdFromString(String s); static Properties extractPropertiesFromExpression(String expression);  }
@Test @Ignore("CI system has no /etc/machine-id . But this should work on Fedora/RHEL/CentOS boxes.") public void getSystemId() { Assert.assertNotNull(Util.getMachineId()); }