Repository: jclouds
Updated Branches:
  refs/heads/master 7cde28a4d -> de68c2a1b


Some handles were not properly closed


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/de68c2a1
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/de68c2a1
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/de68c2a1

Branch: refs/heads/master
Commit: de68c2a1b04872609444b4949b15423f85349a41
Parents: 7cde28a
Author: Zack Shoylev <[email protected]>
Authored: Wed Sep 7 15:23:36 2016 -0500
Committer: Zack Shoylev <[email protected]>
Committed: Wed Sep 7 16:28:00 2016 -0500

----------------------------------------------------------------------
 .../blobstore/RegionScopedSwiftBlobStore.java   | 26 +++++++--------
 ...ionScopedSwiftBlobStoreParallelLiveTest.java | 33 +++++++++++---------
 2 files changed, 32 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/de68c2a1/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java
----------------------------------------------------------------------
diff --git 
a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java
 
b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java
index b9630e1..e902c5a 100644
--- 
a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java
+++ 
b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java
@@ -41,6 +41,7 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.LinkedBlockingQueue;
 
+import javax.annotation.Resource;
 import javax.inject.Inject;
 import javax.inject.Named;
 
@@ -76,6 +77,7 @@ import org.jclouds.io.ContentMetadata;
 import org.jclouds.io.Payload;
 import org.jclouds.io.PayloadSlicer;
 import org.jclouds.io.payloads.ByteSourcePayload;
+import org.jclouds.logging.Logger;
 import org.jclouds.openstack.swift.v1.SwiftApi;
 import org.jclouds.openstack.swift.v1.blobstore.functions.ToBlobMetadata;
 import 
org.jclouds.openstack.swift.v1.blobstore.functions.ToListContainerOptions;
@@ -89,6 +91,7 @@ import org.jclouds.openstack.swift.v1.features.BulkApi;
 import org.jclouds.openstack.swift.v1.features.ObjectApi;
 import org.jclouds.openstack.swift.v1.options.UpdateContainerOptions;
 import org.jclouds.openstack.swift.v1.reference.SwiftHeaders;
+import org.jclouds.util.Closeables2;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Function;
@@ -152,6 +155,9 @@ public class RegionScopedSwiftBlobStore implements 
BlobStore {
    protected final PayloadSlicer slicer;
    protected final ListeningExecutorService userExecutor;
 
+   @Resource
+   protected Logger logger = Logger.NULL;
+
    @Override
    public Set<? extends Location> listAssignableLocations() {
       return ImmutableSet.of(region);
@@ -701,14 +707,11 @@ public class RegionScopedSwiftBlobStore implements 
BlobStore {
          Futures.getUnchecked(Futures.allAsList(results));
 
       } catch (IOException e) {
-         // cleanup, attempt to delete large file
-         if (raf != null) {
-            try {
-               raf.close();
-            } catch (IOException e1) {}
-         }
+         Closeables2.closeQuietly(raf);
          destination.delete();
          throw new RuntimeException(e);
+      } finally {
+         Closeables2.closeQuietly(raf);
       }
    }
 
@@ -798,7 +801,7 @@ public class RegionScopedSwiftBlobStore implements 
BlobStore {
             long from;
             for (from = 0; from < contentLength; from = from + partSize) {
                try {
-                  System.out.println(Thread.currentThread() + " writing to 
output");
+                  logger.debug(Thread.currentThread() + " writing to output");
                   result = results.take();
                   if (result == null) {
                      output.close();
@@ -807,7 +810,7 @@ public class RegionScopedSwiftBlobStore implements 
BlobStore {
                   }
                   output.write(result.get());
                } catch (Exception e) {
-                  System.out.println(e);
+                  logger.debug(e.toString());
                   try {
                      // close pipe so client is notified of an exception
                      input.close();
@@ -819,10 +822,7 @@ public class RegionScopedSwiftBlobStore implements 
BlobStore {
                }
             }
             // Finished writing results to stream
-            try {
-               output.close();
-            } catch (IOException e) {
-            }
+            Closeables2.closeQuietly(output);
          }
       });
 
@@ -866,7 +866,7 @@ public class RegionScopedSwiftBlobStore implements 
BlobStore {
                byte[] downloadedBlock = 
ByteStreams.toByteArray(object.getPayload().openStream());
                return downloadedBlock;
             } catch (IOException e) {
-               System.out.println(e);
+               logger.debug(e.toString());
                lastException = e;
                continue;
             }

http://git-wip-us.apache.org/repos/asf/jclouds/blob/de68c2a1/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStoreParallelLiveTest.java
----------------------------------------------------------------------
diff --git 
a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStoreParallelLiveTest.java
 
b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStoreParallelLiveTest.java
index e7a4fed..dd48612 100644
--- 
a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStoreParallelLiveTest.java
+++ 
b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStoreParallelLiveTest.java
@@ -40,6 +40,7 @@ import org.jclouds.blobstore.BlobStore;
 import org.jclouds.blobstore.domain.Blob;
 import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
 import org.jclouds.io.payloads.FilePayload;
+import org.jclouds.util.Closeables2;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -147,24 +148,28 @@ public class RegionScopedSwiftBlobStoreParallelLiveTest 
extends BaseBlobStoreInt
 
       // Reserve space for performance reasons
       raf = new RandomAccessFile(file.getAbsoluteFile(), "rw");
-      raf.seek(size - 1);
-      raf.write(0);
+      try {
+         raf.seek(size - 1);
+         raf.write(0);
 
-      // Loop through ranges within the file
-      long from;
-      long to;
-      long partSize = 1000000;
+         // Loop through ranges within the file
+         long from;
+         long to;
+         long partSize = 1000000;
 
-      ExecutorService threadPool = Executors.newFixedThreadPool(16);
+         ExecutorService threadPool = Executors.newFixedThreadPool(16);
 
-      for (from = 0; from < size; from = from + partSize) {
-         to = (from + partSize >= size) ? size - 1 : from + partSize - 1;
-         RandomFileWriter writer = new RandomFileWriter(raf, from, to);
-         threadPool.submit(writer);
-      }
+         for (from = 0; from < size; from = from + partSize) {
+            to = (from + partSize >= size) ? size - 1 : from + partSize - 1;
+            RandomFileWriter writer = new RandomFileWriter(raf, from, to);
+            threadPool.submit(writer);
+         }
 
-      threadPool.shutdown();
-      threadPool.awaitTermination(1, TimeUnit.DAYS);
+         threadPool.shutdown();
+         threadPool.awaitTermination(1, TimeUnit.DAYS);
+      } finally {
+         Closeables2.closeQuietly(raf);
+      }
    }
 
    private final class RandomFileWriter implements Runnable {

Reply via email to