private void checkSystemMetadataAndPutIfPresentReplaceStrategy(AtmosObject object)
     throws Exception {
   long time = System.currentTimeMillis();
   boolean update = true;
   try {
     connection.getSystemMetadata(privateDirectory + "/object");
   } catch (KeyNotFoundException ex) {
     update = false;
   }
   try {
     if (update) connection.updateFile(privateDirectory, object);
     else connection.createFile(privateDirectory, object);
     System.err.printf(
         "%s %s; %dms%n",
         update ? "updated" : "created",
         object.getData() instanceof InputStream ? "stream" : "string",
         System.currentTimeMillis() - time);
   } catch (Exception e) {
     String message =
         (e.getCause().getCause() != null)
             ? e.getCause().getCause().getMessage()
             : e.getCause().getMessage();
     System.err.printf(
         "failure %s %s; %dms: [%s]%n",
         update ? "updating" : "creating",
         object.getData() instanceof InputStream ? "stream" : "string",
         System.currentTimeMillis() - time,
         message);
     throw e;
   }
 }
 private void deleteImmediateAndVerifyWithHead(final String path)
     throws InterruptedException, ExecutionException, TimeoutException {
   try {
     connection.deletePath(path);
   } catch (KeyNotFoundException ex) {
   }
   assert !connection.pathExists(path);
 }
 private static void verifyHeadObject(
     AtmosStorageClient connection, String path, String metadataValue)
     throws InterruptedException, ExecutionException, TimeoutException, IOException {
   AtmosObject getBlob = connection.headFile(path);
   assertEquals(IOUtils.toString((InputStream) getBlob.getData()), "");
   verifyMetadata(metadataValue, getBlob);
 }
 @Test(timeOut = 5 * 60 * 1000)
 public void testCreateDirectory() throws Exception {
   boolean created = false;
   while (!created) {
     privateDirectory = containerPrefix + new SecureRandom().nextInt();
     try {
       created = connection.createDirectory(privateDirectory) != null;
     } catch (UndeclaredThrowableException e) {
       HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
       if (htpe.getResponse().getStatusCode() == 409) continue;
       throw e;
     }
   }
   BoundedSortedSet<? extends DirectoryEntry> response = connection.listDirectories();
   for (DirectoryEntry id : response) {
     BoundedSortedSet<? extends DirectoryEntry> r2 = connection.listDirectory(id.getObjectName());
     assert r2 != null;
   }
 }
 private void createOrReplaceObject(String name, Object data, String metadataValue)
     throws Exception {
   // Test PUT with string data, ETag hash, and a piece of metadata
   AtmosObject object = connection.newObject();
   object.getContentMetadata().setName(name);
   object.setData(data);
   object.getContentMetadata().setContentLength(16);
   object.generateMD5();
   object.getContentMetadata().setContentType("text/plain");
   object.getUserMetadata().getMetadata().put("Metadata", metadataValue);
   replaceObject(object);
 }
 protected void deleteConsistencyAware(final String path)
     throws InterruptedException, ExecutionException, TimeoutException {
   try {
     connection.deletePath(path);
   } catch (KeyNotFoundException ex) {
   }
   assert Utils.enventuallyTrue(
       new Supplier<Boolean>() {
         public Boolean get() {
           return !connection.pathExists(path);
         }
       },
       INCONSISTENCY_WINDOW);
 }
  @BeforeGroups(groups = {"live"})
  public void setupClient() throws InterruptedException, ExecutionException, TimeoutException {
    String uid = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
    String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");

    RestContext<AtmosStorageAsyncClient, AtmosStorageClient> context =
        new AtmosStorageContextBuilder(new AtmosStoragePropertiesBuilder(uid, key).build())
            .withModules(new Log4JLoggingModule())
            .buildContext();
    connection = context.getApi();
    ClearContainerStrategy clearer = new RecursiveRemove(context.getAsyncApi(), connection);
    for (DirectoryEntry entry : connection.listDirectories()) {
      if (entry.getObjectName().startsWith(containerPrefix)) {
        clearer.execute(entry.getObjectName());
        deleteConfirmed(entry.getObjectName());
      }
    }
  }
  @Test(
      timeOut = 5 * 60 * 1000,
      dependsOnMethods = {"testCreateDirectory"})
  public void testListOptions() throws Exception {
    createOrReplaceObject("object2", "here is my data!", "meta-value1");
    createOrReplaceObject("object3", "here is my data!", "meta-value1");
    createOrReplaceObject("object4", "here is my data!", "meta-value1");
    BoundedSortedSet<? extends DirectoryEntry> r2 =
        connection.listDirectory(privateDirectory, ListOptions.Builder.limit(1));
    // test bug exists:
    assertEquals(r2.size(), 3);
    // assertEquals(r2.size(), 1);
    // assert r2.getToken() != null;
    // assertEquals(r2.last().getObjectName(),"object2");
    // r2 = connection.listDirectory(privateDirectory,
    // ListOptions.Builder.token(r2.getToken())).get(10,
    // TimeUnit.SECONDS);
    // assertEquals(r2.size(), 2);
    // assert r2.getToken() == null;
    // assertEquals(r2.last().getObjectName(),"object4");

  }
 private void alwaysDeleteFirstReplaceStrategy(AtmosObject object) throws Exception {
   deleteConfirmed(privateDirectory + "/" + object.getContentMetadata().getName());
   long time = System.currentTimeMillis();
   try {
     connection.createFile(privateDirectory, object);
     System.err.printf(
         "%s %s; %dms%n",
         "created",
         object.getData() instanceof InputStream ? "stream" : "string",
         System.currentTimeMillis() - time);
   } catch (Exception e) {
     String message =
         (e.getCause().getCause() != null)
             ? e.getCause().getCause().getMessage()
             : e.getCause().getMessage();
     System.err.printf(
         "failure %s %s; %dms: [%s]%n",
         "creating",
         object.getData() instanceof InputStream ? "stream" : "string",
         System.currentTimeMillis() - time,
         message);
     throw e;
   }
 }
 @Test
 public void testListDirectorys() throws Exception {
   BoundedSortedSet<? extends DirectoryEntry> response = connection.listDirectories();
   assert null != response;
 }