Example usage for org.apache.lucene.store FileSwitchDirectory getPrimaryDir

List of usage examples for org.apache.lucene.store FileSwitchDirectory getPrimaryDir

Introduction

In this page you can find the example usage for org.apache.lucene.store FileSwitchDirectory getPrimaryDir.

Prototype

public Directory getPrimaryDir() 

Source Link

Document

Return the primary directory

Usage

From source file:org.elasticsearch.index.store.FsDirectoryServiceTests.java

License:Apache License

private void doTestPreload(String... preload) throws IOException {
    Settings build = Settings.builder().put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "mmapfs")
            .putArray(IndexModule.INDEX_STORE_PRE_LOAD_SETTING.getKey(), preload).build();
    IndexSettings settings = IndexSettingsModule.newIndexSettings("foo", build);
    IndexStoreConfig config = new IndexStoreConfig(settings.getSettings());
    IndexStore store = new IndexStore(settings, config);
    Path tempDir = createTempDir().resolve(settings.getUUID()).resolve("0");
    Files.createDirectories(tempDir);
    ShardPath path = new ShardPath(false, tempDir, tempDir, new ShardId(settings.getIndex(), 0));
    FsDirectoryService fsDirectoryService = new FsDirectoryService(settings, store, path);
    Directory directory = fsDirectoryService.newDirectory();
    assertTrue(directory instanceof RateLimitedFSDirectory);
    RateLimitedFSDirectory rateLimitingDirectory = (RateLimitedFSDirectory) directory;
    Directory delegate = rateLimitingDirectory.getDelegate();
    assertFalse(delegate instanceof SleepingLockWrapper);
    if (preload.length == 0) {
        assertTrue(delegate.toString(), delegate instanceof MMapDirectory);
        assertFalse(((MMapDirectory) delegate).getPreload());
    } else if (Arrays.asList(preload).contains("*")) {
        assertTrue(delegate.toString(), delegate instanceof MMapDirectory);
        assertTrue(((MMapDirectory) delegate).getPreload());
    } else {/*from ww  w.j a  v a 2s.com*/
        assertTrue(delegate.toString(), delegate instanceof FileSwitchDirectory);
        FileSwitchDirectory fsd = (FileSwitchDirectory) delegate;
        assertTrue(fsd.getPrimaryDir() instanceof MMapDirectory);
        assertTrue(((MMapDirectory) fsd.getPrimaryDir()).getPreload());
        assertTrue(fsd.getSecondaryDir() instanceof MMapDirectory);
        assertFalse(((MMapDirectory) fsd.getSecondaryDir()).getPreload());
    }
}