You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/05/01 13:19:33 UTC
svn commit: r1591605 -
/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/CrankyTokenFilter.java
Author: rmuir
Date: Thu May 1 11:19:33 2014
New Revision: 1591605
URL: http://svn.apache.org/r1591605
Log:
LUCENE-5635: add CrankyTokenFilter
Added:
lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/CrankyTokenFilter.java (with props)
Added: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/CrankyTokenFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/CrankyTokenFilter.java?rev=1591605&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/CrankyTokenFilter.java (added)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/CrankyTokenFilter.java Thu May 1 11:19:33 2014
@@ -0,0 +1,71 @@
+package org.apache.lucene.analysis;
+
+/*
+ * 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;
+
+/**
+ * Throws IOException from random Tokenstream methods.
+ * <p>
+ * This can be used to simulate a buggy analyzer in IndexWriter,
+ * where we must delete the document but not abort everything in the buffer.
+ */
+public class CrankyTokenFilter extends TokenFilter {
+ final Random random;
+ int thingToDo;
+
+ /** Creates a new CrankyTokenFilter */
+ public CrankyTokenFilter(TokenStream input, Random random) {
+ super(input);
+ this.random = random;
+ }
+
+ @Override
+ public boolean incrementToken() throws IOException {
+ if (thingToDo == 0 && random.nextBoolean()) {
+ throw new IOException("Fake IOException from TokenStream.incrementToken()");
+ }
+ return input.incrementToken();
+ }
+
+ @Override
+ public void end() throws IOException {
+ super.end();
+ if (thingToDo == 1 && random.nextBoolean()) {
+ throw new IOException("Fake IOException from TokenStream.end()");
+ }
+ }
+
+ @Override
+ public void reset() throws IOException {
+ super.reset();
+ thingToDo = random.nextInt(10);
+ if (thingToDo == 2 && random.nextBoolean()) {
+ throw new IOException("Fake IOException from TokenStream.reset()");
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ if (thingToDo == 3 && random.nextBoolean()) {
+ throw new IOException("Fake IOException from TokenStream.close()");
+ }
+ }
+}