@Test
public void testExtractJsonResults() {

  Map<String, TopicWorkload> workloads = new HashMap<>();
  // full results
  C3QueryUtils.extractJsonResults(
      "{\"topic1\":[{\"endTimeSec\":1485991200,\"startTimeSec\":1485988200,\"totalBytes\":30000,\"totalCount\":3000}],"
          + "\"topic2\":[{\"endTimeSec\":1485991200,\"invalidCount\":0,\"maxLatencyFromCreation\":3750,\"meanLatencyFromCreation\":1576.2152157017917,\"p99LatencyFromCreation\":3529,\"startTimeSec\":1485988200,\"totalBytes\":3000000,\"totalCount\":1500}]}",
      Arrays.asList("topic1", "topic2"), workloads);
  TopicWorkload tw1 = workloads.get("topic1");
  Assert.assertEquals(tw1.getBytesPerSecond(), 10, 0.01);
  Assert.assertEquals(tw1.getMsgsPerSecond(), 1, 0.01);
  TopicWorkload tw2 = workloads.get("topic2");
  Assert.assertEquals(tw2.getBytesPerSecond(), 1000, 0.01);
  Assert.assertEquals(tw2.getMsgsPerSecond(), 0.5, 0.01);
  workloads.clear();
  // no result
  C3QueryUtils.extractJsonResults("", Arrays.asList("topic1", "topic2"), workloads);
  Assert.assertTrue(workloads.isEmpty());
  // no result
  C3QueryUtils.extractJsonResults("{}", Arrays.asList("topic1", "topic2"), workloads);
  Assert.assertTrue(workloads.isEmpty());
  // empty result
  C3QueryUtils.extractJsonResults("{\"topic1\":[]}", Arrays.asList("topic1", "topic2"), workloads);
  Assert.assertTrue(workloads.isEmpty());
  // missing partial result for one of the topics
  C3QueryUtils.extractJsonResults(
      "{\"topic1\":[{,\"startTimeSec\":1485988200,\"totalBytes\":30000,\"totalCount\":3000}],"
          + "\"topic2\":[{\"endTimeSec\":1485991200,\"invalidCount\":0,\"maxLatencyFromCreation\":3750,\"meanLatencyFromCreation\":1576.2152157017917,\"p99LatencyFromCreation\":3529,\"startTimeSec\":1485988200,\"totalBytes\":3000000,\"totalCount\":1500}]}",
      Arrays.asList("topic1", "topic2"), workloads);
  tw1 = workloads.get("topic1");
  Assert.assertNull(tw1);
  tw2 = workloads.get("topic2");
  Assert.assertEquals(tw2.getBytesPerSecond(), 1000, 0.01);
  Assert.assertEquals(tw2.getMsgsPerSecond(), 0.5, 0.01);
  workloads.clear();
  // invalid partial result for one of the topics
  C3QueryUtils.extractJsonResults(
      "{\"topic1\":[{\"endTimeSec\":1485988200,\"startTimeSec\":1485988200,\"totalBytes\":30000,\"totalCount\":3000}],"
          + "\"topic2\":[{\"endTimeSec\":1485991200,\"invalidCount\":0,\"maxLatencyFromCreation\":3750,\"meanLatencyFromCreation\":1576.2152157017917,\"p99LatencyFromCreation\":3529,\"startTimeSec\":1485988200,\"totalBytes\":3000000,\"totalCount\":1500}]}",
      Arrays.asList("topic1", "topic2"), workloads);
  tw1 = workloads.get("topic1");
  Assert.assertNull(tw1);
  tw2 = workloads.get("topic2");
  Assert.assertEquals(tw2.getBytesPerSecond(), 1000, 0.01);
  Assert.assertEquals(tw2.getMsgsPerSecond(), 0.5, 0.01);
  workloads.clear();
}