Search in sources :

Example 11 with CoreContainer

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

the class TestCoreAdminApis method testCalls.

public void testCalls() throws Exception {
    Map<String, Object[]> calls = new HashMap<>();
    CoreContainer mockCC = getCoreContainerMock(calls, new HashMap<>());
    CoreAdminHandler coreAdminHandler = new CoreAdminHandler(mockCC);
    ApiBag apiBag = new ApiBag(false);
    for (Api api : coreAdminHandler.getApis()) {
        apiBag.register(api, Collections.EMPTY_MAP);
    }
    TestCollectionAPIs.makeCall(apiBag, "/cores", SolrRequest.METHOD.POST, "{create:{name: hello, instanceDir : someDir, schema: 'schema.xml'}}", mockCC);
    Object[] params = calls.get("create");
    assertEquals("hello", params[0]);
    assertEquals(fromJSONString("{schema : schema.xml}"), params[2]);
    TestCollectionAPIs.makeCall(apiBag, "/cores/core1", SolrRequest.METHOD.POST, "{swap:{with: core2}}", mockCC);
    params = calls.get("swap");
    assertEquals("core1", params[0]);
    assertEquals("core2", params[1]);
    TestCollectionAPIs.makeCall(apiBag, "/cores/core1", SolrRequest.METHOD.POST, "{rename:{to: core2}}", mockCC);
    params = calls.get("swap");
    assertEquals("core1", params[0]);
    assertEquals("core2", params[1]);
    TestCollectionAPIs.makeCall(apiBag, "/cores/core1", SolrRequest.METHOD.POST, "{unload:{deleteIndex : true}}", mockCC);
    params = calls.get("unload");
    assertEquals("core1", params[0]);
    assertEquals(Boolean.TRUE, params[1]);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) HashMap(java.util.HashMap) ApiBag(org.apache.solr.api.ApiBag) Utils.fromJSONString(org.apache.solr.common.util.Utils.fromJSONString) Api(org.apache.solr.api.Api)

Example 12 with CoreContainer

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

the class CoreAdminHandlerTest method testCreateWithSysVars.

@Test
public void testCreateWithSysVars() throws Exception {
    // I require FS-based indexes for this test.
    useFactory(null);
    final File workDir = createTempDir(getCoreName()).toFile();
    String coreName = "with_sys_vars";
    File instDir = new File(workDir, coreName);
    File subHome = new File(instDir, "conf");
    assertTrue("Failed to make subdirectory ", subHome.mkdirs());
    // Be sure we pick up sysvars when we create this
    String srcDir = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
    FileUtils.copyFile(new File(srcDir, "schema-tiny.xml"), new File(subHome, "schema_ren.xml"));
    FileUtils.copyFile(new File(srcDir, "solrconfig-minimal.xml"), new File(subHome, "solrconfig_ren.xml"));
    FileUtils.copyFile(new File(srcDir, "solrconfig.snippet.randomindexconfig.xml"), new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));
    final CoreContainer cores = h.getCoreContainer();
    final CoreAdminHandler admin = new CoreAdminHandler(cores);
    // create a new core (using CoreAdminHandler) w/ properties
    System.setProperty("INSTDIR_TEST", instDir.getAbsolutePath());
    System.setProperty("CONFIG_TEST", "solrconfig_ren.xml");
    System.setProperty("SCHEMA_TEST", "schema_ren.xml");
    File dataDir = new File(workDir.getAbsolutePath(), "data_diff");
    System.setProperty("DATA_TEST", dataDir.getAbsolutePath());
    SolrQueryResponse resp = new SolrQueryResponse();
    admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.NAME, getCoreName(), CoreAdminParams.INSTANCE_DIR, "${INSTDIR_TEST}", CoreAdminParams.CONFIG, "${CONFIG_TEST}", CoreAdminParams.SCHEMA, "${SCHEMA_TEST}", CoreAdminParams.DATA_DIR, "${DATA_TEST}"), resp);
    assertNull("Exception on create", resp.getException());
    // Now assert that certain values are properly dereferenced in the process of creating the core, see
    // SOLR-4982.
    // Should NOT be a datadir named ${DATA_TEST} (literal). This is the bug after all
    File badDir = new File(instDir, "${DATA_TEST}");
    assertFalse("Should have substituted the sys var, found file " + badDir.getAbsolutePath(), badDir.exists());
    // For the other 3 vars, we couldn't get past creating the core fi dereferencing didn't work correctly.
    // Should have segments in the directory pointed to by the ${DATA_TEST}.
    File test = new File(dataDir, "index");
    assertTrue("Should have found index dir at " + test.getAbsolutePath(), test.exists());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) File(java.io.File) Test(org.junit.Test)

