Java Code Examples for org.apache.lucene.codecs.Codec#setDefault()
The following examples show how to use
org.apache.lucene.codecs.Codec#setDefault() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseLiveDocsFormatTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); // set the default codec, so adding test cases to this isn't fragile savedCodec = Codec.getDefault(); Codec.setDefault(getCodec()); }
Example 2
Source File: TestRuleSetupAndRestoreClassEnv.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * After suite cleanup (always invoked). */ @Override protected void after() throws Exception { Codec.setDefault(savedCodec); InfoStream.setDefault(savedInfoStream); if (savedLocale != null) Locale.setDefault(savedLocale); if (savedTimeZone != null) TimeZone.setDefault(savedTimeZone); }
Example 3
Source File: BaseIndexFileFormatTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
public void setUp() throws Exception { super.setUp(); // set the default codec, so adding test cases to this isn't fragile savedCodec = Codec.getDefault(); Codec.setDefault(getCodec()); }
Example 4
Source File: BaseIndexFileFormatTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
public void tearDown() throws Exception { Codec.setDefault(savedCodec); // restore super.tearDown(); }
Example 5
Source File: BaseIndexFileFormatTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
/** Test the accuracy of the ramBytesUsed estimations. */ @Nightly public void testRamBytesUsed() throws IOException { if (Codec.getDefault() instanceof RandomCodec) { // this test relies on the fact that two segments will be written with // the same codec so we need to disable MockRandomPF final Set<String> avoidCodecs = new HashSet<>(((RandomCodec) Codec.getDefault()).avoidCodecs); avoidCodecs.add(new MockRandomPostingsFormat().getName()); Codec.setDefault(new RandomCodec(random(), avoidCodecs)); } Directory dir = applyCreatedVersionMajor(newDirectory()); IndexWriterConfig cfg = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriter w = new IndexWriter(dir, cfg); // we need to index enough documents so that constant overhead doesn't dominate final int numDocs = atLeast(10000); LeafReader reader1 = null; for (int i = 0; i < numDocs; ++i) { Document d = new Document(); addRandomFields(d); w.addDocument(d); if (i == 100) { w.forceMerge(1); w.commit(); reader1 = getOnlyLeafReader(DirectoryReader.open(dir)); } } w.forceMerge(1); w.commit(); w.close(); LeafReader reader2 = getOnlyLeafReader(DirectoryReader.open(dir)); for (LeafReader reader : Arrays.asList(reader1, reader2)) { new SimpleMergedSegmentWarmer(InfoStream.NO_OUTPUT).warm(reader); } long act1 = RamUsageTester.sizeOf(reader2, new Accumulator(reader2)); long act2 = RamUsageTester.sizeOf(reader1, new Accumulator(reader1)); final long measuredBytes = act1 - act2; long reported1 = ((SegmentReader) reader2).ramBytesUsed(); long reported2 = ((SegmentReader) reader1).ramBytesUsed(); final long reportedBytes = reported1 - reported2; final long absoluteError = Math.abs(measuredBytes - reportedBytes); final double relativeError = (double) absoluteError / measuredBytes; final String message = String.format(Locale.ROOT, "RamUsageTester reports %d bytes but ramBytesUsed() returned %d (%.1f error). " + " [Measured: %d, %d. Reported: %d, %d]", measuredBytes, reportedBytes, (100 * relativeError), act1, act2, reported1, reported2); assertTrue(message, relativeError < 0.20d || absoluteError < 1000); reader1.close(); reader2.close(); dir.close(); }
Example 6
Source File: BaseLiveDocsFormatTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void tearDown() throws Exception { Codec.setDefault(savedCodec); // restore super.tearDown(); }