Search in sources :

Example 66 with SolrCore

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);
}
Also used : SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 67 with SolrCore

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);
}
Also used : SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 68 with SolrCore

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);
}
Also used : SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) Test(org.junit.Test)

Example 69 with SolrCore

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]");
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrCore(org.apache.solr.core.SolrCore) ArrayList(java.util.ArrayList) ScriptEngine(javax.script.ScriptEngine)

Example 70 with SolrCore

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);
            }
        }
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) HashMap(java.util.HashMap) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) Slice(org.apache.solr.common.cloud.Slice) SolrCore(org.apache.solr.core.SolrCore) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) Replica(org.apache.solr.common.cloud.Replica)

Aggregations

SolrCore (org.apache.solr.core.SolrCore)254 Test (org.junit.Test)88 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)57 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)55 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)52 SolrException (org.apache.solr.common.SolrException)41 CoreContainer (org.apache.solr.core.CoreContainer)40 NamedList (org.apache.solr.common.util.NamedList)38 HashMap (java.util.HashMap)33 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)33 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)32 File (java.io.File)28 MapSolrParams (org.apache.solr.common.params.MapSolrParams)26 ArrayList (java.util.ArrayList)25 IOException (java.io.IOException)23 SolrParams (org.apache.solr.common.params.SolrParams)19 Map (java.util.Map)17 Replica (org.apache.solr.common.cloud.Replica)17 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)15 SolrInputDocument (org.apache.solr.common.SolrInputDocument)13