StorageUtils { public static double parseMemory(String memory, String units) { return parseMemory(memory) / (double) memoryFactor(units); }  static double parseMemory(String memory, String units); static long parseMemory(Quantity size); static long parseMemory(String size); static boolean usesEphemeral(Storage storage);  }
@Test public void testSizeConversion() { assertThat(StorageUtils.parseMemory("100Gi"), is(100L * 1_024L * 1_024L * 1_024L)); assertThat(StorageUtils.parseMemory("100G"), is(100L * 1_000L * 1_000L * 1_000L)); assertThat(StorageUtils.parseMemory("100000Mi"), is(100_000L * 1_024L * 1_024L)); assertThat(StorageUtils.parseMemory("100000M"), is(100L * 1_000L * 1_000L * 1_000L)); assertThat(StorageUtils.parseMemory("100Ti"), is(100L * 1_024L * 1_024L * 1_024L * 1_024L)); assertThat(StorageUtils.parseMemory("100T"), is(100L * 1_000L * 1_000L * 1_000L * 1_000L)); assertThat(StorageUtils.parseMemory("100Pi"), is(100L * 1_024L * 1_024L * 1_024L * 1_024L * 1_024L)); assertThat(StorageUtils.parseMemory("100P"), is(100L * 1_000L * 1_000L * 1_000L * 1_000L * 1_000L)); assertThat(StorageUtils.parseMemory("100.5P"), is((long) (100.5 * 1_000L * 1_000L * 1_000L * 1_000L * 1_000L))); assertThat(StorageUtils.parseMemory("2.1e6"), is((long) (2.1 * 1_000L * 1_000L))); assertThat(StorageUtils.parseMemory("100Gi") == StorageUtils.parseMemory("100Gi"), is(true)); assertThat(StorageUtils.parseMemory("1000Gi") > StorageUtils.parseMemory("100Gi"), is(true)); assertThat(StorageUtils.parseMemory("1000000Mi") > StorageUtils.parseMemory("100Gi"), is(true)); assertThat(StorageUtils.parseMemory("100Pi") > StorageUtils.parseMemory("100Gi"), is(true)); assertThat(StorageUtils.parseMemory("1000G") == StorageUtils.parseMemory("1T"), is(true)); }
@Test public void testQuantityConversion() { assertThat(StorageUtils.parseMemory(new Quantity("1000G")), is(1_000L * 1_000L * 1_000L * 1_000L)); assertThat(StorageUtils.parseMemory(new Quantity("100Gi")), is(100L * 1_024L * 1_024L * 1_024L)); Quantity size = new Quantity("100", "Gi"); assertThat(StorageUtils.parseMemory(size), is(100L * 1_024L * 1_024L * 1_024L)); }