Example 13 with CoreContainer

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

the class CoreAdminRequestStatusTest method testCoreAdminRequestStatus.

@Test
public void testCoreAdminRequestStatus() throws Exception {
    final File workDir = createTempDir().toFile();
    final CoreContainer cores = h.getCoreContainer();
    final CoreAdminHandler admin = new CoreAdminHandler(cores);
    Path instDir;
    try (SolrCore template = cores.getCore("collection1")) {
        assertNotNull(template);
        instDir = template.getCoreDescriptor().getInstanceDir();
    }
    assertTrue("instDir doesn't exist: " + instDir, Files.exists(instDir));
    final File instPropFile = new File(workDir, "instProp");
    FileUtils.copyDirectory(instDir.toFile(), instPropFile);
    // create a new core (using CoreAdminHandler) w/ properties
    SolrQueryResponse resp = new SolrQueryResponse();
    admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.INSTANCE_DIR, instPropFile.getAbsolutePath(), CoreAdminParams.NAME, "dummycore", CommonAdminParams.ASYNC, "42"), resp);
    assertNull("Exception on create", resp.getException());
    int maxRetries = 10;
    while (maxRetries-- > 0) {
        resp = new SolrQueryResponse();
        admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(), CoreAdminParams.REQUESTID, "42"), resp);
        if (resp.getValues().get("STATUS") != null && resp.getValues().get("STATUS").equals("completed"))
            break;
        Thread.sleep(1000);
    }
    assertEquals("The status of request was expected to be completed", "completed", resp.getValues().get("STATUS"));
    resp = new SolrQueryResponse();
    admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(), CoreAdminParams.REQUESTID, "9999999"), resp);
    assertEquals("Was expecting it to be invalid but found a task with the id.", "notfound", resp.getValues().get("STATUS"));
    admin.shutdown();
}
Also used : Path(java.nio.file.Path) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) File(java.io.File) Test(org.junit.Test)

Example 14 with CoreContainer

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

the class InfoHandlerTest method testCoreAdminHandler.

