@Test
public void testGetDataForXRange() {

  myTransportService.setAgentStatus(DEFAULT_AGENT_ATTACHED_RESPONSE);
  StudioProfilers studioProfilers =
    new StudioProfilers(new ProfilerClient(myGrpcChannel.getName()), myIdeProfilerServices, myTimer);
  studioProfilers.setPreferredProcess(FAKE_DEVICE_NAME, FAKE_PROCESS_NAME, null);
  myTimer.tick(TimeUnit.SECONDS.toNanos(1));
  MemoryAllocStatsData stats1 = MemoryAllocStatsData.newBuilder().setJavaAllocationCount(1000).setJavaFreeCount(2000).build();
  MemoryAllocStatsData stats2 = MemoryAllocStatsData.newBuilder().setJavaAllocationCount(1500).setJavaFreeCount(2500).build();
  long timestamp1 = TimeUnit.MICROSECONDS.toNanos(3);
  long timestamp2 = TimeUnit.MICROSECONDS.toNanos(14);
  if (myNewDataPipeline) {
    myTransportService.addEventToStream(FakeTransportService.FAKE_DEVICE_ID, Common.Event.newBuilder()
      .setPid(FakeTransportService.FAKE_PROCESS.getPid())
      .setTimestamp(timestamp1)
      .setKind(Common.Event.Kind.MEMORY_ALLOC_STATS)
      .setMemoryAllocStats(stats1)
      .build());
    myTransportService.addEventToStream(FakeTransportService.FAKE_DEVICE_ID, Common.Event.newBuilder()
      .setPid(FakeTransportService.FAKE_PROCESS.getPid())
      .setTimestamp(timestamp2)
      .setKind(Common.Event.Kind.MEMORY_ALLOC_STATS)
      .setMemoryAllocStats(stats2)
      .build());
  }
  else {
    MemoryData memoryData = MemoryData.newBuilder()
      .setEndTimestamp(1)
      .addAllocStatsSamples(
        MemoryData.AllocStatsSample.newBuilder().setTimestamp(TimeUnit.MICROSECONDS.toNanos(3)).setAllocStats(stats1))
      .addAllocStatsSamples(
        MemoryData.AllocStatsSample.newBuilder().setTimestamp(TimeUnit.MICROSECONDS.toNanos(14)).setAllocStats(stats2))
      .build();
    myService.setMemoryData(memoryData);
  }
  AllocStatsDataSeries series =
    new AllocStatsDataSeries(studioProfilers,
                             sample -> (long)sample.getJavaAllocationCount());
  List<SeriesData<Long>> dataList = series.getDataForRange(new Range(0, Double.MAX_VALUE));
  assertEquals(2, dataList.size());
  assertEquals(3, dataList.get(0).x);
  assertEquals(1000, dataList.get(0).value.longValue());
  assertEquals(14, dataList.get(1).x);
  assertEquals(1500, dataList.get(1).value.longValue());
  series = new AllocStatsDataSeries(studioProfilers,
                                    sample -> (long)sample.getJavaFreeCount());
  dataList = series.getDataForRange(new Range(0, Double.MAX_VALUE));
  assertEquals(2, dataList.size());
  assertEquals(3, dataList.get(0).x);
  assertEquals(2000, dataList.get(0).value.longValue());
  assertEquals(14, dataList.get(1).x);
  assertEquals(2500, dataList.get(1).value.longValue());
}