From cabea439385b177abbbd2538b4e014e13d20d848 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 7 Jan 2011 18:02:35 +0000 Subject: [PATCH] LUCENE-2852: fix false EOF corner case in RAMInputStream git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1056428 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/store/RAMInputStream.java | 2 +- .../apache/lucene/search/TestThreadSafe.java | 20 +++++++++---------- .../apache/lucene/store/TestRAMDirectory.java | 18 +++++++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/store/RAMInputStream.java b/lucene/src/java/org/apache/lucene/store/RAMInputStream.java index 15f87d5e595..b898f7b38dd 100644 --- a/lucene/src/java/org/apache/lucene/store/RAMInputStream.java +++ b/lucene/src/java/org/apache/lucene/store/RAMInputStream.java @@ -83,6 +83,7 @@ class RAMInputStream extends IndexInput implements Cloneable { } private final void switchCurrentBuffer(boolean enforceEOF) throws IOException { + bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex; if (currentBufferIndex >= file.numBuffers()) { // end of file reached, no more buffers left if (enforceEOF) @@ -95,7 +96,6 @@ class RAMInputStream extends IndexInput implements Cloneable { } else { currentBuffer = file.getBuffer(currentBufferIndex); bufferPosition = 0; - bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex; long buflen = length - bufferStart; bufferLength = buflen > BUFFER_SIZE ? BUFFER_SIZE : (int) buflen; } diff --git a/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java b/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java index cb9f13f10a1..048ad57ecdc 100755 --- a/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java +++ b/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java @@ -27,6 +27,7 @@ import org.apache.lucene.document.*; import java.util.Random; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import java.io.IOException; public class TestThreadSafe extends LuceneTestCase { @@ -34,16 +35,16 @@ public class TestThreadSafe extends LuceneTestCase { IndexReader ir1; - String failure=null; - - class Thr extends Thread { final int iter; final Random rand; + final AtomicBoolean failed; + // pass in random in case we want to make things reproducable - public Thr(int iter, Random rand) { + public Thr(int iter, Random rand, AtomicBoolean failed) { this.iter = iter; this.rand = rand; + this.failed = failed; } @Override @@ -61,8 +62,8 @@ public class TestThreadSafe extends LuceneTestCase { } } catch (Throwable th) { - failure=th.toString(); - fail(failure); + failed.set(true); + throw new RuntimeException(th); } } @@ -124,16 +125,15 @@ public class TestThreadSafe extends LuceneTestCase { void doTest(int iter, int nThreads) throws Exception { Thr[] tarr = new Thr[nThreads]; + AtomicBoolean failed = new AtomicBoolean(); for (int i=0; i