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 static void verifyMetadata(String metadataValue, AtmosObject getBlob) {
    assertEquals(getBlob.getContentMetadata().getContentLength(), new Long(16));
    assert getBlob.getContentMetadata().getContentType().startsWith("text/plain");
    assertEquals(getBlob.getUserMetadata().getMetadata().get("Metadata"), metadataValue);
    SystemMetadata md = getBlob.getSystemMetadata();
    assertEquals(md.getSize(), 16);
    assert md.getGroupID() != null;
    assertEquals(md.getHardLinkCount(), 1);
    assert md.getInceptionTime() != null;
    assert md.getLastAccessTime() != null;
    assert md.getLastMetadataModification() != null;
    assert md.getLastUserDataModification() != null;
    assert md.getObjectID() != null;
    assertEquals(md.getObjectName(), "object");
    assert md.getPolicyName() != null;
    assertEquals(md.getType(), FileType.REGULAR);
    assert md.getUserID() != null;

    try {
      Utils.toStringAndClose(
          URI.create(
                  "http://accesspoint.emccis.com/rest/objects/"
                      + getBlob.getSystemMetadata().getObjectID())
              .toURL()
              .openStream());
      assert false : "shouldn't have worked, since it is private";
    } catch (IOException e) {

    }
  }
 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);
 }
 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);
 }
 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;
   }
 }
  protected void retryAndCheckSystemMetadataAndPutIfPresentReplaceStrategy(AtmosObject object)
      throws Exception {

    int failures = 0;
    while (true) {
      try {
        checkSystemMetadataAndPutIfPresentReplaceStrategy(object);
        break;
      } catch (ExecutionException e1) { // bug
        if (!(e1.getCause() instanceof KeyAlreadyExistsException)) throw e1;
        else failures++;
      }
    }
    if (failures > 0)
      System.err.printf(
          "%d failures create/replacing %s%n",
          failures, object.getData() instanceof InputStream ? "stream" : "string");
  }