use of org.apache.lucene.store.BaseDirectoryWrapper in project lucene-solr by apache.
the class LuceneTestCase method wrapDirectory.
private static BaseDirectoryWrapper wrapDirectory(Random random, Directory directory, boolean bare) {
if (rarely(random) && !bare) {
directory = new NRTCachingDirectory(directory, random.nextDouble(), random.nextDouble());
}
if (bare) {
BaseDirectoryWrapper base = new RawDirectoryWrapper(directory);
closeAfterSuite(new CloseableDirectory(base, suiteFailureMarker));
return base;
} else {
MockDirectoryWrapper mock = new MockDirectoryWrapper(random, directory);
mock.setThrottling(TEST_THROTTLING);
closeAfterSuite(new CloseableDirectory(mock, suiteFailureMarker));
return mock;
}
}
use of org.apache.lucene.store.BaseDirectoryWrapper in project elasticsearch by elastic.
the class DirectoryUtilsTests method testGetLeave.
public void testGetLeave() throws IOException {
Path file = createTempDir();
final int iters = scaledRandomIntBetween(10, 100);
for (int i = 0; i < iters; i++) {
{
BaseDirectoryWrapper dir = newFSDirectory(file);
FSDirectory directory = DirectoryUtils.getLeaf(new FilterDirectory(dir) {
}, FSDirectory.class, null);
assertThat(directory, notNullValue());
assertThat(directory, sameInstance(DirectoryUtils.getLeafDirectory(dir, null)));
dir.close();
}
{
BaseDirectoryWrapper dir = newFSDirectory(file);
FSDirectory directory = DirectoryUtils.getLeaf(dir, FSDirectory.class, null);
assertThat(directory, notNullValue());
assertThat(directory, sameInstance(DirectoryUtils.getLeafDirectory(dir, null)));
dir.close();
}
{
Set<String> stringSet = Collections.emptySet();
BaseDirectoryWrapper dir = newFSDirectory(file);
FSDirectory directory = DirectoryUtils.getLeaf(new FileSwitchDirectory(stringSet, dir, dir, random().nextBoolean()), FSDirectory.class, null);
assertThat(directory, notNullValue());
assertThat(directory, sameInstance(DirectoryUtils.getLeafDirectory(dir, null)));
dir.close();
}
{
Set<String> stringSet = Collections.emptySet();
BaseDirectoryWrapper dir = newFSDirectory(file);
FSDirectory directory = DirectoryUtils.getLeaf(new FilterDirectory(new FileSwitchDirectory(stringSet, dir, dir, random().nextBoolean())) {
}, FSDirectory.class, null);
assertThat(directory, notNullValue());
assertThat(directory, sameInstance(DirectoryUtils.getLeafDirectory(dir, null)));
dir.close();
}
{
Set<String> stringSet = Collections.emptySet();
BaseDirectoryWrapper dir = newFSDirectory(file);
RAMDirectory directory = DirectoryUtils.getLeaf(new FilterDirectory(new FileSwitchDirectory(stringSet, dir, dir, random().nextBoolean())) {
}, RAMDirectory.class, null);
assertThat(directory, nullValue());
dir.close();
}
}
}
use of org.apache.lucene.store.BaseDirectoryWrapper in project lucene-solr by apache.
the class DataSplitterTest method assertSplit.
public static void assertSplit(LeafReader originalIndex, double testRatio, double crossValidationRatio, String... fieldNames) throws Exception {
BaseDirectoryWrapper trainingIndex = newDirectory();
BaseDirectoryWrapper testIndex = newDirectory();
BaseDirectoryWrapper crossValidationIndex = newDirectory();
try {
DatasetSplitter datasetSplitter = new DatasetSplitter(testRatio, crossValidationRatio);
datasetSplitter.split(originalIndex, trainingIndex, testIndex, crossValidationIndex, new MockAnalyzer(random()), true, classFieldName, fieldNames);
assertNotNull(trainingIndex);
assertNotNull(testIndex);
assertNotNull(crossValidationIndex);
DirectoryReader trainingReader = DirectoryReader.open(trainingIndex);
assertEquals((int) (originalIndex.maxDoc() * (1d - testRatio - crossValidationRatio)), trainingReader.maxDoc(), 20);
DirectoryReader testReader = DirectoryReader.open(testIndex);
assertEquals((int) (originalIndex.maxDoc() * testRatio), testReader.maxDoc(), 20);
DirectoryReader cvReader = DirectoryReader.open(crossValidationIndex);
assertEquals((int) (originalIndex.maxDoc() * crossValidationRatio), cvReader.maxDoc(), 20);
trainingReader.close();
testReader.close();
cvReader.close();
closeQuietly(trainingReader);
closeQuietly(testReader);
closeQuietly(cvReader);
} finally {
if (trainingIndex != null) {
trainingIndex.close();
}
if (testIndex != null) {
testIndex.close();
}
if (crossValidationIndex != null) {
crossValidationIndex.close();
}
}
}
use of org.apache.lucene.store.BaseDirectoryWrapper in project lucene-solr by apache.
the class TestSegmentInfos method testVersionsNoSegments.
// LUCENE-5954
public void testVersionsNoSegments() throws IOException {
SegmentInfos sis = new SegmentInfos(Version.LATEST.major);
BaseDirectoryWrapper dir = newDirectory();
dir.setCheckIndexOnClose(false);
sis.commit(dir);
sis = SegmentInfos.readLatestCommit(dir);
assertNull(sis.getMinSegmentLuceneVersion());
assertEquals(Version.LATEST, sis.getCommitLuceneVersion());
dir.close();
}
use of org.apache.lucene.store.BaseDirectoryWrapper in project lucene-solr by apache.
the class TestSegmentInfos method testVersionsOneSegment.
// LUCENE-5954
public void testVersionsOneSegment() throws IOException {
BaseDirectoryWrapper dir = newDirectory();
dir.setCheckIndexOnClose(false);
byte[] id = StringHelper.randomId();
Codec codec = Codec.getDefault();
SegmentInfos sis = new SegmentInfos(Version.LATEST.major);
SegmentInfo info = new SegmentInfo(dir, Version.LUCENE_7_0_0, Version.LUCENE_7_0_0, "_0", 1, false, Codec.getDefault(), Collections.<String, String>emptyMap(), id, Collections.<String, String>emptyMap(), null);
info.setFiles(Collections.<String>emptySet());
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
SegmentCommitInfo commitInfo = new SegmentCommitInfo(info, 0, -1, -1, -1);
sis.add(commitInfo);
sis.commit(dir);
sis = SegmentInfos.readLatestCommit(dir);
assertEquals(Version.LUCENE_7_0_0, sis.getMinSegmentLuceneVersion());
assertEquals(Version.LATEST, sis.getCommitLuceneVersion());
dir.close();
}
Aggregations