Fixed file cleanup for unit tests

This commit is contained in:
expani 2024-10-16 18:48:44 +05:30
parent 7312d91394
commit 359440a7dc
3 changed files with 13 additions and 9 deletions

View File

@ -456,8 +456,8 @@ public class DocIdEncodingBenchmark {
/** /**
* We want to load all the docId sequences completely in memory to avoid including the time * We want to load all the docId sequences completely in memory to avoid including the time
* spent in fetching from disk in every iteration unless we can consistently prove otherwise. * spent in fetching from disk or any other source in every iteration unless we can consistently
* <br> * prove otherwise. <br>
* *
* @param args : Data about the source of docId sequences depending on the underlying provider * @param args : Data about the source of docId sequences depending on the underlying provider
* like a file or randomly generated sequences given size. * like a file or randomly generated sequences given size.

View File

@ -36,7 +36,7 @@ public class TestDocIdEncoding extends LuceneTestCase {
super.setUp(); super.setUp();
} }
public void testBPV21AndAbove() { public void testBPV21AndAbove() throws IOException {
List<DocIdEncodingBenchmark.DocIdEncoder> encoders = List<DocIdEncodingBenchmark.DocIdEncoder> encoders =
DocIdEncodingBenchmark.DocIdEncoder.SingletonFactory.getAllExcept(Collections.emptyList()); DocIdEncodingBenchmark.DocIdEncoder.SingletonFactory.getAllExcept(Collections.emptyList());
@ -46,9 +46,11 @@ public class TestDocIdEncoding extends LuceneTestCase {
DocIdEncodingBenchmark.DocIdProvider docIdProvider = DocIdEncodingBenchmark.DocIdProvider docIdProvider =
new DocIdEncodingBenchmark.FixedBPVRandomDocIdProvider(); new DocIdEncodingBenchmark.FixedBPVRandomDocIdProvider();
Path tempDir = null;
try { try {
Path tempDir = Files.createTempDirectory("DocIdEncoding_testBPV21AndAbove_"); tempDir = Files.createTempDirectory("DocIdEncoding_testBPV21AndAbove_");
for (DocIdEncodingBenchmark.DocIdEncoder encoder : encoders) { for (DocIdEncodingBenchmark.DocIdEncoder encoder : encoders) {
@ -69,10 +71,14 @@ public class TestDocIdEncoding extends LuceneTestCase {
encoder.decode(in, 0, sequence.length, scratch); encoder.decode(in, 0, sequence.length, scratch);
assertArrayEquals(sequence, ArrayUtil.copyOfSubArray(scratch, 0, sequence.length)); assertArrayEquals(sequence, ArrayUtil.copyOfSubArray(scratch, 0, sequence.length));
} }
} finally {
Files.delete(tempDir.resolve(encoderFileName));
} }
} }
} catch (IOException e) { } finally {
throw new RuntimeException(e); if (tempDir != null) {
Files.delete(tempDir);
}
} }
} }
} }

View File

@ -41,7 +41,6 @@ final class DocIdsWriter {
private static final byte LEGACY_DELTA_VINT = (byte) 0; private static final byte LEGACY_DELTA_VINT = (byte) 0;
private static final long BPV_21_MASK = 0x1FFFFFL; private static final long BPV_21_MASK = 0x1FFFFFL;
private static final boolean IS_ARCH_64 = Constants.OS_ARCH.equals("aarch64"); private static final boolean IS_ARCH_64 = Constants.OS_ARCH.equals("aarch64");
private final int[] scratch; private final int[] scratch;
@ -312,8 +311,7 @@ final class DocIdsWriter {
// over // over
// org.apache.lucene.benchmark.jmh.DocIdEncodingBenchmark.DocIdEncoder.Bit21With2StepsEncoder // org.apache.lucene.benchmark.jmh.DocIdEncodingBenchmark.DocIdEncoder.Bit21With2StepsEncoder
// for decoding irrespective of architecture // for decoding irrespective of architecture
// due to it's better performance in benchmarks over nyc taxis, big5, http_logs and other // due to it's better performance in benchmarks like nyc taxis, big5, http_logs.
// popular search workloads.
for (; i < count - 8; i += 9) { for (; i < count - 8; i += 9) {
long l1 = in.readLong(); long l1 = in.readLong();
long l2 = in.readLong(); long l2 = in.readLong();