From commits-return-23793-archive-asf-public=cust-asf.ponee.io@accumulo.apache.org Fri Mar 6 22:22:34 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 598CF18057A for ; Fri, 6 Mar 2020 23:22:34 +0100 (CET) Received: (qmail 23735 invoked by uid 500); 6 Mar 2020 22:22:33 -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 23726 invoked by uid 99); 6 Mar 2020 22:22:33 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Mar 2020 22:22:33 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 413448DACA; Fri, 6 Mar 2020 22:22:32 +0000 (UTC) Date: Fri, 06 Mar 2020 22:22:32 +0000 To: "commits@accumulo.apache.org" Subject: [accumulo] branch master updated: Use Set instead of array for ViewFSUtils (#1551) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <158353335277.2837.9907787136509941556@gitbox.apache.org> From: ctubbsii@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: accumulo X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 90dc4d76f11bd16de4f66b4a5714e32fba036bee X-Git-Newrev: 9e802b8d2ad27c2f3db3a14d07321c969598c3b0 X-Git-Rev: 9e802b8d2ad27c2f3db3a14d07321c969598c3b0 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. ctubbsii pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/accumulo.git The following commit(s) were added to refs/heads/master by this push: new 9e802b8 Use Set instead of array for ViewFSUtils (#1551) 9e802b8 is described below commit 9e802b8d2ad27c2f3db3a14d07321c969598c3b0 Author: Christopher Tubbs AuthorDate: Fri Mar 6 17:07:15 2020 -0500 Use Set instead of array for ViewFSUtils (#1551) Resolves a comment from code review on #1551 --- .../org/apache/accumulo/server/fs/ViewFSUtils.java | 3 ++- .../accumulo/server/fs/VolumeManagerImpl.java | 2 +- .../apache/accumulo/server/fs/ViewFSUtilsTest.java | 30 ++++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/server/base/src/main/java/org/apache/accumulo/server/fs/ViewFSUtils.java b/server/base/src/main/java/org/apache/accumulo/server/fs/ViewFSUtils.java index 5263c32..af5a466 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/fs/ViewFSUtils.java +++ b/server/base/src/main/java/org/apache/accumulo/server/fs/ViewFSUtils.java @@ -19,6 +19,7 @@ package org.apache.accumulo.server.fs; import java.io.IOException; +import java.util.Set; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; @@ -45,7 +46,7 @@ public class ViewFSUtils { return fs.getClass().getName().equals(VIEWFS_CLASSNAME); } - public static Path matchingFileSystem(Path source, String[] options, Configuration conf) + public static Path matchingFileSystem(Path source, Set options, Configuration conf) throws IOException { if (!isViewFS(source, conf)) diff --git a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java index 2e3b31e..d181bad 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java +++ b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java @@ -388,7 +388,7 @@ public class VolumeManagerImpl implements VolumeManager { public Path matchingFileSystem(Path source, Set options) { try { if (ViewFSUtils.isViewFS(source, hadoopConf)) { - return ViewFSUtils.matchingFileSystem(source, options.toArray(new String[0]), hadoopConf); + return ViewFSUtils.matchingFileSystem(source, options, hadoopConf); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/server/base/src/test/java/org/apache/accumulo/server/fs/ViewFSUtilsTest.java b/server/base/src/test/java/org/apache/accumulo/server/fs/ViewFSUtilsTest.java index f28d463..0826c5c 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/fs/ViewFSUtilsTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/fs/ViewFSUtilsTest.java @@ -23,6 +23,10 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; @@ -30,10 +34,12 @@ import org.junit.Test; public class ViewFSUtilsTest { - private String[] shuffle(String... inputs) { - // code below will modify array - Collections.shuffle(Arrays.asList(inputs)); - return inputs; + private Set shuffle(String... inputs) { + List inputsArray = Arrays.asList(inputs); + // shuffle will modify array, because ArrayList implements RandomAccess + Collections.shuffle(inputsArray); + // preserve the shuffled array as an insertion-ordered set + return inputsArray.stream().collect(Collectors.toCollection(LinkedHashSet::new)); } @Test @@ -45,11 +51,12 @@ public class ViewFSUtilsTest { conf.set("fs.viewfs.mounttable.default.link./ns2", "file:///tmp/ns2"); conf.set("fs.viewfs.mounttable.default.link./ns22", "file:///tmp/ns22"); - String[] tablesDirs1 = + Set tablesDirs1 = shuffle("viewfs:///ns1/accumulo/tables", "viewfs:///ns2/accumulo/tables", "viewfs:///ns22/accumulo/tables", "viewfs:///ns/accumulo/tables"); - String[] tablesDirs2 = shuffle("viewfs:/ns1/accumulo/tables", "viewfs:/ns2/accumulo/tables", - "viewfs:/ns22/accumulo/tables", "viewfs:/ns/accumulo/tables"); + Set tablesDirs2 = + shuffle("viewfs:/ns1/accumulo/tables", "viewfs:/ns2/accumulo/tables", + "viewfs:/ns22/accumulo/tables", "viewfs:/ns/accumulo/tables"); for (String ns : Arrays.asList("ns1", "ns2", "ns22", "ns")) { Path match = ViewFSUtils.matchingFileSystem(new Path("viewfs:/" + ns + "/bulk_import_01"), @@ -82,13 +89,14 @@ public class ViewFSUtilsTest { conf.set("fs.viewfs.mounttable.default.link./ns1/C", "file:///tmp/3"); conf.set("fs.viewfs.mounttable.default.link./ns2", "file:///tmp/3"); - String[] tablesDirs1 = + Set tablesDirs1 = shuffle("viewfs:///ns1/accumulo/tables", "viewfs:///ns1/A/accumulo/tables", "viewfs:///ns1/AA/accumulo/tables", "viewfs:///ns1/C/accumulo/tables", "viewfs:///ns2/accumulo/tables", "viewfs:///accumulo/tables"); - String[] tablesDirs2 = shuffle("viewfs:/ns1/accumulo/tables", "viewfs:/ns1/A/accumulo/tables", - "viewfs:/ns1/AA/accumulo/tables", "viewfs:/ns1/C/accumulo/tables", - "viewfs:/ns2/accumulo/tables", "viewfs:/accumulo/tables"); + Set tablesDirs2 = + shuffle("viewfs:/ns1/accumulo/tables", "viewfs:/ns1/A/accumulo/tables", + "viewfs:/ns1/AA/accumulo/tables", "viewfs:/ns1/C/accumulo/tables", + "viewfs:/ns2/accumulo/tables", "viewfs:/accumulo/tables"); for (String ns : Arrays.asList("", "/ns1", "/ns1/A", "/ns1/AA", "/ns1/C", "/ns2")) { Path match = ViewFSUtils.matchingFileSystem(new Path("viewfs:" + ns + "/bulk_import_01"),