accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [22/23] accumulo git commit: ACCUMULO-4318 Fix resource leak warnings from AutoClosable
Date Mon, 20 Jun 2016 23:50:14 GMT
ACCUMULO-4318 Fix resource leak warnings from AutoClosable


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

Branch: refs/heads/1.8
Commit: 94bf129c8c3635bb99b272db009350a448503607
Parents: 4f7fbf4
Author: Christopher Tubbs <ctubbsii@apache.org>
Authored: Mon Jun 20 19:37:47 2016 -0400
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Mon Jun 20 19:45:36 2016 -0400

----------------------------------------------------------------------
 .../core/metadata/MetadataLocationObtainer.java | 21 ++++---
 .../core/client/impl/ScannerOptionsTest.java    | 58 +++++++++++---------
 2 files changed, 44 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/94bf129c/core/src/main/java/org/apache/accumulo/core/metadata/MetadataLocationObtainer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/metadata/MetadataLocationObtainer.java
b/core/src/main/java/org/apache/accumulo/core/metadata/MetadataLocationObtainer.java
index c59fab2..d6af8ba 100644
--- a/core/src/main/java/org/apache/accumulo/core/metadata/MetadataLocationObtainer.java
+++ b/core/src/main/java/org/apache/accumulo/core/metadata/MetadataLocationObtainer.java
@@ -149,6 +149,15 @@ public class MetadataLocationObtainer implements TabletLocationObtainer
{
     }
   }
 
+  private static class SettableScannerOptions extends ScannerOptions {
+    public ScannerOptions setColumns(SortedSet<Column> locCols) {
+      this.fetchedColumns = locCols;
+      // see comment in lookupTablet about why iterator is used
+      addScanIterator(new IteratorSetting(10000, "WRI", WholeRowIterator.class.getName()));
+      return this;
+    }
+  }
+
   @Override
   public List<TabletLocation> lookupTablets(ClientContext context, String tserver,
Map<KeyExtent,List<Range>> tabletsRanges, TabletLocator parent)
       throws AccumuloSecurityException, AccumuloException {
@@ -169,14 +178,10 @@ public class MetadataLocationObtainer implements TabletLocationObtainer
{
       }
     };
 
-    ScannerOptions opts = new ScannerOptions() {
-      ScannerOptions setOpts() {
-        this.fetchedColumns = locCols;
-        // see comment in lookupTablet about why iterator is used
-        addScanIterator(new IteratorSetting(10000, "WRI", WholeRowIterator.class.getName()));
-        return this;
-      }
-    }.setOpts();
+    ScannerOptions opts = null;
+    try (SettableScannerOptions unsetOpts = new SettableScannerOptions()) {
+      opts = unsetOpts.setColumns(locCols);
+    }
 
     Map<KeyExtent,List<Range>> unscanned = new HashMap<KeyExtent,List<Range>>();
     Map<KeyExtent,List<Range>> failures = new HashMap<KeyExtent,List<Range>>();

http://git-wip-us.apache.org/repos/asf/accumulo/blob/94bf129c/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerOptionsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerOptionsTest.java
b/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerOptionsTest.java
index 920d687..cfdbe6f 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerOptionsTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerOptionsTest.java
@@ -38,44 +38,48 @@ public class ScannerOptionsTest {
    */
   @Test
   public void testAddRemoveIterator() throws Throwable {
-    ScannerOptions options = new ScannerOptions();
-    options.addScanIterator(new IteratorSetting(1, "NAME", WholeRowIterator.class));
-    assertEquals(1, options.serverSideIteratorList.size());
-    options.removeScanIterator("NAME");
-    assertEquals(0, options.serverSideIteratorList.size());
+    try (ScannerOptions options = new ScannerOptions()) {
+      options.addScanIterator(new IteratorSetting(1, "NAME", WholeRowIterator.class));
+      assertEquals(1, options.serverSideIteratorList.size());
+      options.removeScanIterator("NAME");
+      assertEquals(0, options.serverSideIteratorList.size());
+    }
   }
 
   @Test
   public void testIteratorConflict() {
-    ScannerOptions options = new ScannerOptions();
-    options.addScanIterator(new IteratorSetting(1, "NAME", DebugIterator.class));
-    try {
-      options.addScanIterator(new IteratorSetting(2, "NAME", DebugIterator.class));
-      fail();
-    } catch (IllegalArgumentException e) {}
-    try {
-      options.addScanIterator(new IteratorSetting(1, "NAME2", DebugIterator.class));
-      fail();
-    } catch (IllegalArgumentException e) {}
+    try (ScannerOptions options = new ScannerOptions()) {
+      options.addScanIterator(new IteratorSetting(1, "NAME", DebugIterator.class));
+      try {
+        options.addScanIterator(new IteratorSetting(2, "NAME", DebugIterator.class));
+        fail();
+      } catch (IllegalArgumentException e) {}
+      try {
+        options.addScanIterator(new IteratorSetting(1, "NAME2", DebugIterator.class));
+        fail();
+      } catch (IllegalArgumentException e) {}
+    }
   }
 
   @Test
   public void testFetchColumn() {
-    ScannerOptions options = new ScannerOptions();
-    assertEquals(0, options.getFetchedColumns().size());
-    IteratorSetting.Column col = new IteratorSetting.Column(new Text("family"), new Text("qualifier"));
-    options.fetchColumn(col);
-    SortedSet<Column> fetchedColumns = options.getFetchedColumns();
-    assertEquals(1, fetchedColumns.size());
-    Column fetchCol = fetchedColumns.iterator().next();
-    assertEquals(col.getColumnFamily(), new Text(fetchCol.getColumnFamily()));
-    assertEquals(col.getColumnQualifier(), new Text(fetchCol.getColumnQualifier()));
+    try (ScannerOptions options = new ScannerOptions()) {
+      assertEquals(0, options.getFetchedColumns().size());
+      IteratorSetting.Column col = new IteratorSetting.Column(new Text("family"), new Text("qualifier"));
+      options.fetchColumn(col);
+      SortedSet<Column> fetchedColumns = options.getFetchedColumns();
+      assertEquals(1, fetchedColumns.size());
+      Column fetchCol = fetchedColumns.iterator().next();
+      assertEquals(col.getColumnFamily(), new Text(fetchCol.getColumnFamily()));
+      assertEquals(col.getColumnQualifier(), new Text(fetchCol.getColumnQualifier()));
+    }
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testFetchNullColumn() {
-    ScannerOptions options = new ScannerOptions();
-    // Require a non-null instance of Column
-    options.fetchColumn((IteratorSetting.Column) null);
+    try (ScannerOptions options = new ScannerOptions()) {
+      // Require a non-null instance of Column
+      options.fetchColumn((IteratorSetting.Column) null);
+    }
   }
 }


Mime
View raw message