use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.
the class DefaultSolrIndexer method processBatch.
/**
* Process a batch of operations that were just read from the index operations queue. This method also commits the
* batch when it finishes to process it.
*
* @param queueEntry the batch to process
* @return {@code true} to wait for another batch, {@code false} to stop the indexing thread
*/
private boolean processBatch(IndexQueueEntry queueEntry) {
SolrInstance solrInstance = this.solrInstanceProvider.get();
int length = 0;
for (IndexQueueEntry batchEntry = queueEntry; batchEntry != null; batchEntry = this.indexQueue.poll()) {
if (batchEntry == INDEX_QUEUE_ENTRY_STOP) {
// Discard the current batch and stop the indexing thread.
return false;
}
IndexOperation operation = batchEntry.operation;
// For the current contiguous operations queue, group the changes
try {
this.ecim.initialize(new ExecutionContext());
if (IndexOperation.INDEX.equals(operation)) {
LengthSolrInputDocument solrDocument = getSolrDocument(batchEntry.reference);
if (solrDocument != null) {
solrInstance.add(solrDocument);
length += solrDocument.getLength();
++this.batchSize;
}
} else if (IndexOperation.DELETE.equals(operation)) {
if (batchEntry.reference == null) {
solrInstance.deleteByQuery(batchEntry.deleteQuery);
} else {
solrInstance.delete(this.solrRefereceResolver.getId(batchEntry.reference));
}
++this.batchSize;
}
} catch (Throwable e) {
this.logger.error("Failed to process entry [{}]", batchEntry, e);
} finally {
this.execution.removeContext();
}
// the reason why we perform it at the end of the batch.
if (shouldCommit(length, this.batchSize)) {
commit();
length = 0;
}
}
// Commit what's left
if (this.batchSize > 0) {
commit();
}
return true;
}
use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.
the class SolrDocumentIteratorTest method configure.
@Before
public void configure() throws Exception {
solr = mock(SolrInstance.class);
Provider<SolrInstance> solrInstanceProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, SolrInstance.class));
when(solrInstanceProvider.get()).thenReturn(solr);
this.solrDocumentReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class, SolrDocument.class));
}
use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.
the class SolrQueryExecutorTest method configure.
@Before
public void configure() throws Exception {
ParameterizedType solrProviderType = new DefaultParameterizedType(null, Provider.class, SolrInstance.class);
Provider<SolrInstance> provider = this.componentManager.registerMockComponent(solrProviderType);
when(provider.get()).thenReturn(this.solr);
}
use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.
the class EmbeddedSolrInstanceInitializationTest method getInstanceAndAssertHomeDirectory.
/**
* TODO DOCUMENT ME!
*
* @param expected
* @throws ComponentLookupException
* @throws Exception
*/
private void getInstanceAndAssertHomeDirectory(String expected) throws ComponentLookupException, Exception {
SolrInstance instance = mocker.getInstance(SolrInstance.class, "embedded");
Assert.assertNotNull(instance);
EmbeddedSolrInstance implementation = ((EmbeddedSolrInstance) instance);
CoreContainer container = implementation.getContainer();
if (expected == null) {
expected = implementation.getDefaultHomeDirectory();
}
Assert.assertEquals(expected, container.getSolrHome());
Assert.assertEquals(1, container.getCores().size());
SolrCore core = container.getCores().iterator().next();
File coreBaseDirectory = new File(container.getSolrHome(), core.getName());
File configDirectory = new File(coreBaseDirectory, DefaultSolrConfiguration.CONF_DIRECTORY);
Assert.assertTrue(new File(configDirectory, core.getSchemaResource()).exists());
Assert.assertTrue(new File(configDirectory, core.getConfigResource()).exists());
}
use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.
the class SolrInstanceProviderTest method testEmbeddedInstanceRetrieval.
@Test
public void testEmbeddedInstanceRetrieval() throws Exception {
when(this.mockConfig.getServerType()).thenReturn("embedded");
SolrInstance instance = this.mocker.getComponentUnderTest().get();
Assert.assertNotNull(instance);
Assert.assertSame(this.embedded, instance);
}
Aggregations