Skip to content

Commit

Permalink
Add back assertions removed by LUCENE-9187. (#1236)
Browse files Browse the repository at this point in the history
This time they would only apply to TestFastLZ4/TestHighLZ4 and avoid slowing
down all tests.
  • Loading branch information
jpountz authored Feb 14, 2020
1 parent dcf448e commit 5cbe58f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lucene/core/src/java/org/apache/lucene/util/compress/LZ4.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ static abstract class HashTable {
* 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();
}

/**
Expand Down Expand Up @@ -263,6 +266,11 @@ public int previous(int off) {
return -1;
}

@Override
boolean assertReset() {
return true;
}

}

/**
Expand Down Expand Up @@ -369,6 +377,14 @@ int previous(int off) {
}
return -1;
}

@Override
boolean assertReset() {
for (int i = 0; i < chainTable.length; ++i) {
assert chainTable[i] == (short) 0xFFFF : i;
}
return true;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 5cbe58f

Please # to comment.