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

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

Introduction

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

Prototype

public Directory getSecondaryDir() 

Source Link

Document

Return the secondary 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  w w  w .j  a va2 s  .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());
    }
}