Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add back assertions removed by LUCENE-9187. #1236

Merged
merged 2 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}