Java Code Examples for org.apache.lucene.util.StringHelper#randomId()
The following examples show how to use
org.apache.lucene.util.StringHelper#randomId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseSegmentInfoFormatTestCase.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Tests SI writer adds itself to files... */ public void testAddsSelfToFiles() throws Exception { Directory dir = newDirectory(); Codec codec = getCodec(); byte id[] = StringHelper.randomId(); SegmentInfo info = new SegmentInfo(dir, getVersions()[0], getVersions()[0], "_123", 1, false, codec, Collections.emptyMap(), id, Collections.emptyMap(), null); Set<String> originalFiles = Collections.singleton("_123.a"); info.setFiles(originalFiles); codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT); Set<String> modifiedFiles = info.files(); assertTrue(modifiedFiles.containsAll(originalFiles)); assertTrue("did you forget to add yourself to files()", modifiedFiles.size() > originalFiles.size()); SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT); assertEquals(info.files(), info2.files()); // files set should be immutable expectThrows(UnsupportedOperationException.class, () -> { info2.files().add("bogus"); }); dir.close(); }
Example 2
Source File: BaseSegmentInfoFormatTestCase.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Test diagnostics map */ public void testDiagnostics() throws Exception { Directory dir = newDirectory(); Codec codec = getCodec(); byte id[] = StringHelper.randomId(); Map<String,String> diagnostics = new HashMap<>(); diagnostics.put("key1", "value1"); diagnostics.put("key2", "value2"); SegmentInfo info = new SegmentInfo(dir, getVersions()[0], getVersions()[0], "_123", 1, false, codec, diagnostics, id, Collections.emptyMap(), null); info.setFiles(Collections.<String>emptySet()); codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT); SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT); assertEquals(diagnostics, info2.getDiagnostics()); // diagnostics map should be immutable expectThrows(UnsupportedOperationException.class, () -> { info2.getDiagnostics().put("bogus", "bogus"); }); dir.close(); }
Example 3
Source File: BaseSegmentInfoFormatTestCase.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Test attributes map */ public void testAttributes() throws Exception { Directory dir = newDirectory(); Codec codec = getCodec(); byte id[] = StringHelper.randomId(); Map<String,String> attributes = new HashMap<>(); attributes.put("key1", "value1"); attributes.put("key2", "value2"); SegmentInfo info = new SegmentInfo(dir, getVersions()[0], getVersions()[0], "_123", 1, false, codec, Collections.emptyMap(), id, attributes, null); info.setFiles(Collections.<String>emptySet()); codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT); SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT); assertEquals(attributes, info2.getAttributes()); // attributes map should be immutable expectThrows(UnsupportedOperationException.class, () -> { info2.getAttributes().put("bogus", "bogus"); }); dir.close(); }
Example 4
Source File: BaseSegmentInfoFormatTestCase.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Test versions */ public void testVersions() throws Exception { Codec codec = getCodec(); for (Version v : getVersions()) { for (Version minV : new Version[] { v, null}) { Directory dir = newDirectory(); byte id[] = StringHelper.randomId(); SegmentInfo info = new SegmentInfo(dir, v, minV, "_123", 1, false, codec, Collections.<String,String>emptyMap(), id, Collections.emptyMap(), null); info.setFiles(Collections.<String>emptySet()); codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT); SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT); assertEquals(info2.getVersion(), v); if (supportsMinVersion()) { assertEquals(info2.getMinVersion(), minV); } else { assertEquals(info2.getMinVersion(), null); } dir.close(); } } }
Example 5
Source File: TestCodecUtil.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testWriteVeryLongSuffix() throws Exception { StringBuilder justLongEnough = new StringBuilder(); for (int i = 0; i < 255; i++) { justLongEnough.append('a'); } ByteBuffersDataOutput out = new ByteBuffersDataOutput(); IndexOutput output = new ByteBuffersIndexOutput(out, "temp", "temp"); byte[] id = StringHelper.randomId(); CodecUtil.writeIndexHeader(output, "foobar", 5, id, justLongEnough.toString()); output.close(); IndexInput input = new ByteBuffersIndexInput(out.toDataInput(), "temp"); CodecUtil.checkIndexHeader(input, "foobar", 5, 5, id, justLongEnough.toString()); assertEquals(input.getFilePointer(), input.length()); assertEquals(input.getFilePointer(), CodecUtil.indexHeaderLength("foobar", justLongEnough.toString())); input.close(); }
Example 6
Source File: TestSegmentInfos.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testVersionsOneSegment() throws IOException { BaseDirectoryWrapper dir = newDirectory(); dir.setCheckIndexOnClose(false); byte id[] = StringHelper.randomId(); Codec codec = Codec.getDefault(); SegmentInfos sis = new SegmentInfos(Version.LATEST.major); SegmentInfo info = new SegmentInfo(dir, Version.LUCENE_9_0_0, Version.LUCENE_9_0_0, "_0", 1, false, Codec.getDefault(), Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null); info.setFiles(Collections.<String>emptySet()); codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT); SegmentCommitInfo commitInfo = new SegmentCommitInfo(info, 0, 0, -1, -1, -1, StringHelper.randomId()); sis.add(commitInfo); sis.commit(dir); sis = SegmentInfos.readLatestCommit(dir); assertEquals(Version.LUCENE_9_0_0, sis.getMinSegmentLuceneVersion()); assertEquals(Version.LATEST, sis.getCommitLuceneVersion()); dir.close(); }
Example 7
Source File: BaseMergePolicyTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Make a new {@link SegmentCommitInfo} with the given {@code maxDoc}, * {@code numDeletedDocs} and {@code sizeInBytes}, which are usually the * numbers that merge policies care about. */ protected static SegmentCommitInfo makeSegmentCommitInfo(String name, int maxDoc, int numDeletedDocs, double sizeMB, String source) { if (name.startsWith("_") == false) { throw new IllegalArgumentException("name must start with an _, got " + name); } byte[] id = new byte[StringHelper.ID_LENGTH]; random().nextBytes(id); SegmentInfo info = new SegmentInfo(FAKE_DIRECTORY, Version.LATEST, Version.LATEST, name, maxDoc, false, TestUtil.getDefaultCodec(), Collections.emptyMap(), id, Collections.singletonMap(IndexWriter.SOURCE, source), null); info.setFiles(Collections.singleton(name + "_size=" + Long.toString((long) (sizeMB * 1024 * 1024)) + ".fake")); return new SegmentCommitInfo(info, numDeletedDocs, 0, 0, 0, 0, StringHelper.randomId()); }
Example 8
Source File: TestPendingDeletes.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testDeleteDoc() throws IOException { Directory dir = new ByteBuffersDirectory(); SegmentInfo si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "test", 10, false, Codec.getDefault(), Collections.emptyMap(), StringHelper.randomId(), new HashMap<>(), null); SegmentCommitInfo commitInfo = new SegmentCommitInfo(si, 0, 0, -1, -1, -1, StringHelper.randomId()); PendingDeletes deletes = newPendingDeletes(commitInfo); assertNull(deletes.getLiveDocs()); int docToDelete = TestUtil.nextInt(random(), 0, 7); assertTrue(deletes.delete(docToDelete)); assertNotNull(deletes.getLiveDocs()); assertEquals(1, deletes.numPendingDeletes()); Bits liveDocs = deletes.getLiveDocs(); assertFalse(liveDocs.get(docToDelete)); assertFalse(deletes.delete(docToDelete)); // delete again assertTrue(liveDocs.get(8)); assertTrue(deletes.delete(8)); assertTrue(liveDocs.get(8)); // we have a snapshot assertEquals(2, deletes.numPendingDeletes()); assertTrue(liveDocs.get(9)); assertTrue(deletes.delete(9)); assertTrue(liveDocs.get(9)); // now make sure new live docs see the deletions liveDocs = deletes.getLiveDocs(); assertFalse(liveDocs.get(9)); assertFalse(liveDocs.get(8)); assertFalse(liveDocs.get(docToDelete)); assertEquals(3, deletes.numPendingDeletes()); dir.close(); }
Example 9
Source File: TestSegmentInfos.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testIDChangesOnAdvance() throws IOException { try (BaseDirectoryWrapper dir = newDirectory()) { dir.setCheckIndexOnClose(false); byte id[] = StringHelper.randomId(); SegmentInfo info = new SegmentInfo(dir, Version.LUCENE_9_0_0, Version.LUCENE_9_0_0, "_0", 1, false, Codec.getDefault(), Collections.<String, String>emptyMap(), StringHelper.randomId(), Collections.<String, String>emptyMap(), null); SegmentCommitInfo commitInfo = new SegmentCommitInfo(info, 0, 0, -1, -1, -1, id); assertEquals(StringHelper.idToString(id), StringHelper.idToString(commitInfo.getId())); commitInfo.advanceDelGen(); assertNotEquals(StringHelper.idToString(id), StringHelper.idToString(commitInfo.getId())); id = commitInfo.getId(); commitInfo.advanceDocValuesGen(); assertNotEquals(StringHelper.idToString(id), StringHelper.idToString(commitInfo.getId())); id = commitInfo.getId(); commitInfo.advanceFieldInfosGen(); assertNotEquals(StringHelper.idToString(id), StringHelper.idToString(commitInfo.getId())); SegmentCommitInfo clone = commitInfo.clone(); id = commitInfo.getId(); assertEquals(StringHelper.idToString(id), StringHelper.idToString(commitInfo.getId())); assertEquals(StringHelper.idToString(id), StringHelper.idToString(clone.getId())); commitInfo.advanceFieldInfosGen(); assertNotEquals(StringHelper.idToString(id), StringHelper.idToString(commitInfo.getId())); assertEquals("clone changed but shouldn't", StringHelper.idToString(id), StringHelper.idToString(clone.getId())); } }
Example 10
Source File: TestSegmentInfos.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testVersionsTwoSegments() throws IOException { BaseDirectoryWrapper dir = newDirectory(); dir.setCheckIndexOnClose(false); byte id[] = StringHelper.randomId(); Codec codec = Codec.getDefault(); SegmentInfos sis = new SegmentInfos(Version.LATEST.major); SegmentInfo info = new SegmentInfo(dir, Version.LUCENE_9_0_0, Version.LUCENE_9_0_0, "_0", 1, false, Codec.getDefault(), Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null); info.setFiles(Collections.<String>emptySet()); codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT); SegmentCommitInfo commitInfo = new SegmentCommitInfo(info, 0, 0, -1, -1, -1, StringHelper.randomId()); sis.add(commitInfo); info = new SegmentInfo(dir, Version.LUCENE_9_0_0, Version.LUCENE_9_0_0, "_1", 1, false, Codec.getDefault(), Collections.<String,String>emptyMap(), id, Collections.<String,String>emptyMap(), null); info.setFiles(Collections.<String>emptySet()); codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT); commitInfo = new SegmentCommitInfo(info, 0, 0,-1, -1, -1, StringHelper.randomId()); sis.add(commitInfo); sis.commit(dir); byte[] commitInfoId0 = sis.info(0).getId(); byte[] commitInfoId1 = sis.info(1).getId(); sis = SegmentInfos.readLatestCommit(dir); assertEquals(Version.LUCENE_9_0_0, sis.getMinSegmentLuceneVersion()); assertEquals(Version.LATEST, sis.getCommitLuceneVersion()); assertEquals(StringHelper.idToString(commitInfoId0), StringHelper.idToString(sis.info(0).getId())); assertEquals(StringHelper.idToString(commitInfoId1), StringHelper.idToString(sis.info(1).getId())); dir.close(); }
Example 11
Source File: BaseCompoundFormatTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
/** Returns a new fake segment */ protected static SegmentInfo newSegmentInfo(Directory dir, String name) { Version minVersion = random().nextBoolean() ? null : Version.LATEST; return new SegmentInfo(dir, Version.LATEST, minVersion, name, 10000, false, Codec.getDefault(), Collections.emptyMap(), StringHelper.randomId(), Collections.emptyMap(), null); }
Example 12
Source File: TestIndexWriterThreadsToSegments.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testDocsStuckInRAMForever() throws Exception { Directory dir = newDirectory(); IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); iwc.setRAMBufferSizeMB(.2); Codec codec = TestUtil.getDefaultCodec(); iwc.setCodec(codec); iwc.setMergePolicy(NoMergePolicy.INSTANCE); final IndexWriter w = new IndexWriter(dir, iwc); final CountDownLatch startingGun = new CountDownLatch(1); Thread[] threads = new Thread[2]; for(int i=0;i<threads.length;i++) { final int threadID = i; threads[i] = new Thread() { @Override public void run() { try { startingGun.await(); for(int j=0;j<1000;j++) { Document doc = new Document(); doc.add(newStringField("field", "threadID" + threadID, Field.Store.NO)); w.addDocument(doc); } } catch (Exception e) { throw new RuntimeException(e); } } }; threads[i].start(); } startingGun.countDown(); for(Thread t : threads) { t.join(); } Set<String> segSeen = new HashSet<>(); int thread0Count = 0; int thread1Count = 0; // At this point the writer should have 2 thread states w/ docs; now we index with only 1 thread until we see all 1000 thread0 & thread1 // docs flushed. If the writer incorrectly holds onto previously indexed docs forever then this will run forever: long counter = 0; long checkAt = 100; while (thread0Count < 1000 || thread1Count < 1000) { Document doc = new Document(); doc.add(newStringField("field", "threadIDmain", Field.Store.NO)); w.addDocument(doc); if (counter++ == checkAt) { for(String fileName : dir.listAll()) { if (fileName.endsWith(".si")) { String segName = IndexFileNames.parseSegmentName(fileName); if (segSeen.contains(segName) == false) { segSeen.add(segName); byte id[] = readSegmentInfoID(dir, fileName); SegmentInfo si = TestUtil.getDefaultCodec().segmentInfoFormat().read(dir, segName, id, IOContext.DEFAULT); si.setCodec(codec); SegmentCommitInfo sci = new SegmentCommitInfo(si, 0, 0, -1, -1, -1, StringHelper.randomId()); SegmentReader sr = new SegmentReader(sci, Version.LATEST.major, IOContext.DEFAULT); try { thread0Count += sr.docFreq(new Term("field", "threadID0")); thread1Count += sr.docFreq(new Term("field", "threadID1")); } finally { sr.close(); } } } } checkAt = (long) (checkAt * 1.25); counter = 0; } } w.close(); dir.close(); }
Example 13
Source File: TestCodecs.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testFixedPostings() throws Throwable { final int NUM_TERMS = 100; final TermData[] terms = new TermData[NUM_TERMS]; for(int i=0;i<NUM_TERMS;i++) { final int[] docs = new int[] {i}; final String text = Integer.toString(i, Character.MAX_RADIX); terms[i] = new TermData(text, docs, null); } final FieldInfos.Builder builder = new FieldInfos.Builder(new FieldInfos.FieldNumbers(null)); final FieldData field = new FieldData("field", builder, terms, true, false); final FieldData[] fields = new FieldData[] {field}; final FieldInfos fieldInfos = builder.finish(); final Directory dir = newDirectory(); Codec codec = Codec.getDefault(); final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, SEGMENT, 10000, false, codec, Collections.emptyMap(), StringHelper.randomId(), new HashMap<>(), null); this.write(si, fieldInfos, dir, fields); final FieldsProducer reader = codec.postingsFormat().fieldsProducer(new SegmentReadState(dir, si, fieldInfos, newIOContext(random()))); final Iterator<String> fieldsEnum = reader.iterator(); String fieldName = fieldsEnum.next(); assertNotNull(fieldName); final Terms terms2 = reader.terms(fieldName); assertNotNull(terms2); final TermsEnum termsEnum = terms2.iterator(); PostingsEnum postingsEnum = null; for(int i=0;i<NUM_TERMS;i++) { final BytesRef term = termsEnum.next(); assertNotNull(term); assertEquals(terms[i].text2, term.utf8ToString()); // do this twice to stress test the codec's reuse, ie, // make sure it properly fully resets (rewinds) its // internal state: for(int iter=0;iter<2;iter++) { postingsEnum = TestUtil.docs(random(), termsEnum, postingsEnum, PostingsEnum.NONE); assertEquals(terms[i].docs[0], postingsEnum.nextDoc()); assertEquals(DocIdSetIterator.NO_MORE_DOCS, postingsEnum.nextDoc()); } } assertNull(termsEnum.next()); for(int i=0;i<NUM_TERMS;i++) { assertEquals(termsEnum.seekCeil(new BytesRef(terms[i].text2)), TermsEnum.SeekStatus.FOUND); } assertFalse(fieldsEnum.hasNext()); reader.close(); dir.close(); }
Example 14
Source File: TestSegmentInfos.java From lucene-solr with Apache License 2.0 | 4 votes |
/** Test toString method */ public void testToString() throws Throwable{ SegmentInfo si; final Directory dir = newDirectory(); Codec codec = Codec.getDefault(); // diagnostics map Map<String, String> diagnostics = Map.of("key1", "value1", "key2", "value2"); // attributes map Map<String,String> attributes = Map.of("akey1", "value1", "akey2", "value2"); // diagnostics X, attributes X si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "TEST", 10000, false, codec, Collections.emptyMap(), StringHelper.randomId(), new HashMap<>(), Sort.INDEXORDER); assertEquals("TEST(" + Version.LATEST.toString() + ")" + ":C10000" + ":[indexSort=<doc>]", si.toString()); // diagnostics O, attributes X si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "TEST", 10000, false, codec, diagnostics, StringHelper.randomId(), new HashMap<>(), Sort.INDEXORDER); assertEquals("TEST(" + Version.LATEST.toString() + ")" + ":C10000" + ":[indexSort=<doc>]" + ":[diagnostics=" + diagnostics + "]", si.toString()); // diagnostics X, attributes O si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "TEST", 10000, false, codec, Collections.emptyMap(), StringHelper.randomId(), attributes, Sort.INDEXORDER); assertEquals("TEST(" + Version.LATEST.toString() + ")" + ":C10000" + ":[indexSort=<doc>]" + ":[attributes=" + attributes + "]", si.toString()); // diagnostics O, attributes O si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "TEST", 10000, false, codec, diagnostics, StringHelper.randomId(), attributes, Sort.INDEXORDER); assertEquals("TEST(" + Version.LATEST.toString() + ")" + ":C10000" + ":[indexSort=<doc>]" + ":[diagnostics=" + diagnostics + "]" + ":[attributes=" + attributes + "]", si.toString()); dir.close(); }
Example 15
Source File: SegmentCommitInfo.java From lucene-solr with Apache License 2.0 | 4 votes |
private void generationAdvanced() { sizeInBytes = -1; id = StringHelper.randomId(); }
Example 16
Source File: TestSegmentMerger.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testMerge() throws IOException { final Codec codec = Codec.getDefault(); final SegmentInfo si = new SegmentInfo(mergedDir, Version.LATEST, null, mergedSegment, -1, false, codec, Collections.emptyMap(), StringHelper.randomId(), new HashMap<>(), null); SegmentMerger merger = new SegmentMerger(Arrays.<CodecReader>asList(reader1, reader2), si, InfoStream.getDefault(), mergedDir, new FieldInfos.FieldNumbers(null), newIOContext(random(), new IOContext(new MergeInfo(-1, -1, false, -1)))); MergeState mergeState = merger.merge(); int docsMerged = mergeState.segmentInfo.maxDoc(); assertTrue(docsMerged == 2); //Should be able to open a new SegmentReader against the new directory SegmentReader mergedReader = new SegmentReader(new SegmentCommitInfo( mergeState.segmentInfo, 0, 0, -1L, -1L, -1L, StringHelper.randomId()), Version.LATEST.major, newIOContext(random())); assertTrue(mergedReader != null); assertTrue(mergedReader.numDocs() == 2); Document newDoc1 = mergedReader.document(0); assertTrue(newDoc1 != null); //There are 2 unstored fields on the document assertTrue(DocHelper.numFields(newDoc1) == DocHelper.numFields(doc1) - DocHelper.unstored.size()); Document newDoc2 = mergedReader.document(1); assertTrue(newDoc2 != null); assertTrue(DocHelper.numFields(newDoc2) == DocHelper.numFields(doc2) - DocHelper.unstored.size()); PostingsEnum termDocs = TestUtil.docs(random(), mergedReader, DocHelper.TEXT_FIELD_2_KEY, new BytesRef("field"), null, 0); assertTrue(termDocs != null); assertTrue(termDocs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); int tvCount = 0; for(FieldInfo fieldInfo : mergedReader.getFieldInfos()) { if (fieldInfo.hasVectors()) { tvCount++; } } //System.out.println("stored size: " + stored.size()); assertEquals("We do not have 3 fields that were indexed with term vector", 3, tvCount); Terms vector = mergedReader.getTermVectors(0).terms(DocHelper.TEXT_FIELD_2_KEY); assertNotNull(vector); assertEquals(3, vector.size()); TermsEnum termsEnum = vector.iterator(); int i = 0; while (termsEnum.next() != null) { String term = termsEnum.term().utf8ToString(); int freq = (int) termsEnum.totalTermFreq(); //System.out.println("Term: " + term + " Freq: " + freq); assertTrue(DocHelper.FIELD_2_TEXT.indexOf(term) != -1); assertTrue(DocHelper.FIELD_2_FREQS[i] == freq); i++; } TestSegmentReader.checkNorms(mergedReader); mergedReader.close(); }
Example 17
Source File: TestPendingDeletes.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testWriteLiveDocs() throws IOException { Directory dir = new ByteBuffersDirectory(); SegmentInfo si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "test", 6, false, Codec.getDefault(), Collections.emptyMap(), StringHelper.randomId(), new HashMap<>(), null); SegmentCommitInfo commitInfo = new SegmentCommitInfo(si, 0, 0, -1, -1, -1, StringHelper.randomId()); PendingDeletes deletes = newPendingDeletes(commitInfo); assertFalse(deletes.writeLiveDocs(dir)); assertEquals(0, dir.listAll().length); boolean secondDocDeletes = random().nextBoolean(); deletes.delete(5); if (secondDocDeletes) { deletes.getLiveDocs(); deletes.delete(2); } assertEquals(-1, commitInfo.getDelGen()); assertEquals(0, commitInfo.getDelCount()); assertEquals(secondDocDeletes ? 2 : 1, deletes.numPendingDeletes()); assertTrue(deletes.writeLiveDocs(dir)); assertEquals(1, dir.listAll().length); Bits liveDocs = Codec.getDefault().liveDocsFormat().readLiveDocs(dir, commitInfo, IOContext.DEFAULT); assertFalse(liveDocs.get(5)); if (secondDocDeletes) { assertFalse(liveDocs.get(2)); } else { assertTrue(liveDocs.get(2)); } assertTrue(liveDocs.get(0)); assertTrue(liveDocs.get(1)); assertTrue(liveDocs.get(3)); assertTrue(liveDocs.get(4)); assertEquals(0, deletes.numPendingDeletes()); assertEquals(secondDocDeletes ? 2 : 1, commitInfo.getDelCount()); assertEquals(1, commitInfo.getDelGen()); deletes.delete(0); assertTrue(deletes.writeLiveDocs(dir)); assertEquals(2, dir.listAll().length); liveDocs = Codec.getDefault().liveDocsFormat().readLiveDocs(dir, commitInfo, IOContext.DEFAULT); assertFalse(liveDocs.get(5)); if (secondDocDeletes) { assertFalse(liveDocs.get(2)); } else { assertTrue(liveDocs.get(2)); } assertFalse(liveDocs.get(0)); assertTrue(liveDocs.get(1)); assertTrue(liveDocs.get(3)); assertTrue(liveDocs.get(4)); assertEquals(0, deletes.numPendingDeletes()); assertEquals(secondDocDeletes ? 3 : 2, commitInfo.getDelCount()); assertEquals(2, commitInfo.getDelGen()); dir.close(); }
Example 18
Source File: BootstrapProxy.java From crate with Apache License 2.0 | 4 votes |
/** * initialize native resources */ static void initializeNatives(boolean mlockAll, boolean ctrlHandler) { final Logger logger = LogManager.getLogger(BootstrapProxy.class); // check if the user is running as root, and bail if (Natives.definitelyRunningAsRoot()) { throw new RuntimeException("can not run crate as root"); } // mlockall if requested if (mlockAll) { if (Constants.WINDOWS) { Natives.tryVirtualLock(); } else { Natives.tryMlockall(); } } // listener for windows close event if (ctrlHandler) { Natives.addConsoleCtrlHandler(code -> { if (ConsoleCtrlHandler.CTRL_CLOSE_EVENT == code) { logger.info("running graceful exit on windows"); try { BootstrapProxy.stop(); } catch (IOException e) { throw new ElasticsearchException("failed to stop node", e); } return true; } return false; }); } // force remainder of JNA to be loaded (if available). try { JNAKernel32Library.getInstance(); } catch (Exception ignored) { // we've already logged this. } Natives.trySetMaxNumberOfThreads(); Natives.trySetMaxSizeVirtualMemory(); Natives.trySetMaxFileSize(); // init lucene random seed. it will use /dev/urandom where available: StringHelper.randomId(); }
Example 19
Source File: BaseFieldInfoFormatTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
/** Returns a new fake segment */ protected static SegmentInfo newSegmentInfo(Directory dir, String name) { Version minVersion = random().nextBoolean() ? null : Version.LATEST; return new SegmentInfo(dir, Version.LATEST, minVersion, name, 10000, false, Codec.getDefault(), Collections.emptyMap(), StringHelper.randomId(), Collections.emptyMap(), null); }
Example 20
Source File: Bootstrap.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** initialize native resources */ public static void initializeNatives(Path tmpFile, boolean mlockAll, boolean seccomp, boolean ctrlHandler) { final ESLogger logger = Loggers.getLogger(Bootstrap.class); // check if the user is running as root, and bail if (Natives.definitelyRunningAsRoot()) { if (Boolean.parseBoolean(System.getProperty("es.insecure.allow.root"))) { logger.warn("running as ROOT user. this is a bad idea!"); } else { throw new RuntimeException("don't run elasticsearch as root."); } } // enable secure computing mode if (seccomp) { Natives.trySeccomp(tmpFile); } // mlockall if requested if (mlockAll) { if (Constants.WINDOWS) { Natives.tryVirtualLock(); } else { Natives.tryMlockall(); } } // listener for windows close event if (ctrlHandler) { Natives.addConsoleCtrlHandler(new ConsoleCtrlHandler() { @Override public boolean handle(int code) { if (CTRL_CLOSE_EVENT == code) { logger.info("running graceful exit on windows"); Bootstrap.stop(); return true; } return false; } }); } // force remainder of JNA to be loaded (if available). try { JNAKernel32Library.getInstance(); } catch (Throwable ignored) { // we've already logged this. } // init lucene random seed. it will use /dev/urandom where available: StringHelper.randomId(); }