Search in sources :

Example 46 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class AutoCommitTest method testMaxDocs.

public void testMaxDocs() throws Exception {
    SolrCore core = h.getCore();
    NewSearcherListener trigger = new NewSearcherListener();
    DirectUpdateHandler2 updateHandler = (DirectUpdateHandler2) core.getUpdateHandler();
    CommitTracker tracker = updateHandler.softCommitTracker;
    tracker.setTimeUpperBound(-1);
    tracker.setDocsUpperBound(14);
    core.registerNewSearcherListener(trigger);
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
    // Add documents
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
    };
    for (int i = 0; i < 14; i++) {
        req.setContentStreams(toContentStreams(adoc("id", Integer.toString(i), "subject", "info"), null));
        handler.handleRequest(req, rsp);
    }
    // It should not be there right away
    assertQ("shouldn't find any", req("id:1"), "//result[@numFound=0]");
    assertEquals(0, tracker.getCommitCount());
    req.setContentStreams(toContentStreams(adoc("id", "14", "subject", "info"), null));
    handler.handleRequest(req, rsp);
    assertTrue(trigger.waitForNewSearcher(15000));
    req.setContentStreams(toContentStreams(adoc("id", "15", "subject", "info"), null));
    handler.handleRequest(req, rsp);
    // Now make sure we can find it
    assertQ("should find one", req("id:14"), "//result[@numFound=1]");
    assertEquals(1, tracker.getCommitCount());
    // But not the one added afterward
    assertQ("should not find one", req("id:15"), "//result[@numFound=0]");
    assertEquals(1, tracker.getCommitCount());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrCore(org.apache.solr.core.SolrCore) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler)

Example 47 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class DirectUpdateHandlerTest method testAddRollback.

@Test
public void testAddRollback() throws Exception {
    // re-init the core
    deleteCore();
    initCore("solrconfig.xml", "schema12.xml");
    assertU(adoc("id", "A"));
    // commit "A"
    SolrCore core = h.getCore();
    UpdateHandler updater = core.getUpdateHandler();
    assertTrue(updater instanceof DirectUpdateHandler2);
    DirectUpdateHandler2 duh2 = (DirectUpdateHandler2) updater;
    SolrQueryRequest ureq = req();
    CommitUpdateCommand cmtCmd = new CommitUpdateCommand(ureq, false);
    cmtCmd.waitSearcher = true;
    assertEquals(1, duh2.addCommands.longValue());
    assertEquals(1, duh2.addCommandsCumulative.getCount());
    assertEquals(0, duh2.commitCommands.getCount());
    updater.commit(cmtCmd);
    assertEquals(0, duh2.addCommands.longValue());
    assertEquals(1, duh2.addCommandsCumulative.getCount());
    assertEquals(1, duh2.commitCommands.getCount());
    ureq.close();
    assertU(adoc("id", "B"));
    // rollback "B"
    ureq = req();
    RollbackUpdateCommand rbkCmd = new RollbackUpdateCommand(ureq);
    assertEquals(1, duh2.addCommands.longValue());
    assertEquals(2, duh2.addCommandsCumulative.getCount());
    assertEquals(0, duh2.rollbackCommands.getCount());
    updater.rollback(rbkCmd);
    assertEquals(0, duh2.addCommands.longValue());
    assertEquals(1, duh2.addCommandsCumulative.getCount());
    assertEquals(1, duh2.rollbackCommands.getCount());
    ureq.close();
    // search - "B" should not be found.
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.Q, "id:A OR id:B");
    args.put("indent", "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
    assertQ("\"B\" should not be found.", req, "//*[@numFound='1']", "//result/doc[1]/str[@name='id'][.='A']");
    // Add a doc after the rollback to make sure we can continue to add/delete documents
    // after a rollback as normal
    assertU(adoc("id", "ZZZ"));
    assertU(commit());
    assertQ("\"ZZZ\" must be found.", req("q", "id:ZZZ"), "//*[@numFound='1']", "//result/doc[1]/str[@name='id'][.='ZZZ']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 48 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class DirectUpdateHandlerTest method testPostSoftCommitEvents.

@Test
public void testPostSoftCommitEvents() throws Exception {
    SolrCore core = h.getCore();
    assert core != null;
    DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
    MySolrEventListener listener = new MySolrEventListener();
    core.registerNewSearcherListener(listener);
    updater.registerSoftCommitCallback(listener);
    assertU(adoc("id", "999"));
    assertU(commit("softCommit", "true"));
    assertEquals("newSearcher was called more than once", 1, listener.newSearcherCount.get());
    assertFalse("postSoftCommit was not called", listener.postSoftCommitAt.get() == Long.MAX_VALUE);
    assertTrue("newSearcher was called after postSoftCommitCallback", listener.postSoftCommitAt.get() >= listener.newSearcherOpenedAt.get());
}
Also used : SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 49 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class TestCoreAdmin method testConfigSet.

@Test
public void testConfigSet() throws Exception {
    SolrClient client = getSolrAdmin();
    File testDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()).toFile();
    File newCoreInstanceDir = new File(testDir, "newcore");
    CoreAdminRequest.Create req = new CoreAdminRequest.Create();
    req.setCoreName("corewithconfigset");
    req.setInstanceDir(newCoreInstanceDir.getAbsolutePath());
    req.setConfigSet("configset-2");
    CoreAdminResponse response = req.process(client);
    assertThat((String) response.getResponse().get("core"), is("corewithconfigset"));
    try (SolrCore core = cores.getCore("corewithconfigset")) {
        assertThat(core, is(notNullValue()));
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) SolrCore(org.apache.solr.core.SolrCore) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) File(java.io.File) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) Test(org.junit.Test)

Example 50 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class TestCoreAdmin method testCustomUlogDir.

@Test
public void testCustomUlogDir() throws Exception {
    try (SolrClient client = getSolrAdmin()) {
        File dataDir = createTempDir("data").toFile();
        File newCoreInstanceDir = createTempDir("instance").toFile();
        File instanceDir = new File(cores.getSolrHome());
        FileUtils.copyDirectory(instanceDir, new File(newCoreInstanceDir, "newcore"));
        CoreAdminRequest.Create req = new CoreAdminRequest.Create();
        req.setCoreName("newcore");
        req.setInstanceDir(newCoreInstanceDir.getAbsolutePath() + File.separator + "newcore");
        req.setDataDir(dataDir.getAbsolutePath());
        req.setUlogDir(new File(dataDir, "ulog").getAbsolutePath());
        req.setConfigSet("shared");
        // These should be the inverse of defaults.
        req.setIsLoadOnStartup(false);
        req.setIsTransient(true);
        req.process(client);
        // Show that the newly-created core has values for load on startup and transient different than defaults due to the
        // above.
        File logDir;
        try (SolrCore coreProveIt = cores.getCore("collection1");
            SolrCore core = cores.getCore("newcore")) {
            assertTrue(core.getCoreDescriptor().isTransient());
            assertFalse(coreProveIt.getCoreDescriptor().isTransient());
            assertFalse(core.getCoreDescriptor().isLoadOnStartup());
            assertTrue(coreProveIt.getCoreDescriptor().isLoadOnStartup());
            logDir = new File(core.getUpdateHandler().getUpdateLog().getLogDir());
        }
        assertEquals(new File(dataDir, "ulog" + File.separator + "tlog").getAbsolutePath(), logDir.getAbsolutePath());
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) SolrCore(org.apache.solr.core.SolrCore) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) File(java.io.File) Test(org.junit.Test)

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