/** * Returns {@link StorageObjectOrIOException StorageObjectOrIOExceptions} for the given {@link * GcsPath GcsPaths}. */ public List<StorageObjectOrIOException> getObjects(List<GcsPath> gcsPaths) throws IOException { List<StorageObjectOrIOException[]> results = new ArrayList<>(); executeBatches(makeGetBatches(gcsPaths, results)); ImmutableList.Builder<StorageObjectOrIOException> ret = ImmutableList.builder(); for (StorageObjectOrIOException[] result : results) { ret.add(result[0]); } return ret.build(); }
@Test public void testMakeGetBatches() throws IOException { GcsUtil gcsUtil = gcsOptionsWithTestCredential().getGcsUtil(); // Small number of files fits in 1 batch List<StorageObjectOrIOException[]> results = Lists.newArrayList(); List<BatchRequest> batches = gcsUtil.makeGetBatches(makeGcsPaths("s", 3), results); assertThat(batches.size(), equalTo(1)); assertThat(sumBatchSizes(batches), equalTo(3)); assertEquals(3, results.size()); // 1 batch of files fits in 1 batch results = Lists.newArrayList(); batches = gcsUtil.makeGetBatches(makeGcsPaths("s", 100), results); assertThat(batches.size(), equalTo(1)); assertThat(sumBatchSizes(batches), equalTo(100)); assertEquals(100, results.size()); // A little more than 5 batches of files fits in 6 batches results = Lists.newArrayList(); batches = gcsUtil.makeGetBatches(makeGcsPaths("s", 501), results); assertThat(batches.size(), equalTo(6)); assertThat(sumBatchSizes(batches), equalTo(501)); assertEquals(501, results.size()); }