@Test
public void testCachePolling() throws Exception {

  final CachingCounters counters = new CachingCounters();
  FakeDataSet fakeDataSet =
      new FakeDataSet()
          .newData("test_data")
          .appendReadData(TestUtil.buildTestData(100))
          .appendReadAction(() -> counters.assertValues(0, 100, 300))
          .appendReadData(TestUtil.buildTestData(100))
          .appendReadAction(() -> counters.assertValues(0, 200, 300))
          .appendReadData(TestUtil.buildTestData(100))
          .endData();
  FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
  CacheUtil.cache(
      new DataSpec(Uri.parse("test_data")),
      cache,
      /* cacheKeyFactory= */ null,
      dataSource,
      counters,
      /* isCanceled= */ null);
  counters.assertValues(0, 300, 300);
  assertCachedData(cache, fakeDataSet);
}