@Override
  public Map<String, Long> call() throws Exception {
    Map<String, Long> result = new LinkedHashMap<>();
    for (DownloadableItem item : items) {
      InputStreamWrapper stream = connectionProvider.getInputStreamForItem(jobId, item);
      long size = stream.getBytes();
      if (size <= 0) {
        size = computeSize(stream);
      }

      result.put(item.getIdempotentId(), size);
    }

    return result;
  }
@Test
  public void testSizeIsNotProvided() throws Exception {
    DownloadableItem item = createItem("1-" + nextInt(100, 9999));

    int size = nextInt(1, 1024 * 1024 * 42); // 42MB max
    byte[] bytes = new byte[size];
    Arrays.fill(bytes, (byte) 0);
    InputStream inputStream = new ByteArrayInputStream(bytes);
    when(connectionProvider.getInputStreamForItem(eq(jobId), eq(item)))
        .thenReturn(new InputStreamWrapper(inputStream, -1L));

    Map<String, Long> expected = Collections.singletonMap(item.getIdempotentId(), (long) size);

    Map<String, Long> actual = new CallableSizeCalculator(jobId, connectionProvider,
        Collections.singleton(item)).call();

    Truth.assertThat(actual).containsExactlyEntriesIn(expected);

    // Make sure the input stream was read in full
    int nextByte = inputStream.read();
    Truth.assertThat(nextByte).isEqualTo(-1);
  }