@Test
  public void testContainerStorageStats() throws Exception {
    short containerId = 10;
    long logicalStorageUsage = 10000;
    long physicalStorageUsage = 20000;
    long numberOfBlobs = 100;
    ContainerStorageStats stats =
        new ContainerStorageStats.Builder(containerId).logicalStorageUsage(logicalStorageUsage)
            .physicalStorageUsage(physicalStorageUsage)
            .numberOfBlobs(numberOfBlobs)
            .build();
    assertContainerStorageStats(stats, containerId, logicalStorageUsage, physicalStorageUsage, numberOfBlobs);

    String serialized = objectMapper.writeValueAsString(stats);
    Map<String, Object> tempMap = objectMapper.readValue(serialized, new TypeReference<Map<String, Object>>() {
    });
    // We are only expecting "containerId", "logicalStorageUsage", "physicalStorageUsage" and "numberOfBlobs" in the serialized string
    Assert.assertEquals(4, tempMap.size());
    for (String key : new String[]{"containerId", "logicalStorageUsage", "physicalStorageUsage", "numberOfBlobs"}) {
      Assert.assertTrue(tempMap.containsKey(key));
    }
    ContainerStorageStats deserialized = objectMapper.readValue(serialized, ContainerStorageStats.class);
    Assert.assertEquals(stats, deserialized);

    ContainerStorageStats newStats = stats.add(deserialized);
    assertContainerStorageStats(stats, containerId, logicalStorageUsage, physicalStorageUsage, numberOfBlobs);
    assertContainerStorageStats(newStats, containerId, 2 * logicalStorageUsage, 2 * physicalStorageUsage,
        2 * numberOfBlobs);

    serialized = "{`logicalStorageUsage`:1234, `physicalStorageUsage`:2345, `numberOfBlobs`: 12}".replace("`", "\"");
    try {
      objectMapper.readValue(serialized, ContainerStorageStats.class);
      Assert.fail("Missing container is should fail deserialization");
    } catch (Exception e) {
      Assert.assertTrue(e.getCause() instanceof IllegalStateException);
    }
  }
Test methods in {@link ContainerStorageStats}.
@throws Exception
ambry-api/src/test/java/com/github/ambry/server/StorageStatsTest.java