use of org.apache.solr.client.solrj.embedded.EmbeddedSolrServer in project lucene-solr by apache.
the class TestRandomCollapseQParserPlugin method buildIndexAndClient.
@BeforeClass
public static void buildIndexAndClient() throws Exception {
initCore("solrconfig-minimal.xml", "schema-sorts.xml");
final int totalDocs = atLeast(500);
for (int i = 1; i <= totalDocs; i++) {
SolrInputDocument doc = CursorPagingTest.buildRandomDocument(i);
// every doc will be in the same group for this (string) field
doc.addField("same_for_all_docs", "xxx");
assertU(adoc(doc));
}
assertU(commit());
// Don't close this client, it would shutdown the CoreContainer
SOLR = new EmbeddedSolrServer(h.getCoreContainer(), h.coreName);
ALL_SORT_FIELD_NAMES = CursorPagingTest.pruneAndDeterministicallySort(h.getCore().getLatestSchema().getFields().keySet());
ALL_COLLAPSE_FIELD_NAMES = new ArrayList<String>(ALL_SORT_FIELD_NAMES.size());
for (String candidate : ALL_SORT_FIELD_NAMES) {
if (candidate.startsWith("str") || candidate.startsWith("float") || candidate.startsWith("int")) {
ALL_COLLAPSE_FIELD_NAMES.add(candidate);
}
}
}
use of org.apache.solr.client.solrj.embedded.EmbeddedSolrServer in project lucene-solr by apache.
the class TestInPlaceUpdatesStandalone method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
System.setProperty("solr.tests.intClassName", random().nextBoolean() ? "TrieIntField" : "IntPointField");
System.setProperty("solr.tests.longClassName", random().nextBoolean() ? "TrieLongField" : "LongPointField");
System.setProperty("solr.tests.floatClassName", random().nextBoolean() ? "TrieFloatField" : "FloatPointField");
System.setProperty("solr.tests.doubleClassName", random().nextBoolean() ? "TrieDoubleField" : "DoublePointField");
// we need consistent segments that aren't re-ordered on merge because we're
// asserting inplace updates happen by checking the internal [docid]
systemSetPropertySolrTestsMergePolicyFactory(NoMergePolicyFactory.class.getName());
initCore("solrconfig-tlog.xml", "schema-inplace-updates.xml");
// sanity check that autocommits are disabled
assertEquals(-1, h.getCore().getSolrConfig().getUpdateHandlerInfo().autoCommmitMaxTime);
assertEquals(-1, h.getCore().getSolrConfig().getUpdateHandlerInfo().autoSoftCommmitMaxTime);
assertEquals(-1, h.getCore().getSolrConfig().getUpdateHandlerInfo().autoCommmitMaxDocs);
assertEquals(-1, h.getCore().getSolrConfig().getUpdateHandlerInfo().autoSoftCommmitMaxDocs);
// assert that NoMergePolicy was chosen
RefCounted<IndexWriter> iw = h.getCore().getSolrCoreState().getIndexWriter(h.getCore());
try {
IndexWriter writer = iw.get();
assertTrue("Actual merge policy is: " + writer.getConfig().getMergePolicy(), writer.getConfig().getMergePolicy() instanceof NoMergePolicy);
} finally {
iw.decref();
}
// validate that the schema was not changed to an unexpected state
IndexSchema schema = h.getCore().getLatestSchema();
for (String fieldName : Arrays.asList("_version_", "inplace_l_dvo", "inplace_updatable_float", "inplace_updatable_int", "inplace_updatable_float_with_default", "inplace_updatable_int_with_default")) {
// these fields must only be using docValues to support inplace updates
SchemaField field = schema.getField(fieldName);
assertTrue(field.toString(), field.hasDocValues() && !field.indexed() && !field.stored());
}
for (String fieldName : Arrays.asList("title_s", "regular_l", "stored_i")) {
// these fields must support atomic updates, but not inplace updates (ie: stored)
SchemaField field = schema.getField(fieldName);
assertTrue(field.toString(), field.stored());
}
// Don't close this client, it would shutdown the CoreContainer
client = new EmbeddedSolrServer(h.getCoreContainer(), h.coreName);
}
use of org.apache.solr.client.solrj.embedded.EmbeddedSolrServer in project lucene-solr by apache.
the class SolrJettyTestBase method createNewSolrClient.
/**
* Create a new solr client.
* If createJetty was called, an http implementation will be created,
* otherwise an embedded implementation will be created.
* Subclasses should override for other options.
*/
public SolrClient createNewSolrClient() {
if (jetty != null) {
try {
// setup the client...
String url = jetty.getBaseUrl().toString() + "/" + "collection1";
HttpSolrClient client = getHttpSolrClient(url);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
} else {
return new EmbeddedSolrServer(h.getCoreContainer(), "collection1") {
@Override
public void close() {
// do not close core container
}
};
}
}
use of org.apache.solr.client.solrj.embedded.EmbeddedSolrServer in project stanbol by apache.
the class RegisteredSolrServerTracker method addingService.
@Override
public SolrServer addingService(ServiceReference reference) {
log.info(" ... in addingService for {} (ref: {})", this.reference, reference);
String coreName;
CoreContainer server;
Object service = super.addingService(reference);
if (service == null) {
log.warn("addingService({}) returned null -> unable to create " + "EmbeddedSolrServer for IndexReference {}", reference, this.reference);
}
if (trackingSolrCore) {
SolrCore core;
//might not be the same as for this classloader
if (service instanceof SolrCore) {
core = (SolrCore) service;
} else {
log.warn("SolrCore fitting to IndexReference {} is incompatible to the" + "classloader of bundle [{}]{} - Service [{}] ignored!", new Object[] { reference, context.getBundle().getBundleId(), context.getBundle().getSymbolicName() }, reference.getProperty(Constants.SERVICE_ID));
context.ungetService(reference);
return null;
}
coreName = core.getName();
CoreDescriptor descriptor = core.getCoreDescriptor();
if (descriptor == null) {
//core not registered with a container!
context.ungetService(reference);
//ignore
return null;
} else {
server = descriptor.getCoreContainer();
}
} else {
if (service instanceof CoreContainer) {
server = (CoreContainer) service;
} else {
log.warn("Solr CoreContainer fitting to IndexReference {} is incompatible to the" + "classloader of bundle [{}]{} - Service [{}] ignored!", new Object[] { reference, context.getBundle().getBundleId(), context.getBundle().getSymbolicName() }, reference.getProperty(Constants.SERVICE_ID));
context.ungetService(reference);
return null;
}
coreName = this.coreName;
}
return new EmbeddedSolrServer(server, coreName);
}
use of org.apache.solr.client.solrj.embedded.EmbeddedSolrServer in project stanbol by apache.
the class SolrYardIndexingDestination method initialise.
@Override
public void initialise() {
log.info("initialise {}", getClass().getSimpleName());
//The constructors and the setConfiguration(..) only validate the parsed
//parameters and initialise the member variables. This method performs
//the the actual initialisation of the SolrYard!
//copy a custom configuration (if present)
EmbeddedSolrServer server;
IndexReference solrServerRef = IndexReference.parse(solrYardConfig.getSolrServerLocation());
if (solrIndexConfig != null) {
//copy the configuration
try {
log.info(" ... copy Solr Configuration form {} to {}", solrIndexConfig, solrIndexLocation);
FileUtils.copyDirectory(solrIndexConfig, solrIndexLocation);
} catch (IOException e) {
throw new IllegalStateException(String.format("Unable to copy the Solr index configuration from %s to %s!", solrIndexConfig, solrIndexLocation), e);
}
solrYardConfig.setAllowInitialisation(Boolean.FALSE);
server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrServerRef, solrServerRef.getIndex());
this.core = server.getCoreContainer().getCore(solrServerRef.getIndex());
} else {
//allow the default initialisation
solrYardConfig.setAllowInitialisation(Boolean.TRUE);
StandaloneEmbeddedSolrServerProvider.getInstance();
server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrServerRef, solrYardConfig.getIndexConfigurationName());
if (server != null) {
log.info(" ... initialised SolrCore with default configuration");
this.core = server.getCoreContainer().getCore(solrServerRef.getIndex());
} else if (solrServerRef.isPath() && new File(solrServerRef.getIndex()).isAbsolute()) {
//the parsed absolute path is not within the managed SolrServer
//so we need to create some CoreContainer and init/register
//the core at the parsed location
StandaloneManagedSolrServer s;
if (solrServerRef.getServer() == null) {
s = StandaloneManagedSolrServer.getManagedServer();
} else {
s = StandaloneManagedSolrServer.getManagedServer(solrServerRef.getServer());
}
CoreContainer cc = s.getCoreContainer();
CoreDescriptor cd = new CoreDescriptor(cc, "dummy", solrServerRef.getIndex());
this.core = cc.create(cd);
cc.register(core, false);
server = new EmbeddedSolrServer(cc, "dummy");
log.info(" ... initialised existing SolrCore at {}", solrServerRef.getIndex());
} else {
throw new IllegalStateException("Unable to initialise SolrCore " + solrServerRef);
}
}
log.info(" ... create SolrYard");
this.solrYard = new SolrYard(server, solrYardConfig, namespacePrefixService);
}
Aggregations