DocumentQueue implements Closeable, IndexingQueue { @Override public boolean add(LuceneDoc doc){ checkState(!stopped); boolean added = false; try { added = docsQueue.offer(doc, queueOfferTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } scheduleQueuedDocsProcessing(); if (added) { queueSizeStats.inc(); if (log.isTraceEnabled()){ log.trace("Adding {} to queue at size {}", doc, docsQueue.size()); } } else { dropped.mark(); } return added; } DocumentQueue(int maxQueueSize, IndexTracker tracker, Executor executor);  DocumentQueue(int maxQueueSize, long queueOfferTimeoutMillis, IndexTracker tracker, Executor executor, StatisticsProvider sp); @Override boolean addIfNotFullWithoutWait(LuceneDoc doc); @Override boolean add(LuceneDoc doc); @Override void scheduleQueuedDocsProcessing(); @Override void addAllSynchronously(Map<String, Collection<LuceneDoc>> docsPerIndex); void setExceptionHandler(UncaughtExceptionHandler delegate); @Override void close();  }
@Test public void dropDocOnLimit() throws Exception{ DocumentQueue queue = new DocumentQueue(2, tracker, NOOP_EXECUTOR); assertTrue(queue.add(LuceneDoc.forDelete("foo", "bar"))); assertTrue(queue.add(LuceneDoc.forDelete("foo", "bar"))); assertFalse(queue.add(LuceneDoc.forDelete("foo", "bar"))); }
@Test public void noIssueIfNoWriter() throws Exception{ NodeState indexed = createAndPopulateAsyncIndex(FulltextIndexConstants.IndexingMode.NRT); DocumentQueue queue = new DocumentQueue(2, tracker, sameThreadExecutor()); tracker.update(indexed); assertTrue(queue.add(LuceneDoc.forDelete("/oak:index/fooIndex", "bar"))); }
@Test public void updateDocument() throws Exception{ IndexTracker tracker = createTracker(); NodeState indexed = createAndPopulateAsyncIndex(FulltextIndexConstants.IndexingMode.NRT); tracker.update(indexed); DocumentQueue queue = new DocumentQueue(2, tracker, sameThreadExecutor()); Document d1 = new Document(); d1.add(newPathField("/a/b")); d1.add(new StringField("foo", "a", Field.Store.NO)); queue.add(LuceneDoc.forUpdate("/oak:index/fooIndex", "/a/b", d1)); List<NRTIndex> indexes = indexFactory.getIndexes("/oak:index/fooIndex"); NRTIndex index = indexes.get(indexes.size() - 1); assertEquals(1, index.getPrimaryReaderForTest().numDocs()); }