Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 4ed530dc0 -> 073ed20c1


PHOENIX-2563 Pherf's ResourceList should fail gracefully if a Jar file doesn't 
exist (elserj)


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 073ed20c15093a78fe210dfc0b86920a3270d26e
Parents: 4ed530d
Author: Mujtaba <mujt...@apache.org>
Authored: Mon Jan 11 16:31:53 2016 -0800
Committer: Mujtaba <mujt...@apache.org>
Committed: Mon Jan 11 16:31:53 2016 -0800

----------------------------------------------------------------------
 .../apache/phoenix/pherf/util/ResourceList.java |  7 +++-
 .../phoenix/pherf/util/ResourceListTest.java    | 38 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/073ed20c/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java
----------------------------------------------------------------------
diff --git 
a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java 
b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java
index 037426e..0b54641 100644
--- 
a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java
+++ 
b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java
@@ -24,6 +24,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URL;
@@ -121,13 +122,17 @@ public class ResourceList {
         return retVal;
     }
 
-    private Collection<String> getResourcesFromJarFile(
+    // Visible for testing
+    Collection<String> getResourcesFromJarFile(
             final File file,
             final Pattern pattern) {
         final List<String> retVal = new ArrayList<>();
         ZipFile zf;
         try {
             zf = new ZipFile(file);
+        } catch (FileNotFoundException e) {
+            // Gracefully handle a jar listed on the classpath that doesn't 
actually exist.
+            return Collections.emptyList();
         } catch (final ZipException e) {
             throw new Error(e);
         } catch (final IOException e) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/073ed20c/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/util/ResourceListTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/util/ResourceListTest.java
 
b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/util/ResourceListTest.java
new file mode 100644
index 0000000..c77cb82
--- /dev/null
+++ 
b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/util/ResourceListTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.pherf.util;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+public class ResourceListTest {
+
+  @Test
+  public void testMissingJarFileReturnsGracefully() {
+    ResourceList rl = new ResourceList("foo");
+    File missingFile = new File("abracadabraphoenix.txt");
+    assertFalse("Did not expect a fake test file to actually exist", 
missingFile.exists());
+    assertEquals(Collections.emptyList(), 
rl.getResourcesFromJarFile(missingFile, Pattern.compile("pattern")));
+  }
+
+}

Reply via email to