use of org.apache.lucene.store.IndexOutput in project elasticsearch by elastic.
the class StoreRecoveryTests method testStatsDirWrapper.
public void testStatsDirWrapper() throws IOException {
Directory dir = newDirectory();
Directory target = newDirectory();
RecoveryState.Index indexStats = new RecoveryState.Index();
StoreRecovery.StatsDirectoryWrapper wrapper = new StoreRecovery.StatsDirectoryWrapper(target, indexStats);
try (IndexOutput output = dir.createOutput("foo.bar", IOContext.DEFAULT)) {
CodecUtil.writeHeader(output, "foo", 0);
int numBytes = randomIntBetween(100, 20000);
for (int i = 0; i < numBytes; i++) {
output.writeByte((byte) i);
}
CodecUtil.writeFooter(output);
}
wrapper.copyFrom(dir, "foo.bar", "bar.foo", IOContext.DEFAULT);
assertNotNull(indexStats.getFileDetails("bar.foo"));
assertNull(indexStats.getFileDetails("foo.bar"));
assertEquals(dir.fileLength("foo.bar"), indexStats.getFileDetails("bar.foo").length());
assertEquals(dir.fileLength("foo.bar"), indexStats.getFileDetails("bar.foo").recovered());
assertFalse(indexStats.getFileDetails("bar.foo").reused());
IOUtils.close(dir, target);
}
use of org.apache.lucene.store.IndexOutput in project elasticsearch by elastic.
the class StoreTests method testStoreStats.
public void testStoreStats() throws IOException {
final ShardId shardId = new ShardId("index", "_na_", 1);
DirectoryService directoryService = new LuceneManagedDirectoryService(random());
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), TimeValue.timeValueMinutes(0)).build();
Store store = new Store(shardId, IndexSettingsModule.newIndexSettings("index", settings), directoryService, new DummyShardLock(shardId));
long initialStoreSize = 0;
for (String extraFiles : store.directory().listAll()) {
assertTrue("expected extraFS file but got: " + extraFiles, extraFiles.startsWith("extra"));
initialStoreSize += store.directory().fileLength(extraFiles);
}
StoreStats stats = store.stats();
assertEquals(stats.getSize().getBytes(), initialStoreSize);
Directory dir = store.directory();
final long length;
try (IndexOutput output = dir.createOutput("foo.bar", IOContext.DEFAULT)) {
int iters = scaledRandomIntBetween(10, 100);
for (int i = 0; i < iters; i++) {
BytesRef bytesRef = new BytesRef(TestUtil.randomRealisticUnicodeString(random(), 10, 1024));
output.writeBytes(bytesRef.bytes, bytesRef.offset, bytesRef.length);
}
length = output.getFilePointer();
}
assertTrue(numNonExtraFiles(store) > 0);
stats = store.stats();
assertEquals(stats.getSizeInBytes(), length + initialStoreSize);
deleteContent(store.directory());
IOUtils.close(store);
}
use of org.apache.lucene.store.IndexOutput in project gerrit by GerritCodeReview.
the class QueryDocumentationExecutor method readIndexDirectory.
protected Directory readIndexDirectory() throws IOException {
Directory dir = new RAMDirectory();
byte[] buffer = new byte[4096];
InputStream index = getClass().getResourceAsStream(Constants.INDEX_ZIP);
if (index == null) {
log.warn("No index available");
return null;
}
try (ZipInputStream zip = new ZipInputStream(index)) {
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
try (IndexOutput out = dir.createOutput(entry.getName(), null)) {
int count;
while ((count = zip.read(buffer)) != -1) {
out.writeBytes(buffer, count);
}
}
}
}
// We must NOT call dir.close() here, as DirectoryReader.open() expects an opened directory.
return dir;
}
use of org.apache.lucene.store.IndexOutput in project zm-mailbox by Zimbra.
the class LuceneDirectoryTest method write.
@Test
public void write() throws IOException {
long count = ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.getCount();
long total = ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.getTotal();
LuceneDirectory dir = LuceneDirectory.open(new File("/tmp"));
IndexOutput out = dir.createOutput("write");
out.writeBytes(new byte[] { 0, 1, 2 }, 3);
out.close();
Assert.assertEquals(1, ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.getCount() - count);
Assert.assertEquals(3, ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.getTotal() - total);
}
use of org.apache.lucene.store.IndexOutput in project jackrabbit-oak by apache.
the class LuceneBlobCacheTest method assertWrites.
byte[] assertWrites(Directory dir, int blobSize) throws IOException {
byte[] data = randomBytes(blobSize);
IndexOutput o = dir.createOutput("test", IOContext.DEFAULT);
o.writeBytes(data, data.length);
o.close();
IndexInput i = dir.openInput("test", IOContext.DEFAULT);
assertEquals(blobSize, i.length());
byte[] result = new byte[blobSize];
i.readBytes(result, 0, result.length);
assertTrue(Arrays.equals(data, result));
// Load agagin to see if cached
i = dir.openInput("test", IOContext.DEFAULT);
assertEquals(blobSize, i.length());
result = new byte[blobSize];
i.readBytes(result, 0, result.length);
assertTrue(Arrays.equals(data, result));
assertEquals(1, fileDataStore.count);
return data;
}
Aggregations