/** * Looks up the Directory adapter if it's already known, or attempts to initialize indexes. */ private DirectoryLoaderAdaptor getDirectory(final String indexName) { DirectoryLoaderAdaptor adapter = openDirectories.get(indexName); if (adapter == null) { synchronized (openDirectories) { adapter = openDirectories.get(indexName); if (adapter == null) { final File path = new File(this.rootDirectory, indexName); final FSDirectory directory = openLuceneDirectory(path); adapter = new DirectoryLoaderAdaptor(directory, indexName, autoChunkSize, affinitySegmentId); openDirectories.put(indexName, adapter); } } } return adapter; }
/** * Looks up the Directory adapter if it's already known, or attempts to initialize indexes. */ private DirectoryLoaderAdaptor getDirectory(final String indexName) { DirectoryLoaderAdaptor adapter = openDirectories.get(indexName); if (adapter == null) { synchronized (openDirectories) { adapter = openDirectories.get(indexName); if (adapter == null) { final File path = new File(this.rootDirectory, indexName); final FSDirectory directory = openLuceneDirectory(path); adapter = new DirectoryLoaderAdaptor(directory, indexName, autoChunkSize, affinitySegmentId); openDirectories.put(indexName, adapter); } } } return adapter; }
/** * Looks up the Directory adapter if it's already known, or attempts to initialize indexes. */ private DirectoryLoaderAdaptor getDirectory(final String indexName) { DirectoryLoaderAdaptor adapter = openDirectories.get(indexName); if (adapter == null) { synchronized (openDirectories) { adapter = openDirectories.get(indexName); if (adapter == null) { final File path = new File(this.rootDirectory, indexName); final FSDirectory directory = openLuceneDirectory(path); final InternalDirectoryContract wrapped = ContractAdaptorFactory.wrapNativeDirectory(directory); adapter = new DirectoryLoaderAdaptor(wrapped, indexName, autoChunkSize); openDirectories.put(indexName, adapter); } } } return adapter; }
public void testAutoChunkingOnLargeFiles() throws IOException { Directory mockDirectory = createMockDirectory(); FileCacheKey k = new FileCacheKey(INDEX_NAME, FILE_NAME, segmentId); DirectoryLoaderAdaptor adaptor = new DirectoryLoaderAdaptor(mockDirectory, INDEX_NAME, AUTO_BUFFER, -1); Object loaded = adaptor.load(k); AssertJUnit.assertTrue(loaded instanceof FileMetadata); FileMetadata metadata = (FileMetadata)loaded; AssertJUnit.assertEquals(TEST_SIZE, metadata.getSize()); AssertJUnit.assertEquals(AUTO_BUFFER, metadata.getBufferSize()); }
public void testSmallChunkLoading() throws IOException { Directory mockDirectory = createMockDirectory(); DirectoryLoaderAdaptor adaptor = new DirectoryLoaderAdaptor(mockDirectory, INDEX_NAME, AUTO_BUFFER, -1); Object loaded = adaptor.load(new ChunkCacheKey(INDEX_NAME, FILE_NAME, 0, AUTO_BUFFER, segmentId)); AssertJUnit.assertTrue(loaded instanceof byte[]); AssertJUnit.assertEquals(AUTO_BUFFER, ((byte[])loaded).length); loaded = adaptor.load(new ChunkCacheKey(INDEX_NAME, FILE_NAME, 5, AUTO_BUFFER, segmentId)); AssertJUnit.assertTrue(loaded instanceof byte[]); AssertJUnit.assertEquals(AUTO_BUFFER, ((byte[])loaded).length); final int lastChunk = (int)(TEST_SIZE / AUTO_BUFFER); final long lastChunkSize = TEST_SIZE % AUTO_BUFFER; AssertJUnit.assertEquals(9, lastChunkSize); loaded = adaptor.load(new ChunkCacheKey(INDEX_NAME, FILE_NAME, lastChunk, AUTO_BUFFER, segmentId)); AssertJUnit.assertTrue(loaded instanceof byte[]); AssertJUnit.assertEquals(lastChunkSize, ((byte[])loaded).length); }