@Test
public void testCoreAdminHandler() throws Exception {
    final CoreContainer cores = h.getCoreContainer();
    InfoHandler infoHandler = cores.getInfoHandler();
    SolrQueryResponse rsp = handleRequest(infoHandler, "properties");
    assertNotNull(rsp.getValues().get("system.properties"));
    rsp = handleRequest(infoHandler, "threads");
    assertNotNull(rsp.getValues().get("system"));
    rsp = handleRequest(infoHandler, "logging");
    assertNotNull(rsp.getValues().get("watcher"));
    try {
        rsp = handleRequest(infoHandler, "info");
        fail("Should have failed with not found");
    } catch (SolrException e) {
        assertEquals(404, e.code());
    }
    try {
        rsp = handleRequest(infoHandler, "");
        fail("Should have failed with not found");
    } catch (SolrException e) {
        assertEquals(404, e.code());
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 15 with CoreContainer

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

the class VersionInfoTest method testMaxVersionLogic.

protected void testMaxVersionLogic(SolrQueryRequest req) throws Exception {
    UpdateHandler uhandler = req.getCore().getUpdateHandler();
    UpdateLog ulog = uhandler.getUpdateLog();
    ulog.init(uhandler, req.getCore());
    clearIndex();
    assertU(commit());
    // index the first doc
    String docId = Integer.toString(1);
    assertU(adoc("id", docId));
    assertU(commit());
    // max from index should not be 0 or null
    Long maxVersionFromIndex = ulog.getMaxVersionFromIndex();
    assertNotNull(maxVersionFromIndex);
    assertTrue(maxVersionFromIndex != 0L);
    // version from index should be less than or equal the version of the first doc indexed
    VersionInfo vInfo = ulog.getVersionInfo();
    Long version = vInfo.getVersionFromIndex(new BytesRef(docId));
    assertNotNull("version info should not be null for test doc: " + docId, version);
    assertTrue("max version from index should be less than or equal to the version of first doc added, diff: " + (version - maxVersionFromIndex), maxVersionFromIndex <= version);
    BytesRef idBytes = new BytesRef(docId);
    int bucketHash = Hash.murmurhash3_x86_32(idBytes.bytes, idBytes.offset, idBytes.length, 0);
    VersionBucket bucket = vInfo.bucket(bucketHash);
    assertTrue(bucket.highest == version.longValue());
    // send 2nd doc ...
    docId = Integer.toString(2);
    assertU(adoc("id", docId));
    assertU(commit());
    maxVersionFromIndex = ulog.getMaxVersionFromIndex();
    assertNotNull(maxVersionFromIndex);
    assertTrue(maxVersionFromIndex != 0L);
    vInfo = ulog.getVersionInfo();
    version = vInfo.getVersionFromIndex(new BytesRef(docId));
    assertNotNull("version info should not be null for test doc: " + docId, version);
    assertTrue("max version from index should be less than version of last doc added, diff: " + (version - maxVersionFromIndex), maxVersionFromIndex < version);
    idBytes = new BytesRef(docId);
    bucketHash = Hash.murmurhash3_x86_32(idBytes.bytes, idBytes.offset, idBytes.length, 0);
    bucket = vInfo.bucket(bucketHash);
    assertTrue(bucket.highest == version.longValue());
    Long versionFromTLog = ulog.lookupVersion(idBytes);
    Long versionFromIndex = vInfo.getVersionFromIndex(idBytes);
    assertEquals("version from tlog and version from index should be the same", versionFromTLog, versionFromIndex);
    // reload the core, which should reset the max
    CoreContainer coreContainer = req.getCore().getCoreContainer();
    coreContainer.reload(req.getCore().getName());
    maxVersionFromIndex = ulog.getMaxVersionFromIndex();
    assertEquals("max version from index should be equal to version of last doc added after reload", maxVersionFromIndex, version);
    // one more doc after reload
    docId = Integer.toString(3);
    assertU(adoc("id", docId));
    assertU(commit());
    maxVersionFromIndex = ulog.getMaxVersionFromIndex();
    assertNotNull(maxVersionFromIndex);
    assertTrue(maxVersionFromIndex != 0L);
    vInfo = ulog.getVersionInfo();
    version = vInfo.getVersionFromIndex(new BytesRef(docId));
    assertNotNull("version info should not be null for test doc: " + docId, version);
    assertTrue("max version from index should be less than version of last doc added, diff: " + (version - maxVersionFromIndex), maxVersionFromIndex < version);
    idBytes = new BytesRef(docId);
    bucketHash = Hash.murmurhash3_x86_32(idBytes.bytes, idBytes.offset, idBytes.length, 0);
    bucket = vInfo.bucket(bucketHash);
    assertTrue(bucket.highest == version.longValue());
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

CoreContainer (org.apache.solr.core.CoreContainer)95 SolrCore (org.apache.solr.core.SolrCore)30 Test (org.junit.Test)23 SolrException (org.apache.solr.common.SolrException)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)14 File (java.io.File)13 HashMap (java.util.HashMap)11 Replica (org.apache.solr.common.cloud.Replica)11 CoreDescriptor (org.apache.solr.core.CoreDescriptor)11 Path (java.nio.file.Path)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)8 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)8 Map (java.util.Map)7 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)7 Properties (java.util.Properties)6 DocCollection (org.apache.solr.common.cloud.DocCollection)6 Slice (org.apache.solr.common.cloud.Slice)6 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)6