lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwe...@apache.org
Subject lucene-solr:branch_7x: LUCENE-8415: test quirk follow up. MockDirectoryWriter uses AccessDeniedException (a subclass of IOException) to signal files still open for writing when read access is requested.
Date Wed, 25 Jul 2018 09:35:13 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x d31e45961 -> 608f0277b


LUCENE-8415: test quirk follow up. MockDirectoryWriter uses AccessDeniedException (a subclass
of IOException) to signal files still open for writing when read access is requested.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/608f0277
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/608f0277
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/608f0277

Branch: refs/heads/branch_7x
Commit: 608f0277b07c73218e5dc1d8ce3a264020c50f36
Parents: d31e459
Author: Dawid Weiss <dweiss@apache.org>
Authored: Wed Jul 25 11:34:31 2018 +0200
Committer: Dawid Weiss <dweiss@apache.org>
Committed: Wed Jul 25 11:34:57 2018 +0200

----------------------------------------------------------------------
 .../org/apache/lucene/store/BaseDirectoryTestCase.java   |  4 ++--
 .../org/apache/lucene/store/MockDirectoryWrapper.java    | 11 ++++++-----
 2 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/608f0277/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
index 4270424..ab2921b 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
@@ -440,8 +440,8 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
                 try (IndexInput input = dir.openInput(file, newIOContext(random()))) {
                   // Just open, nothing else.
                 } catch (AccessDeniedException e) {
-                  // Access denied is allowed for files for which the output is still open.
-                  // Since we don't synchronize with the writer thread, just ignore it.
+                  // Access denied is allowed for files for which the output is still open
(MockDirectoryWriter enforces
+                  // this, for example). Since we don't synchronize with the writer thread,
just ignore it.
                 } catch (IOException e) {
                   throw new UncheckedIOException("Something went wrong when opening: " +
file, e);
                 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/608f0277/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
index ec0d4ff..15f6454 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
@@ -19,6 +19,7 @@ package org.apache.lucene.store;
 import java.io.Closeable;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.nio.file.AccessDeniedException;
 import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.NoSuchFileException;
 import java.util.ArrayList;
@@ -218,11 +219,11 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
     }
     
     if (openFiles.containsKey(source) && assertNoDeleteOpenFile) {
-      throw (AssertionError) fillOpenTrace(new AssertionError("MockDirectoryWrapper: source
file \"" + source + "\" is still open: cannot rename"), source, true);
+      throw fillOpenTrace(new AssertionError("MockDirectoryWrapper: source file \"" + source
+ "\" is still open: cannot rename"), source, true);
     }
 
     if (openFiles.containsKey(dest) && assertNoDeleteOpenFile) {
-      throw (AssertionError) fillOpenTrace(new AssertionError("MockDirectoryWrapper: dest
file \"" + dest + "\" is still open: cannot rename"), dest, true);
+      throw fillOpenTrace(new AssertionError("MockDirectoryWrapper: dest file \"" + dest
+ "\" is still open: cannot rename"), dest, true);
     }
 
     boolean success = false;
@@ -596,7 +597,7 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
     if (openFiles.containsKey(name)) {
       openFilesDeleted.add(name);
       if (assertNoDeleteOpenFile) {
-        throw (IOException) fillOpenTrace(new IOException("MockDirectoryWrapper: file \""
+ name + "\" is still open: cannot delete"), name, true);
+        throw fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\"
is still open: cannot delete"), name, true);
       }
     } else {
       openFilesDeleted.remove(name);
@@ -609,7 +610,7 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
 
   // sets the cause of the incoming ioe to be the stack
   // trace when the offending file name was opened
-  private synchronized Throwable fillOpenTrace(Throwable t, String name, boolean input) {
+  private synchronized <T extends Throwable> T fillOpenTrace(T t, String name, boolean
input) {
     for(Map.Entry<Closeable,Exception> ent : openFileHandles.entrySet()) {
       if (input && ent.getKey() instanceof MockIndexInputWrapper && ((MockIndexInputWrapper)
ent.getKey()).name.equals(name)) {
         t.initCause(ent.getValue());
@@ -749,7 +750,7 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
 
     // cannot open a file for input if it's still open for output.
     if (!allowReadingFilesStillOpenForWrite && openFilesForWrite.contains(name))
{
-      throw (IOException) fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" +
name + "\" is still open for writing"), name, false);
+      throw fillOpenTrace(new AccessDeniedException("MockDirectoryWrapper: file \"" + name
+ "\" is still open for writing"), name, false);
     }
 
     IndexInput delegateInput = in.openInput(name, LuceneTestCase.newIOContext(randomState,
context));


Mime
View raw message