You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2018/11/14 07:20:38 UTC
lucene-solr:branch_7x: LUCENE-8560:
TestByteBuffersDirectory.testSeekPastEOF() failures with ByteArrayIndexInput.
(backport) ByteArrayIndexInput deprecated.
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x a06e33e33 -> b33027505
LUCENE-8560: TestByteBuffersDirectory.testSeekPastEOF() failures with ByteArrayIndexInput. (backport) ByteArrayIndexInput deprecated.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b3302750
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b3302750
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b3302750
Branch: refs/heads/branch_7x
Commit: b33027505b79669bc558f5a0884b75bc525ecaa0
Parents: a06e33e
Author: Dawid Weiss <dw...@apache.org>
Authored: Wed Nov 14 08:19:38 2018 +0100
Committer: Dawid Weiss <dw...@apache.org>
Committed: Wed Nov 14 08:19:38 2018 +0100
----------------------------------------------------------------------
.../apache/lucene/store/ByteArrayIndexInput.java | 2 ++
.../apache/lucene/store/ByteBuffersDirectory.java | 17 +++++------------
.../apache/lucene/store/BaseDirectoryTestCase.java | 13 +++++++++----
3 files changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b3302750/lucene/core/src/java/org/apache/lucene/store/ByteArrayIndexInput.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteArrayIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteArrayIndexInput.java
index 9bf5ab2..b2805e5 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteArrayIndexInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteArrayIndexInput.java
@@ -25,7 +25,9 @@ import java.util.Locale;
* A {@link IndexInput} backed by a byte array.
*
* @lucene.experimental
+ * @deprecated Will be removed in future Lucene versions. Use byte buffer backed index inputs instead.
*/
+@Deprecated
public final class ByteArrayIndexInput extends IndexInput implements RandomAccessInput {
private byte[] bytes;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b3302750/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java
index 50fbc02..d1302dc 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java
@@ -68,21 +68,14 @@ public final class ByteBuffersDirectory extends BaseDirectory {
return new ByteBuffersIndexInput(dataInput, inputName);
};
- public static final BiFunction<String, ByteBuffersDataOutput, IndexInput> OUTPUT_AS_BYTE_ARRAY =
- (fileName, output) -> {
- byte[] array = output.toArrayCopy();
- String inputName = String.format(Locale.ROOT, "%s (file=%s, length=%s)",
- ByteArrayIndexInput.class.getSimpleName(),
- fileName,
- array.length);
- return new ByteArrayIndexInput(inputName, array, 0, array.length);
- };
+ public static final BiFunction<String, ByteBuffersDataOutput, IndexInput> OUTPUT_AS_BYTE_ARRAY = OUTPUT_AS_ONE_BUFFER;
public static final BiFunction<String, ByteBuffersDataOutput, IndexInput> OUTPUT_AS_MANY_BUFFERS_LUCENE =
(fileName, output) -> {
List<ByteBuffer> bufferList = output.toBufferList();
- int chunkSizePower;
bufferList.add(ByteBuffer.allocate(0));
+
+ int chunkSizePower;
int blockSize = ByteBuffersDataInput.determineBlockPage(bufferList);
if (blockSize == 0) {
chunkSizePower = 30;
@@ -95,8 +88,8 @@ public final class ByteBuffersDirectory extends BaseDirectory {
fileName);
ByteBufferGuard guard = new ByteBufferGuard("none", (String resourceDescription, ByteBuffer b) -> {});
- return ByteBufferIndexInput.newInstance(inputName,
- bufferList.toArray(new ByteBuffer [bufferList.size()]),
+ return ByteBufferIndexInput.newInstance(inputName,
+ bufferList.toArray(new ByteBuffer [bufferList.size()]),
output.size(), chunkSizePower, guard);
};
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b3302750/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 ab2921b..e49000b 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
@@ -513,10 +513,15 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
o.writeBytes(b, 0, len);
o.close();
IndexInput i = dir.openInput("out", newIOContext(random()));
- expectThrows(EOFException.class, () -> {
- i.seek(len + random().nextInt(2048));
- i.readByte();
- });
+
+ // Seeking past EOF should always throw EOFException
+ expectThrows(EOFException.class, () -> i.seek(len + RandomizedTest.randomIntBetween(1, 2048)));
+
+ // Seeking exactly to EOF should never throw any exception.
+ i.seek(len);
+
+ // But any read following the seek(len) should throw an EOFException.
+ expectThrows(EOFException.class, i::readByte);
i.close();
}