Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

add CrankyPointFormat

Mike McCandlessda5cc3cad56c
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java
index 414c70732f1..b5d12219914 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java
@@ -166,7 +166,7 @@ final class SegmentCoreReaders {
}
}
- private void notifyCoreClosedListeners(Throwable th) {
+ private void notifyCoreClosedListeners(Throwable th) throws IOException {
synchronized(coreClosedListeners) {
for (CoreClosedListener listener : coreClosedListeners) {
// SegmentReader uses our instance as its
@@ -181,7 +181,7 @@ final class SegmentCoreReaders {
}
}
}
- IOUtils.reThrowUnchecked(th);
+ IOUtils.reThrow(th);
}
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyCodec.java
index 7925356f5dd..3367d429093 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyCodec.java
@@ -26,6 +26,7 @@ import org.apache.lucene.codecs.FieldInfosFormat;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.LiveDocsFormat;
import org.apache.lucene.codecs.NormsFormat;
+import org.apache.lucene.codecs.PointFormat;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.SegmentInfoFormat;
import org.apache.lucene.codecs.StoredFieldsFormat;
@@ -91,6 +92,11 @@ public class CrankyCodec extends FilterCodec {
return new CrankyCompoundFormat(delegate.compoundFormat(), random);
}
+ @Override
+ public PointFormat pointFormat() {
+ return new CrankyPointFormat(delegate.pointFormat(), random);
+ }
+
@Override
public String toString() {
return "Cranky(" + delegate + ")";
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyPointFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyPointFormat.java
new file mode 100644
index 00000000000..ed2b7a3da91
--- /dev/null
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyPointFormat.java
@@ -0,0 +1,176 @@
+package org.apache.lucene.codecs.cranky;
+
+/*
+ * 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.io.IOException;
+import java.util.Random;
+
+import org.apache.lucene.codecs.PointFormat;
+import org.apache.lucene.codecs.PointReader;
+import org.apache.lucene.codecs.PointWriter;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.MergeState;
+import org.apache.lucene.index.SegmentInfo;
+import org.apache.lucene.index.SegmentReadState;
+import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+
+class CrankyPointFormat extends PointFormat {
+ PointFormat delegate;
+ Random random;
+
+ CrankyPointFormat(PointFormat delegate, Random random) {
+ this.delegate = delegate;
+ this.random = random;
+ }
+
+ @Override
+ public PointWriter fieldsWriter(SegmentWriteState state) throws IOException {
+ return new CrankyPointWriter(delegate.fieldsWriter(state), random);
+ }
+
+ @Override
+ public PointReader fieldsReader(SegmentReadState state) throws IOException {
+ return new CrankyPointReader(delegate.fieldsReader(state), random);
+ }
+
+ static class CrankyPointWriter extends PointWriter {
+ final PointWriter delegate;
+ final Random random;
+
+ public CrankyPointWriter(PointWriter delegate, Random random) {
+ this.delegate = delegate;
+ this.random = random;
+ }
+
+ @Override
+ public void writeField(FieldInfo fieldInfo, PointReader values) throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ delegate.writeField(fieldInfo, values);
+ }
+
+ @Override
+ public void finish() throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ delegate.finish();
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ }
+
+ @Override
+ public void merge(MergeState mergeState) throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ delegate.merge(mergeState);
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate.close();
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ }
+ }
+
+ static class CrankyPointReader extends PointReader {
+ final PointReader delegate;
+ final Random random;
+ public CrankyPointReader(PointReader delegate, Random random) {
+ this.delegate = delegate;
+ this.random = random;
+ }
+
+ @Override
+ public void checkIntegrity() throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ delegate.checkIntegrity();
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ }
+
+ @Override
+ public void intersect(String fieldName, IntersectVisitor visitor) throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ delegate.intersect(fieldName, visitor);
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ }
+
+ @Override
+ public byte[] getMinPackedValue(String fieldName) throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ return delegate.getMinPackedValue(fieldName);
+ }
+
+ @Override
+ public byte[] getMaxPackedValue(String fieldName) throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ return delegate.getMaxPackedValue(fieldName);
+ }
+
+ @Override
+ public int getNumDimensions(String fieldName) throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ return delegate.getNumDimensions(fieldName);
+ }
+
+ @Override
+ public int getBytesPerDimension(String fieldName) throws IOException {
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ return delegate.getBytesPerDimension(fieldName);
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate.close();
+ if (random.nextInt(100) == 0) {
+ throw new IOException("Fake IOException");
+ }
+ }
+
+ @Override
+ public long ramBytesUsed() {
+ return delegate.ramBytesUsed();
+ }
+ }
+}