Utils { public static long parseMemory(String memory) { if (memory.endsWith("g") || memory.endsWith("G")) { int executorGB = Integer.parseInt(memory.substring(0, memory.length() - 1)); return 1024L * 1024 * 1024 * executorGB; } else if (memory.endsWith("m") || memory.endsWith("M")) { int executorMB = Integer.parseInt(memory.substring(0, memory.length() - 1)); return 1024L * 1024 * executorMB; } else if (memory.endsWith("k") || memory.endsWith("K")) { int executorKB = Integer.parseInt(memory.substring(0, memory.length() - 1)); return 1024L * executorKB; } else if (memory.endsWith("t") || memory.endsWith("T")) { int executorTB = Integer.parseInt(memory.substring(0, memory.length() - 1)); return 1024L * 1024 * 1024 * 1024 * executorTB; } else if (memory.endsWith("p") || memory.endsWith("P")) { int executorPB = Integer.parseInt(memory.substring(0, memory.length() - 1)); return 1024L * 1024 * 1024 * 1024 * 1024 * executorPB; } LOG.warn("Cannot parse memory info " + memory); return 0L; }  static void closeInputStream(InputStream is); static void sleep(long seconds); static long dateTimeToLong(String date); static long parseMemory(String memory); static Constants.JobType fetchJobType(Map config); static Constants.JobType fetchJobType(Configuration config); static String makeLockPath(String zkrootWithSiteId);  }
@Test public void testParseMemory() { long mem = Utils.parseMemory(""); Assert.assertEquals(0l, mem); mem = Utils.parseMemory("1g"); Assert.assertEquals(1073741824l, mem); mem = Utils.parseMemory("1m"); Assert.assertEquals(1048576l, mem); mem = Utils.parseMemory("1k"); Assert.assertEquals(1024, mem); mem = Utils.parseMemory("1t"); Assert.assertEquals(1099511627776l, mem); mem = Utils.parseMemory("1p"); Assert.assertEquals(1125899906842624l, mem); mem = Utils.parseMemory("10000p"); Assert.assertEquals(-7187745005283311616l, mem); }
@Test public void testParseMemory1() { thrown.expect(IllegalArgumentException.class); Utils.parseMemory("0.1g"); }