Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 88080200B35 for ; Tue, 21 Jun 2016 01:49:56 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 86C6E160A55; Mon, 20 Jun 2016 23:49:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 50CD1160A70 for ; Tue, 21 Jun 2016 01:49:55 +0200 (CEST) Received: (qmail 15919 invoked by uid 500); 20 Jun 2016 23:49:54 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 15032 invoked by uid 99); 20 Jun 2016 23:49:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jun 2016 23:49:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B0263ED31D; Mon, 20 Jun 2016 23:49:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ctubbsii@apache.org To: commits@accumulo.apache.org Date: Mon, 20 Jun 2016 23:50:14 -0000 Message-Id: In-Reply-To: <2c754b2c4aab49d89c626af41b84d51f@git.apache.org> References: <2c754b2c4aab49d89c626af41b84d51f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/23] accumulo git commit: ACCUMULO-4318 Fix resource leak warnings from AutoClosable archived-at: Mon, 20 Jun 2016 23:49:56 -0000 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 Authored: Mon Jun 20 19:37:47 2016 -0400 Committer: Christopher Tubbs 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 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 lookupTablets(ClientContext context, String tserver, Map> 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> unscanned = new HashMap>(); Map> failures = new HashMap>(); 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 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 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); + } } }