You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2017/03/01 18:13:05 UTC
lucene-solr:master: LUCENE-7410: Make TestReaderClosed pass if the
IndexSearcher wraps a threadpool.
Repository: lucene-solr
Updated Branches:
refs/heads/master 1cfa04864 -> 540a23723
LUCENE-7410: Make TestReaderClosed pass if the IndexSearcher wraps a threadpool.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/540a2372
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/540a2372
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/540a2372
Branch: refs/heads/master
Commit: 540a23723104e250a4fce94042fb90c86fcf3720
Parents: 1cfa048
Author: Adrien Grand <jp...@gmail.com>
Authored: Wed Mar 1 19:12:14 2017 +0100
Committer: Adrien Grand <jp...@gmail.com>
Committed: Wed Mar 1 19:12:14 2017 +0100
----------------------------------------------------------------------
.../apache/lucene/index/TestReaderClosed.java | 8 ++-
.../lucene/index/OwnCacheKeyMultiReader.java | 76 ++++++++++++++++++++
2 files changed, 82 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/540a2372/lucene/core/src/test/org/apache/lucene/index/TestReaderClosed.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestReaderClosed.java b/lucene/core/src/test/org/apache/lucene/index/TestReaderClosed.java
index 981a0ee..a6b1c653 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestReaderClosed.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestReaderClosed.java
@@ -79,7 +79,9 @@ public class TestReaderClosed extends LuceneTestCase {
assertTrue(reader.getRefCount() > 0);
LeafReader wrappedReader = new ParallelLeafReader(getOnlyLeafReader(reader));
- IndexSearcher searcher = newSearcher(wrappedReader);
+ // We wrap with a OwnCacheKeyMultiReader so that closing the underlying reader
+ // does not terminate the threadpool (if that index searcher uses one)
+ IndexSearcher searcher = newSearcher(new OwnCacheKeyMultiReader(wrappedReader));
TermRangeQuery query = TermRangeQuery.newStringRange("field", "a", "z", true, true);
searcher.search(query, 5);
@@ -93,7 +95,9 @@ public class TestReaderClosed extends LuceneTestCase {
ace = (AlreadyClosedException) t;
}
}
- assertNotNull("Query failed, but not due to an AlreadyClosedException", ace);
+ if (ace == null) {
+ throw new AssertionError("Query failed, but not due to an AlreadyClosedException", e);
+ }
assertEquals(
"this IndexReader cannot be used anymore as one of its child readers was closed",
ace.getMessage()
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/540a2372/lucene/test-framework/src/java/org/apache/lucene/index/OwnCacheKeyMultiReader.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/OwnCacheKeyMultiReader.java b/lucene/test-framework/src/java/org/apache/lucene/index/OwnCacheKeyMultiReader.java
new file mode 100644
index 0000000..45aabfe
--- /dev/null
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/OwnCacheKeyMultiReader.java
@@ -0,0 +1,76 @@
+/*
+ * 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.lucene.index;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import org.apache.lucene.util.IOUtils;
+
+/**
+ * A {@link MultiReader} that has its own cache key, occasionally useful for
+ * testing purposes.
+ */
+public final class OwnCacheKeyMultiReader extends MultiReader {
+
+ private final Set<ClosedListener> readerClosedListeners = new CopyOnWriteArraySet<>();
+
+ private final CacheHelper cacheHelper = new CacheHelper() {
+ private final CacheKey cacheKey = new CacheKey();
+
+ @Override
+ public CacheKey getKey() {
+ return cacheKey;
+ }
+
+ @Override
+ public void addClosedListener(ClosedListener listener) {
+ readerClosedListeners.add(listener);
+ }
+
+ };
+
+ /** Sole constructor. */
+ public OwnCacheKeyMultiReader(IndexReader... subReaders) throws IOException {
+ super(subReaders);
+ }
+
+ @Override
+ public CacheHelper getReaderCacheHelper() {
+ return cacheHelper;
+ }
+
+ @Override
+ void notifyReaderClosedListeners(Throwable th) throws IOException {
+ synchronized(readerClosedListeners) {
+ for(ClosedListener listener : readerClosedListeners) {
+ try {
+ listener.onClose(cacheHelper.getKey());
+ } catch (Throwable t) {
+ if (th == null) {
+ th = t;
+ } else {
+ th.addSuppressed(t);
+ }
+ }
+ }
+ IOUtils.reThrow(th);
+ }
+ }
+
+}