Search in sources :

Example 16 with SolrResourceLoader

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

the class LeaderElectionIntegrationTest method setupContainer.

private void setupContainer(int port, String shard) throws IOException, ParserConfigurationException, SAXException {
    Path data = createTempDir();
    System.setProperty("hostPort", Integer.toString(port));
    System.setProperty("shard", shard);
    System.setProperty("solr.data.dir", data.toString());
    System.setProperty("solr.solr.home", TEST_HOME());
    Set<Integer> ports = shardPorts.get(shard);
    if (ports == null) {
        ports = new HashSet<>();
        shardPorts.put(shard, ports);
    }
    ports.add(port);
    SolrResourceLoader loader = new SolrResourceLoader(createTempDir());
    Files.copy(TEST_PATH().resolve("solr.xml"), loader.getInstancePath().resolve("solr.xml"));
    CoreContainer container = new CoreContainer(loader);
    container.load();
    container.create("collection1_" + shard, ImmutableMap.of("collection", "collection1"));
    containerMap.put(port, container);
    System.clearProperty("solr.solr.home");
    System.clearProperty("hostPort");
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer)

Example 17 with SolrResourceLoader

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

the class QueryResponseTest method testSimpleGroupResponse.

@Test
public void testSimpleGroupResponse() throws Exception {
    XMLResponseParser parser = new XMLResponseParser();
    InputStream is = new SolrResourceLoader().openResource("solrj/sampleSimpleGroupResponse.xml");
    assertNotNull(is);
    Reader in = new InputStreamReader(is, StandardCharsets.UTF_8);
    NamedList<Object> response = parser.processResponse(in);
    in.close();
    QueryResponse qr = new QueryResponse(response, null);
    assertNotNull(qr);
    GroupResponse groupResponse = qr.getGroupResponse();
    assertNotNull(groupResponse);
    List<GroupCommand> commands = groupResponse.getValues();
    assertNotNull(commands);
    assertEquals(1, commands.size());
    GroupCommand fieldCommand = commands.get(0);
    assertEquals("acco_id", fieldCommand.getName());
    assertEquals(30000000, fieldCommand.getMatches());
    assertEquals(5687, fieldCommand.getNGroups().intValue());
    List<Group> fieldCommandGroups = fieldCommand.getValues();
    assertEquals(1, fieldCommandGroups.size());
    assertEquals("acco_id", fieldCommandGroups.get(0).getGroupValue());
    SolrDocumentList documents = fieldCommandGroups.get(0).getResult();
    assertNotNull(documents);
    assertEquals(10, documents.size());
    assertEquals("116_AR", documents.get(0).getFieldValue("acco_id"));
    assertEquals("116_HI", documents.get(1).getFieldValue("acco_id"));
    assertEquals("953_AR", documents.get(2).getFieldValue("acco_id"));
    assertEquals("953_HI", documents.get(3).getFieldValue("acco_id"));
    assertEquals("954_AR", documents.get(4).getFieldValue("acco_id"));
    assertEquals("954_HI", documents.get(5).getFieldValue("acco_id"));
    assertEquals("546_AR", documents.get(6).getFieldValue("acco_id"));
    assertEquals("546_HI", documents.get(7).getFieldValue("acco_id"));
    assertEquals("708_AR", documents.get(8).getFieldValue("acco_id"));
    assertEquals("708_HI", documents.get(9).getFieldValue("acco_id"));
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser) Test(org.junit.Test)

Example 18 with SolrResourceLoader

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

the class QueryResponseTest method testIntervalFacetsResponse.

public void testIntervalFacetsResponse() throws Exception {
    XMLResponseParser parser = new XMLResponseParser();
    try (SolrResourceLoader loader = new SolrResourceLoader()) {
        InputStream is = loader.openResource("solrj/sampleIntervalFacetsResponse.xml");
        assertNotNull(is);
        Reader in = new InputStreamReader(is, StandardCharsets.UTF_8);
        NamedList<Object> response = parser.processResponse(in);
        in.close();
        QueryResponse qr = new QueryResponse(response, null);
        assertNotNull(qr);
        assertNotNull(qr.getIntervalFacets());
        assertEquals(2, qr.getIntervalFacets().size());
        IntervalFacet facet = qr.getIntervalFacets().get(0);
        assertEquals("price", facet.getField());
        assertEquals(3, facet.getIntervals().size());
        assertEquals("[0,10]", facet.getIntervals().get(0).getKey());
        assertEquals("(10,100]", facet.getIntervals().get(1).getKey());
        assertEquals("(100,*]", facet.getIntervals().get(2).getKey());
        assertEquals(3, facet.getIntervals().get(0).getCount());
        assertEquals(4, facet.getIntervals().get(1).getCount());
        assertEquals(9, facet.getIntervals().get(2).getCount());
        facet = qr.getIntervalFacets().get(1);
        assertEquals("popularity", facet.getField());
        assertEquals(3, facet.getIntervals().size());
        assertEquals("bad", facet.getIntervals().get(0).getKey());
        assertEquals("average", facet.getIntervals().get(1).getKey());
        assertEquals("good", facet.getIntervals().get(2).getKey());
        assertEquals(3, facet.getIntervals().get(0).getCount());
        assertEquals(10, facet.getIntervals().get(1).getCount());
        assertEquals(2, facet.getIntervals().get(2).getCount());
    }
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser)

