use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class SignatureUpdateProcessorFactoryTest method testDupeAllFieldsDetection.
@Test
public void testDupeAllFieldsDetection() throws Exception {
this.chain = "dedupe-allfields";
SolrCore core = h.getCore();
UpdateRequestProcessorChain chained = core.getUpdateProcessingChain(this.chain);
SignatureUpdateProcessorFactory factory = ((SignatureUpdateProcessorFactory) chained.getProcessors().get(0));
factory.setEnabled(true);
assertNotNull(chained);
addDoc(adoc("v_t", "Hello Dude man!"));
addDoc(adoc("v_t", "Hello Dude man!", "name", "name1'"));
addDoc(adoc("v_t", "Hello Dude man!", "name", "name2'"));
addDoc(commit());
checkNumDocs(3);
factory.setEnabled(false);
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class SignatureUpdateProcessorFactoryTest method testMultiThreaded.
@Test
public void testMultiThreaded() throws Exception {
UpdateRequestProcessorChain chained = h.getCore().getUpdateProcessingChain("dedupe");
SignatureUpdateProcessorFactory factory = ((SignatureUpdateProcessorFactory) chained.getProcessors().get(0));
factory.setEnabled(true);
Thread[] threads = null;
Thread[] threads2 = null;
threads = new Thread[7];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread() {
@Override
public void run() {
for (int i = 0; i < 30; i++) {
// "Goodbye Dude girl!"));
try {
addDoc(adoc("id", Integer.toString(1 + i), "v_t", "Goodbye Dude girl!"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
};
threads[i].setName("testThread-" + i);
}
threads2 = new Thread[3];
for (int i = 0; i < threads2.length; i++) {
threads2[i] = new Thread() {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
// h.update(commit());
try {
addDoc(adoc("id", Integer.toString(1 + i), "v_t", "Goodbye Dude girl!"));
addDoc(commit());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
};
threads2[i].setName("testThread2-" + i);
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
for (int i = 0; i < threads2.length; i++) {
threads2[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
for (int i = 0; i < threads2.length; i++) {
threads2[i].join();
}
SolrCore core = h.getCore();
assertU(commit());
checkNumDocs(1);
factory.setEnabled(false);
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class SignatureUpdateProcessorFactoryTest method testFailNonIndexedSigWithOverwriteDupes.
@Test
public void testFailNonIndexedSigWithOverwriteDupes() throws Exception {
SolrCore core = h.getCore();
SignatureUpdateProcessorFactory f = new SignatureUpdateProcessorFactory();
NamedList<String> initArgs = new NamedList<>();
initArgs.add("overwriteDupes", "true");
initArgs.add("signatureField", "signatureField_sS");
f.init(initArgs);
boolean exception_ok = false;
try {
f.inform(core);
} catch (Exception e) {
exception_ok = true;
}
assertTrue("Should have gotten an exception from inform(SolrCore)", exception_ok);
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class StatelessScriptUpdateProcessorFactoryTest method testMultipleScripts.
public void testMultipleScripts() throws Exception {
SolrCore core = h.getCore();
for (final String chain : new String[] { "dual-scripts-arr", "dual-scripts-strs" }) {
UpdateRequestProcessorChain chained = core.getUpdateProcessingChain(chain);
final StatelessScriptUpdateProcessorFactory factory = ((StatelessScriptUpdateProcessorFactory) chained.getProcessors().get(0));
final List<String> functionMessages = new ArrayList<>();
ScriptEngineCustomizer customizer = new ScriptEngineCustomizer() {
@Override
public void customize(ScriptEngine engine) {
engine.put("functionMessages", functionMessages);
}
};
factory.setScriptEngineCustomizer(customizer);
assertNotNull(chained);
SolrInputDocument d = processAdd(chain, doc(f("id", "2"), f("name", " foo "), f("subject", "bar")));
assertEquals(chain + " didn't add Double field", 42.3d, d.getFieldValue("script_added_d"));
assertEquals(chain + " didn't add integer field", new Integer(42), d.getFieldValue("script_added_i"));
processCommit("run-no-scripts");
assertQ(chain + ": couldn't find doc by id", req("q", "id:2"), "//result[@numFound=1]");
processDeleteById(chain, "2");
processCommit(chain);
assertEquals(chain, 6, functionMessages.size());
assertTrue(chain, functionMessages.contains("processAdd0"));
assertTrue(chain, functionMessages.contains("processAdd1"));
assertTrue(chain + ": script order doesn't match conf order", functionMessages.indexOf("processAdd0") < functionMessages.indexOf("processAdd1"));
assertTrue(chain, functionMessages.contains("processDelete0"));
assertTrue(chain, functionMessages.contains("processDelete1"));
assertTrue(chain + ": script order doesn't match conf order", functionMessages.indexOf("processDelete0") < functionMessages.indexOf("processDelete1"));
assertTrue(chain, functionMessages.contains("processCommit0"));
assertTrue(chain, functionMessages.contains("processCommit1"));
assertTrue(chain + ": script order doesn't match conf order", functionMessages.indexOf("processCommit0") < functionMessages.indexOf("processCommit1"));
finish(chain);
assertEquals(chain, 8, functionMessages.size());
assertTrue(chain, functionMessages.contains("finish0"));
assertTrue(chain, functionMessages.contains("finish1"));
assertTrue(chain + ": script order doesn't match conf order", functionMessages.indexOf("finish0") < functionMessages.indexOf("finish1"));
assertQ(chain + ": found deleted doc", req("q", "id:2"), "//result[@numFound=0]");
}
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method waitForReplicationFromReplicas.
protected void waitForReplicationFromReplicas(String collectionName, ZkStateReader zkStateReader, TimeOut timeout) throws KeeperException, InterruptedException, IOException {
zkStateReader.forceUpdateCollection(collectionName);
DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
Map<String, CoreContainer> containers = new HashMap<>();
for (JettySolrRunner runner : jettys) {
if (!runner.isRunning()) {
continue;
}
containers.put(runner.getNodeName(), runner.getCoreContainer());
}
for (Slice s : collection.getSlices()) {
Replica leader = s.getLeader();
long leaderIndexVersion = -1;
while (!timeout.hasTimedOut()) {
leaderIndexVersion = getIndexVersion(leader);
if (leaderIndexVersion >= 0) {
break;
}
Thread.sleep(1000);
}
if (timeout.hasTimedOut()) {
fail("Unable to get leader indexVersion");
}
for (Replica pullReplica : s.getReplicas(EnumSet.of(Replica.Type.PULL, Replica.Type.TLOG))) {
if (!zkStateReader.getClusterState().liveNodesContain(pullReplica.getNodeName())) {
continue;
}
while (true) {
long replicaIndexVersion = getIndexVersion(pullReplica);
if (leaderIndexVersion == replicaIndexVersion) {
log.debug("Leader replica's version ({}) in sync with replica({}): {} == {}", leader.getName(), pullReplica.getName(), leaderIndexVersion, replicaIndexVersion);
// Make sure the host is serving the correct version
try (SolrCore core = containers.get(pullReplica.getNodeName()).getCore(pullReplica.getCoreName())) {
RefCounted<SolrIndexSearcher> ref = core.getRegisteredSearcher();
try {
SolrIndexSearcher searcher = ref.get();
String servingVersion = searcher.getIndexReader().getIndexCommit().getUserData().get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
if (Long.parseLong(servingVersion) == replicaIndexVersion) {
break;
} else {
log.debug("Replica {} has the correct version replicated, but the searcher is not ready yet. Replicated version: {}, Serving version: {}", pullReplica.getName(), replicaIndexVersion, servingVersion);
}
} finally {
if (ref != null)
ref.decref();
}
}
} else {
if (timeout.hasTimedOut()) {
logReplicaTypesReplicationInfo(collectionName, zkStateReader);
fail(String.format(Locale.ROOT, "Timed out waiting for replica %s (%d) to replicate from leader %s (%d)", pullReplica.getName(), replicaIndexVersion, leader.getName(), leaderIndexVersion));
}
if (leaderIndexVersion > replicaIndexVersion) {
log.debug("{} version is {} and leader's is {}, will wait for replication", pullReplica.getName(), replicaIndexVersion, leaderIndexVersion);
} else {
log.debug("Leader replica's version ({}) is lower than pull replica({}): {} < {}", leader.getName(), pullReplica.getName(), leaderIndexVersion, replicaIndexVersion);
}
}
Thread.sleep(1000);
}
}
}
}
Aggregations