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());
}
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']");
}
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());
}
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()));
}
}
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());
}
}
Aggregations