Package org.jclouds.blobstore.options

Examples of org.jclouds.blobstore.options.ListContainerOptions


      throw new UnsupportedOperationException();
   }

   public ListenableFuture<PageSet<ObjectInfo>> listObjects(String container,
            org.jclouds.openstack.swift.options.ListContainerOptions... optionsList) {
      ListContainerOptions options = container2ContainerListOptions.apply(optionsList);
      return transform(blobStore.list(container, options), resource2ObjectList, userExecutor);
   }


                        PageSet<? extends StorageMetadata> list;
                        if (eager && marker == null) {
                           list = firstList;
                           marker = firstMarker;
                        } else {
                           ListContainerOptions nextOptions = marker == null ? containerOptions : containerOptions.clone().afterMarker(marker);
                           list = blobStore.list(container, nextOptions);
                           marker = list.getNextMarker();
                        }
                        iterator = list.iterator();
                     }

*/
@Singleton
public class ListBlobsOptionsToListOptions implements
         Function<ListBlobsOptions[], ListContainerOptions> {
   public ListContainerOptions apply(ListBlobsOptions[] optionsList) {
      ListContainerOptions options = new ListContainerOptions();
      if (optionsList.length != 0) {
         if (optionsList[0].getDelimiter() == null) {
            options.recursive();
         } else if (!optionsList[0].getDelimiter().equals("/")) {
            throw new IllegalArgumentException("only '/' is allowed as a blobstore delimiter");
         }
         if (optionsList[0].getMarker() != null) {
            options.afterMarker(optionsList[0].getMarker());
         }
         if (optionsList[0].getMaxResults() != null) {
            options.maxResults(optionsList[0].getMaxResults());
         }
         if (optionsList[0].getPrefix() != null) {
            options.inDirectory(optionsList[0].getPrefix());
         }
         if (optionsList[0].getIncludeMetadata()) {
            options.withDetails();
         }
      }
      return options;
   }

    private void checkForContainerContent(final String containerName, Set<String> expectedBlobKeys) {
        checkForContainerContent(containerName, null, expectedBlobKeys);
    }

    private void checkForContainerContent(final String containerName, String inDirectory, Set<String> expectedBlobKeys) {
        ListContainerOptions options = ListContainerOptions.Builder.recursive();
        if (null != inDirectory && !"".equals(inDirectory))
            options.inDirectory(inDirectory);

        PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options);
        for (Iterator<? extends StorageMetadata> it = blobsRetrieved.iterator(); it.hasNext();) {
           // TODO: FluentIterable
           if (it.next().getType() != StorageType.BLOB) {

   private final String containerName = "mycontainer";

   @Test(expectedExceptions = { ContainerNotFoundException.class })
   public void testListAllForUnknownContainerFromTransientBlobStoreEagerly() throws Exception {
      ListContainerOptions containerOptions = ListContainerOptions.NONE;
      ListAllOptions listAllOptions = ListAllOptions.Builder.eager(true);
      BlobStoreContext context = blobStoreContext();
      try {
         BlobStore blobStore = context.getBlobStore();
         BlobStores.listAll(blobStore, "wrongcontainer", containerOptions, listAllOptions);

   /**
    * Default listAll is not eager, so test that exception is thrown when first attempt to iterate.
    */
   @Test(expectedExceptions = { ContainerNotFoundException.class })
   public void testListAllForUnknownContainerFromTransientBlobStore() throws Exception {
      ListContainerOptions options = ListContainerOptions.NONE;
      BlobStoreContext context = blobStoreContext();
      try {
         BlobStore blobStore = context.getBlobStore();
         Iterable<StorageMetadata> iterable = BlobStores.listAll(blobStore, "wrongcontainer", options);
         iterable.iterator().hasNext();

   }

   private void runListAllFromTransientBlobStore(boolean eager) throws Exception {
      final int numTimesToIterate = 2;
      final int NUM_BLOBS = 31;
      ListContainerOptions containerOptions = ListContainerOptions.Builder.maxResults(10);
      BlobStoreContext context = blobStoreContext();
      BlobStore blobStore = null;
      try {
         blobStore = context.getBlobStore();
         blobStore.createContainerInLocation(null, containerName);

   }

   @Test
   public void testListAllWhenOnePage() throws Exception {
      BlobStore blobStore = createMock(BlobStore.class);
      ListContainerOptions options = ListContainerOptions.NONE;
      StorageMetadata v1 = createMock(StorageMetadata.class);
      PageSet<StorageMetadata> pageSet = new PageSetImpl<StorageMetadata>(ImmutableList.of(v1), null);

      EasyMock.<PageSet<? extends StorageMetadata>> expect(blobStore.list(containerName, options)).andReturn(pageSet)
               .once();

   }

   @Test
   public void testListAllWhenTwoPages() throws Exception {
      BlobStore blobStore = createMock(BlobStore.class);
      ListContainerOptions options = ListContainerOptions.NONE;
      ListContainerOptions options2 = ListContainerOptions.Builder.afterMarker("marker1");
      StorageMetadata v1 = createMock(StorageMetadata.class);
      StorageMetadata v2 = createMock(StorageMetadata.class);
      PageSet<StorageMetadata> pageSet = new PageSetImpl<StorageMetadata>(ImmutableList.of(v1), "marker1");
      PageSet<StorageMetadata> pageSet2 = new PageSetImpl<StorageMetadata>(ImmutableList.of(v2), null);

   public void testLargerThanOnePageNoOptions() {
      blobstore.createContainerInLocation(null, "goodies");
      for (int i = 0; i < 1001; i++) {
         blobstore.putBlob("goodies", blobstore.blobBuilder(i + "").payload(i + "").build());
      }
      Iterable<? extends StorageMetadata> listing = concatter.execute("goodies", new ListContainerOptions());
      assertEquals(Iterables.size(listing), 1001);
   }

TOP

Related Classes of org.jclouds.blobstore.options.ListContainerOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.