Example 19 with SolrResourceLoader

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

the class QueryResponseTest method testGroupResponse.

@Test
public void testGroupResponse() throws Exception {
    XMLResponseParser parser = new XMLResponseParser();
    InputStream is = new SolrResourceLoader().openResource("solrj/sampleGroupResponse.xml");
    assertNotNull(is);
    Reader in = new InputStreamReader(is, StandardCharsets.UTF_8);
    NamedList<Object> response = parser.processResponse(in);
    in.close();
    QueryResponse qr = new QueryResponse(response, null);
    assertNotNull(qr);
    GroupResponse groupResponse = qr.getGroupResponse();
    assertNotNull(groupResponse);
    List<GroupCommand> commands = groupResponse.getValues();
    assertNotNull(commands);
    assertEquals(3, commands.size());
    GroupCommand fieldCommand = commands.get(0);
    assertEquals("acco_id", fieldCommand.getName());
    assertEquals(30000000, fieldCommand.getMatches());
    assertEquals(5687, fieldCommand.getNGroups().intValue());
    List<Group> fieldCommandGroups = fieldCommand.getValues();
    assertEquals(10, fieldCommandGroups.size());
    assertEquals("116_ar", fieldCommandGroups.get(0).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(0).getResult().size());
    assertEquals(2236, fieldCommandGroups.get(0).getResult().getNumFound());
    assertEquals("116_hi", fieldCommandGroups.get(1).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(1).getResult().size());
    assertEquals(2234, fieldCommandGroups.get(1).getResult().getNumFound());
    assertEquals("953_ar", fieldCommandGroups.get(2).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(2).getResult().size());
    assertEquals(1020, fieldCommandGroups.get(2).getResult().getNumFound());
    assertEquals("953_hi", fieldCommandGroups.get(3).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(3).getResult().size());
    assertEquals(1030, fieldCommandGroups.get(3).getResult().getNumFound());
    assertEquals("954_ar", fieldCommandGroups.get(4).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(4).getResult().size());
    assertEquals(2236, fieldCommandGroups.get(4).getResult().getNumFound());
    assertEquals("954_hi", fieldCommandGroups.get(5).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(5).getResult().size());
    assertEquals(2234, fieldCommandGroups.get(5).getResult().getNumFound());
    assertEquals("546_ar", fieldCommandGroups.get(6).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(6).getResult().size());
    assertEquals(4984, fieldCommandGroups.get(6).getResult().getNumFound());
    assertEquals("546_hi", fieldCommandGroups.get(7).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(7).getResult().size());
    assertEquals(4984, fieldCommandGroups.get(7).getResult().getNumFound());
    assertEquals("708_ar", fieldCommandGroups.get(8).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(8).getResult().size());
    assertEquals(4627, fieldCommandGroups.get(8).getResult().getNumFound());
    assertEquals("708_hi", fieldCommandGroups.get(9).getGroupValue());
    assertEquals(2, fieldCommandGroups.get(9).getResult().size());
    assertEquals(4627, fieldCommandGroups.get(9).getResult().getNumFound());
    GroupCommand funcCommand = commands.get(1);
    assertEquals("sum(price, price)", funcCommand.getName());
    assertEquals(30000000, funcCommand.getMatches());
    assertNull(funcCommand.getNGroups());
    List<Group> funcCommandGroups = funcCommand.getValues();
    assertEquals(10, funcCommandGroups.size());
    assertEquals("95000.0", funcCommandGroups.get(0).getGroupValue());
    assertEquals(2, funcCommandGroups.get(0).getResult().size());
    assertEquals(43666, funcCommandGroups.get(0).getResult().getNumFound());
    assertEquals("91400.0", funcCommandGroups.get(1).getGroupValue());
    assertEquals(2, funcCommandGroups.get(1).getResult().size());
    assertEquals(27120, funcCommandGroups.get(1).getResult().getNumFound());
    assertEquals("104800.0", funcCommandGroups.get(2).getGroupValue());
    assertEquals(2, funcCommandGroups.get(2).getResult().size());
    assertEquals(34579, funcCommandGroups.get(2).getResult().getNumFound());
    assertEquals("99400.0", funcCommandGroups.get(3).getGroupValue());
    assertEquals(2, funcCommandGroups.get(3).getResult().size());
    assertEquals(40519, funcCommandGroups.get(3).getResult().getNumFound());
    assertEquals("109600.0", funcCommandGroups.get(4).getGroupValue());
    assertEquals(2, funcCommandGroups.get(4).getResult().size());
    assertEquals(36203, funcCommandGroups.get(4).getResult().getNumFound());
    assertEquals("102400.0", funcCommandGroups.get(5).getGroupValue());
    assertEquals(2, funcCommandGroups.get(5).getResult().size());
    assertEquals(37852, funcCommandGroups.get(5).getResult().getNumFound());
    assertEquals("116800.0", funcCommandGroups.get(6).getGroupValue());
    assertEquals(2, funcCommandGroups.get(6).getResult().size());
    assertEquals(40393, funcCommandGroups.get(6).getResult().getNumFound());
    assertEquals("107800.0", funcCommandGroups.get(7).getGroupValue());
    assertEquals(2, funcCommandGroups.get(7).getResult().size());
    assertEquals(41639, funcCommandGroups.get(7).getResult().getNumFound());
    assertEquals("136200.0", funcCommandGroups.get(8).getGroupValue());
    assertEquals(2, funcCommandGroups.get(8).getResult().size());
    assertEquals(25929, funcCommandGroups.get(8).getResult().getNumFound());
    assertEquals("131400.0", funcCommandGroups.get(9).getGroupValue());
    assertEquals(2, funcCommandGroups.get(9).getResult().size());
    assertEquals(29179, funcCommandGroups.get(9).getResult().getNumFound());
    GroupCommand queryCommand = commands.get(2);
    assertEquals("country:fr", queryCommand.getName());
    assertNull(queryCommand.getNGroups());
    assertEquals(30000000, queryCommand.getMatches());
    List<Group> queryCommandGroups = queryCommand.getValues();
    assertEquals(1, queryCommandGroups.size());
    assertEquals("country:fr", queryCommandGroups.get(0).getGroupValue());
    assertEquals(2, queryCommandGroups.get(0).getResult().size());
    assertEquals(57074, queryCommandGroups.get(0).getResult().getNumFound());
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser) Test(org.junit.Test)

