lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1637278 - in /lucene/dev/trunk/lucene/core/src: java/org/apache/lucene/util/IOUtils.java test/org/apache/lucene/util/TestIOUtils.java
Date Fri, 07 Nov 2014 00:59:27 GMT
Author: rmuir
Date: Fri Nov  7 00:59:26 2014
New Revision: 1637278

URL: http://svn.apache.org/r1637278
Log:
LUCENE-6051: don't use trappy Iterable<Path> in helper functions

Added:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java   (with
props)
Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/IOUtils.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/IOUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/IOUtils.java?rev=1637278&r1=1637277&r2=1637278&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/IOUtils.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/IOUtils.java Fri Nov  7 00:59:26
2014
@@ -37,6 +37,7 @@ import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -215,7 +216,7 @@ public final class IOUtils {
    * <p>
    * Some of the files may be null, if so they are ignored.
    */
-  public static void deleteFilesIgnoringExceptions(Iterable<? extends Path> files)
{
+  public static void deleteFilesIgnoringExceptions(Collection<? extends Path> files)
{
     for (Path name : files) {
       if (name != null) {
         try {
@@ -249,7 +250,7 @@ public final class IOUtils {
    * 
    * @param files files to delete
    */
-  public static void deleteFilesIfExist(Iterable<? extends Path> files) throws IOException
{
+  public static void deleteFilesIfExist(Collection<? extends Path> files) throws IOException
{
     Throwable th = null;
 
     for (Path file : files) {

Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java?rev=1637278&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java Fri Nov
 7 00:59:26 2014
@@ -0,0 +1,81 @@
+package org.apache.lucene.util;
+
+/*
+ * 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.
+ */
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+/** Simple test methods for IOUtils */
+public class TestIOUtils extends LuceneTestCase {
+  
+  public void testDeleteFileIgnoringExceptions() throws Exception {
+    Path dir = createTempDir();
+    Path file1 = dir.resolve("file1");
+    Files.createFile(file1);
+    IOUtils.deleteFilesIgnoringExceptions(file1);
+    assertFalse(Files.exists(file1));
+    // actually deletes
+  }
+  
+  public void testDontDeleteFileIgnoringExceptions() throws Exception {
+    Path dir = createTempDir();
+    Path file1 = dir.resolve("file1");
+    IOUtils.deleteFilesIgnoringExceptions(file1);
+    // no exception
+  }
+  
+  public void testDeleteTwoFilesIgnoringExceptions() throws Exception {
+    Path dir = createTempDir();
+    Path file1 = dir.resolve("file1");
+    Path file2 = dir.resolve("file2");
+    // only create file2
+    Files.createFile(file2);
+    IOUtils.deleteFilesIgnoringExceptions(file1, file2);
+    assertFalse(Files.exists(file2));
+    // no exception
+    // actually deletes file2
+  }
+  
+  public void testDeleteFileIfExists() throws Exception {
+    Path dir = createTempDir();
+    Path file1 = dir.resolve("file1");
+    Files.createFile(file1);
+    IOUtils.deleteFilesIfExist(file1);
+    assertFalse(Files.exists(file1));
+    // actually deletes
+  }
+  
+  public void testDontDeleteDoesntExist() throws Exception {
+    Path dir = createTempDir();
+    Path file1 = dir.resolve("file1");
+    IOUtils.deleteFilesIfExist(file1);
+    // no exception
+  }
+  
+  public void testDeleteTwoFilesIfExist() throws Exception {
+    Path dir = createTempDir();
+    Path file1 = dir.resolve("file1");
+    Path file2 = dir.resolve("file2");
+    // only create file2
+    Files.createFile(file2);
+    IOUtils.deleteFilesIfExist(file1, file2);
+    assertFalse(Files.exists(file2));
+    // no exception
+    // actually deletes file2
+  }
+}



Mime
View raw message