コード例 #1
0
 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;
   }
 }
コード例 #2
0
 private static void verifyObject(
     AtmosStorageClient connection, String path, String compare, String metadataValue)
     throws InterruptedException, ExecutionException, TimeoutException, IOException {
   AtmosObject getBlob = connection.readFile(path);
   assertEquals(
       getBlob.getData() instanceof String
           ? getBlob.getData()
           : IOUtils.toString((InputStream) getBlob.getData()),
       compare);
   verifyMetadata(metadataValue, getBlob);
 }
コード例 #3
0
 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;
   }
 }
コード例 #4
0
  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");
  }