Add back assertions removed by LUCENE-9187. (#1236)

This time they would only apply to TestFastLZ4/TestHighLZ4 and avoid slowing
down all tests.
This commit is contained in:
Adrien Grand 2020-02-14 10:37:06 +01:00 committed by GitHub
parent dcf448efeb
commit 5cbe58f22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 2 deletions

View File

@ -202,6 +202,9 @@ public final class LZ4 {
* offsets. A return value of {@code -1} indicates that no other index could
* be found. */
abstract int previous(int off);
// For testing
abstract boolean assertReset();
}
/**
@ -263,6 +266,11 @@ public final class LZ4 {
return -1;
}
@Override
boolean assertReset() {
return true;
}
}
/**
@ -369,6 +377,14 @@ public final class LZ4 {
}
return -1;
}
@Override
boolean assertReset() {
for (int i = 0; i < chainTable.length; ++i) {
assert chainTable[i] == (short) 0xFFFF : i;
}
return true;
}
}
/**

View File

@ -30,6 +30,37 @@ public abstract class LZ4TestCase extends LuceneTestCase {
protected abstract LZ4.HashTable newHashTable();
protected static class AssertingHashTable extends LZ4.HashTable {
private final LZ4.HashTable in;
AssertingHashTable(LZ4.HashTable in) {
this.in = in;
}
@Override
void reset(byte[] b, int off, int len) {
in.reset(b, off, len);
assertTrue(in.assertReset());
}
@Override
int get(int off) {
return in.get(off);
}
@Override
int previous(int off) {
return in.previous(off);
}
@Override
boolean assertReset() {
throw new UnsupportedOperationException();
}
}
private void doTest(byte[] data, LZ4.HashTable hashTable) throws IOException {
int offset = random().nextBoolean()
? random().nextInt(10)

View File

@ -22,7 +22,8 @@ public class TestFastLZ4 extends LZ4TestCase {
@Override
protected HashTable newHashTable() {
return new LZ4.FastCompressionHashTable();
LZ4.HashTable hashTable = new LZ4.FastCompressionHashTable();
return new AssertingHashTable(hashTable);
}
}

View File

@ -22,7 +22,8 @@ public class TestHighLZ4 extends LZ4TestCase {
@Override
protected HashTable newHashTable() {
return new LZ4.HighCompressionHashTable();
LZ4.HashTable hashTable = new LZ4.HighCompressionHashTable();
return new AssertingHashTable(hashTable);
}
}