use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class TestIndexSearcher method testDontUseColdSearcher.
public void testDontUseColdSearcher() throws Exception {
MockSearchComponent.registerFirstSearcherListener = false;
MockSearchComponent.registerNewSearcherListener = false;
MockSearchComponent.registerSlowSearcherListener = true;
final AtomicBoolean querySucceeded = new AtomicBoolean(false);
SlowSearcherListener.numberOfTimesCalled = new AtomicInteger(0);
SlowSearcherListener.latch = new CountDownLatch(1);
CoreContainer cores = h.getCoreContainer();
CoreDescriptor cd = h.getCore().getCoreDescriptor();
final SolrCore newCore;
boolean coreCreated = false;
try {
// Create a new core, this should call all the firstSearcherListeners
newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
coreCreated = true;
//validate that the new core was created with the correct solrconfig
assertNotNull(newCore.getSearchComponent("mock"));
assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
assertFalse(newCore.getSolrConfig().useColdSearcher);
Thread t = new Thread() {
public void run() {
try {
doQuery(newCore);
querySucceeded.set(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
;
};
t.start();
if (System.getProperty(SYSPROP_NIGHTLY) != null) {
// even if we wait here, the SearcherListener should not finish
Thread.sleep(500);
}
// validate that the searcher warmer didn't finish yet.
assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
assertFalse("Query should be waiting for warming to finish", querySucceeded.get());
// Let warmer finish
SlowSearcherListener.latch.countDown();
// Validate that the query eventually succeeds
for (int i = 0; i <= 1000; i++) {
if (querySucceeded.get()) {
break;
}
if (i == 1000) {
fail("Query didn't succeed after 10 secoonds");
}
Thread.sleep(10);
}
} finally {
if (coreCreated) {
cores.unload("core1");
}
}
}
use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class ZkControllerTest method testGetHostName.
public void testGetHostName() throws Exception {
String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
CoreContainer cc = null;
ZkTestServer server = new ZkTestServer(zkDir);
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
cc = getCoreContainer();
ZkController zkController = null;
try {
CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build();
zkController = new ZkController(cc, server.getZkAddress(), TIMEOUT, cloudConfig, new CurrentCoreDescriptorProvider() {
@Override
public List<CoreDescriptor> getCurrentDescriptors() {
// do nothing
return null;
}
});
} catch (IllegalArgumentException e) {
fail("ZkController did not normalize host name correctly");
} finally {
if (zkController != null)
zkController.close();
}
} finally {
if (cc != null) {
cc.shutdown();
}
server.shutdown();
}
}
use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class SolrShardReporterTest method test.
@Test
public void test() throws Exception {
waitForRecoveriesToFinish("control_collection", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
waitForRecoveriesToFinish("collection1", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
printLayout();
// wait for at least two reports
Thread.sleep(10000);
ClusterState state = jettys.get(0).getCoreContainer().getZkController().getClusterState();
for (JettySolrRunner jetty : jettys) {
CoreContainer cc = jetty.getCoreContainer();
SolrMetricManager metricManager = cc.getMetricManager();
for (final String coreName : cc.getLoadedCoreNames()) {
CoreDescriptor cd = cc.getCoreDescriptor(coreName);
if (cd.getCloudDescriptor() == null) {
// not a cloud collection
continue;
}
CloudDescriptor cloudDesc = cd.getCloudDescriptor();
DocCollection docCollection = state.getCollection(cloudDesc.getCollectionName());
String replicaName = SolrCoreMetricManager.parseReplicaName(cloudDesc.getCollectionName(), coreName);
if (replicaName == null) {
replicaName = cloudDesc.getCoreNodeName();
}
String registryName = SolrCoreMetricManager.createRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId(), replicaName, null);
String leaderRegistryName = SolrCoreMetricManager.createLeaderRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId());
boolean leader = cloudDesc.isLeader();
Slice slice = docCollection.getSlice(cloudDesc.getShardId());
int numReplicas = slice.getReplicas().size();
if (leader) {
assertTrue(metricManager.registryNames() + " doesn't contain " + leaderRegistryName, metricManager.registryNames().contains(leaderRegistryName));
Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
metrics.forEach((k, v) -> {
assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
AggregateMetric am = (AggregateMetric) v;
if (!k.startsWith("REPLICATION.peerSync")) {
assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), numReplicas, am.size());
}
});
} else {
assertFalse(metricManager.registryNames() + " contains " + leaderRegistryName + " but it's not a leader!", metricManager.registryNames().contains(leaderRegistryName));
Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
metrics.forEach((k, v) -> {
assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
AggregateMetric am = (AggregateMetric) v;
if (!k.startsWith("REPLICATION.peerSync")) {
assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), 1, am.size());
}
});
}
assertTrue(metricManager.registryNames() + " doesn't contain " + registryName, metricManager.registryNames().contains(registryName));
}
}
SolrMetricManager metricManager = controlJetty.getCoreContainer().getMetricManager();
assertTrue(metricManager.registryNames().contains("solr.cluster"));
}
use of org.apache.solr.core.CoreDescriptor in project stanbol by apache.
the class EmbeddedSolrHelper method makeEmbeddedSolrServer.
/**
* Create a single core Solr server with it's own folder hierarchy.
*/
public static EmbeddedSolrServer makeEmbeddedSolrServer(File rootFolder, String solrServerId, String coreId, String configName) throws IOException, ParserConfigurationException, SAXException {
File solrFolder = new File(rootFolder, solrServerId);
FileUtils.deleteQuietly(solrFolder);
solrFolder.mkdir();
// solr conf file
File solrFile = new File(solrFolder, "solr.xml");
InputStream is = EmbeddedSolrHelper.class.getResourceAsStream("/solr.xml");
if (is == null) {
throw new IllegalArgumentException("missing test solr.xml file");
}
IOUtils.copy(is, new FileOutputStream(solrFile));
// solr conf folder with schema
File solrCoreFolder = new File(solrFolder, coreId);
solrCoreFolder.mkdir();
File solrConfFolder = new File(solrCoreFolder, "conf");
solrConfFolder.mkdir();
File schemaFile = new File(solrConfFolder, "schema.xml");
is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/schema.xml");
if (is == null) {
throw new IllegalArgumentException("missing test schema.xml file");
}
IOUtils.copy(is, new FileOutputStream(schemaFile));
File solrConfigFile = new File(solrConfFolder, "solrconfig.xml");
is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/solrconfig.xml");
if (is == null) {
throw new IllegalArgumentException("missing test solrconfig.xml file");
}
IOUtils.copy(is, new FileOutputStream(solrConfigFile));
// create the embedded server
SolrResourceLoader loader = new SolrResourceLoader(solrFolder.getAbsolutePath());
CoreContainer coreContainer = new CoreContainer(loader);
//NOTE: with Solr 4.4 we need to call coreContainer.load() otherwise we
//would be affected by the issue stated at
//http://mail-archives.apache.org/mod_mbox/lucene-solr-user/201301.mbox/%3CB7B8B36F1A0BE24F842758C318E56E925EB334%40EXCHDB2.na1.ad.group%3E
//while this was introduced with 4.1 this only affects this code with 4.4
//as with an API change the methods implicitly calling load() where
//removed.
coreContainer.load();
CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, coreId, solrCoreFolder.getAbsolutePath());
SolrCore core = coreContainer.create(coreDescriptor);
// coreContainer.createAndLoad(solrHome, configFile)load();
coreContainer.register(coreId, core, true);
return new EmbeddedSolrServer(coreContainer, coreId);
}
use of org.apache.solr.core.CoreDescriptor in project lucene-solr by apache.
the class SuggestComponentTest method reloadCore.
private void reloadCore(boolean createNewCore) throws Exception {
if (createNewCore) {
CoreContainer cores = h.getCoreContainer();
SolrCore core = h.getCore();
String dataDir1 = core.getDataDir();
CoreDescriptor cd = core.getCoreDescriptor();
h.close();
createCore();
SolrCore createdCore = h.getCore();
assertEquals(dataDir1, createdCore.getDataDir());
assertEquals(createdCore, h.getCore());
} else {
h.reload();
// On regular reloading, wait until the new searcher is registered
waitForWarming();
}
assertQ(req("qt", "standard", "q", "*:*"), "//*[@numFound='11']");
}
Aggregations