ConfigUtils { public static String getMd5(ConfigPayload payload) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { payload.serialize(baos, new JsonFormat(true)); } catch (IOException e) { throw new RuntimeException(e); } return getMd5(baos.toByteArray()); }  static String getMd5(ConfigPayload payload); static String getMd5(String input); static String getMd5(Utf8Array input); static String getMd5(byte[] input); static String stripSpaces(String str); static String getDefMd5(List<String> lines); static String getDefNamespace(Reader in); static Tuple2<String, String> getNameAndNamespaceFromString(String nameDotNamespace); static ConfigDefinitionKey createConfigDefinitionKeyFromZKString(String nodeName); static ConfigDefinitionKey createConfigDefinitionKeyFromDefFile(File file); static String escapeConfigFormatValue(String input); static String getDefMd5FromRequest(String defMd5, List<String> defContent); static String getCanonicalHostName(); static String getEnvValue(String defaultValue, String... envVars); static boolean isGenerationNewer(long newGen, long oldGen);  }
@Test public void testGetMd5WithComment() { String expectedMd5 = "4395db1dfbd977c4d74190d2d23396e2"; List<String> lines = new ArrayList<>(); lines.add("foo=\"1#hello\""); lines.add(""); assertThat(getMd5(lines), is(expectedMd5)); lines.clear(); lines.add("foo=\"1#hello and some more\""); String md5 = getMd5(lines); assertThat(md5, is(not(expectedMd5))); lines.add("foo=\"1#hello and some more and even more\""); assertThat(getMd5(lines), is(not(md5))); }
@Test public void testGetMd5OfPayload() { String expectedMd5 = "c9246ed8c8ab55b1c463c501c84075e6"; String expectedChangedMd5 = "f6f81062ef5f024f1912798490ba7dfc"; ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder())); System.out.println(payload); assertThat(ConfigUtils.getMd5(payload), is(expectedMd5)); payload.getSlime().get().setString("fabio", "bar"); System.out.println(payload); assertThat(ConfigUtils.getMd5(payload), is(expectedChangedMd5)); }
@Test public void testGetMd5OfString() { String expectedMd5 = "c9246ed8c8ab55b1c463c501c84075e6"; String expectedChangedMd5 = "f6f81062ef5f024f1912798490ba7dfc"; ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder())); System.out.println(payload); assertThat(ConfigUtils.getMd5(payload.toString(true)), is(expectedMd5)); payload.getSlime().get().setString("fabio", "bar"); System.out.println(payload); assertThat(ConfigUtils.getMd5(payload.toString(true)), is(expectedChangedMd5)); }