Example usage for org.apache.lucene.store NRTCachingDirectory getDelegate

List of usage examples for org.apache.lucene.store NRTCachingDirectory getDelegate

Introduction

In this page you can find the example usage for org.apache.lucene.store NRTCachingDirectory getDelegate.

Prototype

public final Directory getDelegate() 

Source Link

Document

Return the wrapped Directory .

Usage

From source file:org.apache.solr.cloud.hdfs.HdfsWriteToMultipleCollectionsTest.java

License:Apache License

@Override
public void doTest() throws Exception {
    int docCount = random().nextInt(1313) + 1;
    int cnt = random().nextInt(4) + 1;
    for (int i = 0; i < cnt; i++) {
        createCollection(ACOLLECTION + i, 2, 2, 9);
    }//from   w  w w  .j  a  va 2s.  c o m
    for (int i = 0; i < cnt; i++) {
        waitForRecoveriesToFinish(ACOLLECTION + i, false);
    }
    List<CloudSolrServer> cloudServers = new ArrayList<>();
    List<StopableIndexingThread> threads = new ArrayList<>();
    for (int i = 0; i < cnt; i++) {
        CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress());
        server.setDefaultCollection(ACOLLECTION + i);
        cloudServers.add(server);
        StopableIndexingThread indexThread = new StopableIndexingThread(null, server, "1", true, docCount);
        threads.add(indexThread);
        indexThread.start();
    }

    int addCnt = 0;
    for (StopableIndexingThread thread : threads) {
        thread.join();
        addCnt += thread.getNumAdds() - thread.getNumDeletes();
    }

    long collectionsCount = 0;
    for (CloudSolrServer server : cloudServers) {
        server.commit();
        collectionsCount += server.query(new SolrQuery("*:*")).getResults().getNumFound();
    }

    for (CloudSolrServer server : cloudServers) {
        server.shutdown();
    }

    assertEquals(addCnt, collectionsCount);

    BlockCache lastBlockCache = null;
    // assert that we are using the block directory and that write and read caching are being used
    for (JettySolrRunner jetty : jettys) {
        CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter().getFilter()).getCores();
        Collection<SolrCore> solrCores = cores.getCores();
        for (SolrCore core : solrCores) {
            if (core.getCoreDescriptor().getCloudDescriptor().getCollectionName().startsWith(ACOLLECTION)) {
                assertTrue(core.getDirectoryFactory() instanceof HdfsDirectoryFactory);
                RefCounted<IndexWriter> iwRef = core.getUpdateHandler().getSolrCoreState().getIndexWriter(core);
                try {
                    IndexWriter iw = iwRef.get();
                    NRTCachingDirectory directory = (NRTCachingDirectory) iw.getDirectory();
                    BlockDirectory blockDirectory = (BlockDirectory) directory.getDelegate();
                    assertTrue(blockDirectory.isBlockCacheReadEnabled());
                    assertTrue(blockDirectory.isBlockCacheWriteEnabled());
                    Cache cache = blockDirectory.getCache();
                    // we know its a BlockDirectoryCache, but future proof
                    assertTrue(cache instanceof BlockDirectoryCache);
                    BlockCache blockCache = ((BlockDirectoryCache) cache).getBlockCache();
                    if (lastBlockCache != null) {
                        if (Boolean.getBoolean(SOLR_HDFS_BLOCKCACHE_GLOBAL)) {
                            assertEquals(lastBlockCache, blockCache);
                        } else {
                            assertNotSame(lastBlockCache, blockCache);
                        }
                    }
                    lastBlockCache = blockCache;
                } finally {
                    iwRef.decref();
                }
            }
        }
    }
}