PerformanceCachingGoogleCloudStorage extends ForwardingGoogleCloudStorage { @Override public List<String> listObjectNames(String bucketName, String objectNamePrefix) throws IOException { return this.listObjectNames(bucketName, objectNamePrefix, ListObjectOptions.DEFAULT); } PerformanceCachingGoogleCloudStorage(
      GoogleCloudStorage delegate, PerformanceCachingGoogleCloudStorageOptions options); @VisibleForTesting  PerformanceCachingGoogleCloudStorage(
      GoogleCloudStorage delegate,
      PrefixMappedItemCache cache); @Override WritableByteChannel create(StorageResourceId resourceId); @Override void deleteBuckets(List<String> bucketNames); @Override void deleteObjects(List<StorageResourceId> resourceIds); @Override List<GoogleCloudStorageItemInfo> listBucketInfo(); @Override List<String> listObjectNames(String bucketName, String objectNamePrefix); @Override List<String> listObjectNames(
      String bucketName, String objectNamePrefix, ListObjectOptions listOptions); @Override List<GoogleCloudStorageItemInfo> listObjectInfo(String bucketName, String objectNamePrefix); @Override List<GoogleCloudStorageItemInfo> listObjectInfo(
      String bucketName, String objectNamePrefix, ListObjectOptions listOptions); @Override ListPage<GoogleCloudStorageItemInfo> listObjectInfoPage(
      String bucketName, String objectNamePrefix, ListObjectOptions listOptions, String pageToken); @Override GoogleCloudStorageItemInfo getItemInfo(StorageResourceId resourceId); @Override List<GoogleCloudStorageItemInfo> getItemInfos(List<StorageResourceId> resourceIds); @Override List<GoogleCloudStorageItemInfo> updateItems(List<UpdatableItemInfo> itemInfoList); @Override void close(); @Override GoogleCloudStorageItemInfo composeObjects(
      List<StorageResourceId> sources, StorageResourceId destination, CreateObjectOptions options); @VisibleForTesting void invalidateCache();  }
@Test public void testListObjectNames_delimiter() throws IOException { GoogleCloudStorageItemInfo itemAAPrefix = createInferredDirectory(BUCKET_A, PREFIX_A + "/"); List<String> expectedResult = Lists.newArrayList(ITEM_A_A.getObjectName(), itemAAPrefix.getObjectName()); List<GoogleCloudStorageItemInfo> expectedCached = Lists.newArrayList(ITEM_A_A, itemAAPrefix); List<String> result = gcs.listObjectNames(BUCKET_A, PREFIX_A, ListObjectOptions.DEFAULT); verify(gcsDelegate).listObjectNames(eq(BUCKET_A), eq(PREFIX_A), eq(ListObjectOptions.DEFAULT)); assertThat(result).containsExactlyElementsIn(expectedResult); assertThat(cache.getAllItemsRaw()).containsExactlyElementsIn(expectedCached); }
@Test public void testListObjectNames_prefixDir_delimiter() throws IOException { String prefixADir = PREFIX_A + "/"; String prefixABADir = PREFIX_ABA.substring(0, PREFIX_ABA.lastIndexOf('/') + 1); GoogleCloudStorageItemInfo itemABAPrefix = createInferredDirectory(BUCKET_A, prefixABADir); List<String> expectedResult = Lists.newArrayList(ITEM_A_AA.getObjectName(), itemABAPrefix.getObjectName()); List<GoogleCloudStorageItemInfo> expectedCached = Lists.newArrayList(ITEM_A_AA, itemABAPrefix); List<String> result = gcs.listObjectNames(BUCKET_A, prefixADir, ListObjectOptions.DEFAULT); verify(gcsDelegate) .listObjectNames(eq(BUCKET_A), eq(prefixADir), eq(ListObjectOptions.DEFAULT)); assertThat(result).containsExactlyElementsIn(expectedResult); assertThat(cache.getAllItemsRaw()).containsExactlyElementsIn(expectedCached); }
@Test public void testListObjectNamesAlt() throws IOException { List<String> expected = Lists.newArrayList(ITEM_B_A.getObjectName(), ITEM_B_B.getObjectName()); List<GoogleCloudStorageItemInfo> expectedCached = Lists.newArrayList(ITEM_B_A, ITEM_B_B); List<String> result = gcs.listObjectNames( BUCKET_B, null, ListObjectOptions.DEFAULT_FLAT_LIST); verify(gcsDelegate) .listObjectNames( eq(BUCKET_B), ArgumentMatchers.eq(null), ArgumentMatchers.eq(ListObjectOptions.DEFAULT_FLAT_LIST)); assertThat(result).containsExactlyElementsIn(expected); assertThat(cache.getAllItemsRaw()).containsExactlyElementsIn(expectedCached); }
@Test public void testListObjectNamesCached() throws IOException { List<String> expected = Lists.newArrayList( ITEM_A_A.getObjectName(), ITEM_A_AA.getObjectName(), ITEM_A_ABA.getObjectName(), ITEM_A_B.getObjectName()); List<GoogleCloudStorageItemInfo> expectedCached = Lists.newArrayList(ITEM_A_A, ITEM_A_AA, ITEM_A_ABA, ITEM_A_B); gcs.listObjectNames( BUCKET_A, null, ListObjectOptions.DEFAULT_FLAT_LIST); List<String> result = gcs.listObjectNames( BUCKET_A, null, ListObjectOptions.DEFAULT_FLAT_LIST); verify(gcsDelegate, times(2)) .listObjectNames( eq(BUCKET_A), ArgumentMatchers.eq(null), ArgumentMatchers.eq(ListObjectOptions.DEFAULT_FLAT_LIST)); assertThat(result).containsExactlyElementsIn(expected); assertThat(cache.getAllItemsRaw()).containsExactlyElementsIn(expectedCached); }