Example 20 with SolrResourceLoader

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

the class ContentStreamTest method testFileStream.

public void testFileStream() throws IOException {
    InputStream is = new SolrResourceLoader().openResource("solrj/README");
    assertNotNull(is);
    File file = new File(createTempDir().toFile(), "README");
    FileOutputStream os = new FileOutputStream(file);
    IOUtils.copy(is, os);
    os.close();
    is.close();
    ContentStreamBase stream = new ContentStreamBase.FileStream(file);
    InputStream s = stream.getStream();
    FileInputStream fis = new FileInputStream(file);
    InputStreamReader isr = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
    Reader r = stream.getReader();
    try {
        assertEquals(file.length(), stream.getSize().intValue());
        assertTrue(IOUtils.contentEquals(fis, s));
        assertTrue(IOUtils.contentEquals(isr, r));
    } finally {
        s.close();
        r.close();
        isr.close();
        fis.close();
    }
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)54 Test (org.junit.Test)18 File (java.io.File)11 InputStream (java.io.InputStream)11 NamedList (org.apache.solr.common.util.NamedList)10 SolrException (org.apache.solr.common.SolrException)9 NodeConfig (org.apache.solr.core.NodeConfig)9 Path (java.nio.file.Path)8 CoreContainer (org.apache.solr.core.CoreContainer)8 InputStreamReader (java.io.InputStreamReader)7 Reader (java.io.Reader)7 Map (java.util.Map)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)5 SolrCore (org.apache.solr.core.SolrCore)5 ArrayList (java.util.ArrayList)4 ZkSolrResourceLoader (org.apache.solr.cloud.ZkSolrResourceLoader)4 SolrConfig (org.apache.solr.core.SolrConfig)4