Search in sources :

Example 71 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.

the class TestIntervalFaceting method testSolrJ.

@Test
public void testSolrJ() throws Exception {
    assertU(adoc("id", "1", "test_i_dv", "0"));
    assertU(adoc("id", "2", "test_i_dv", "1"));
    assertU(adoc("id", "3", "test_i_dv", "2"));
    assertU(commit());
    // Don't close this client, it would shutdown the CoreContainer
    @SuppressWarnings("resource") SolrClient client = new EmbeddedSolrServer(h.getCoreContainer(), h.coreName);
    SolrQuery q = new SolrQuery();
    q.setQuery("*:*");
    q.addIntervalFacets("test_i_dv", new String[] { "[0,1]", "[2,*]" });
    QueryResponse response = client.query(q);
    assertEquals(1, response.getIntervalFacets().size());
    assertEquals("test_i_dv", response.getIntervalFacets().get(0).getField());
    assertEquals(2, response.getIntervalFacets().get(0).getIntervals().size());
    assertEquals("[0,1]", response.getIntervalFacets().get(0).getIntervals().get(0).getKey());
    assertEquals("[2,*]", response.getIntervalFacets().get(0).getIntervals().get(1).getKey());
    q = new SolrQuery();
    q.setQuery("*:*");
    q.setFacet(true);
    q.add("facet.interval", "{!key=foo}test_i_dv");
    q.add("f.test_i_dv.facet.interval.set", "{!key=first}[0,1]");
    q.add("f.test_i_dv.facet.interval.set", "{!key=second}[2,*]");
    response = client.query(q);
    assertEquals(1, response.getIntervalFacets().size());
    assertEquals("foo", response.getIntervalFacets().get(0).getField());
    assertEquals(2, response.getIntervalFacets().get(0).getIntervals().size());
    assertEquals("first", response.getIntervalFacets().get(0).getIntervals().get(0).getKey());
    assertEquals("second", response.getIntervalFacets().get(0).getIntervals().get(1).getKey());
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 72 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project spring-boot by spring-projects.

the class SolrHealthIndicatorTests method solrIsUp.

@Test
public void solrIsUp() throws Exception {
    SolrClient solrClient = mock(SolrClient.class);
    SolrPingResponse pingResponse = new SolrPingResponse();
    NamedList<Object> response = new NamedList<>();
    response.add("status", "OK");
    pingResponse.setResponse(response);
    given(solrClient.ping()).willReturn(pingResponse);
    SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("solrStatus")).isEqualTo("OK");
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) SolrClient(org.apache.solr.client.solrj.SolrClient) NamedList(org.apache.solr.common.util.NamedList) Test(org.junit.Test)

Example 73 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project ddf by codice.

the class RemoteSolrCatalogProviderTest method givenSolrClient.

/**
     * @return
     * @throws IOException
     * @throws SolrServerException
     */
private SolrClient givenSolrClient(boolean ok) throws SolrServerException, IOException {
    SolrClient client = mock(SolrClient.class);
    SolrPingResponse pingResponse = mock(SolrPingResponse.class);
    NamedList<Object> namedList = new NamedList<Object>();
    if (ok) {
        namedList.add("status", "OK");
    } else {
        namedList.add("status", "NOT_OK");
    }
    when(pingResponse.getResponse()).thenReturn(namedList);
    when(client.ping()).thenReturn(pingResponse);
    return client;
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) SolrClient(org.apache.solr.client.solrj.SolrClient) NamedList(org.apache.solr.common.util.NamedList)

Example 74 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project ddf by codice.

the class RemoteSolrCatalogProviderTest method testSetUrlResolvesProperties.

/**
     * Tests that property replacement is performed on the URL provided to
     * {@link RemoteSolrCatalogProvider#setUrl(String)}.
     */
@Test
public void testSetUrlResolvesProperties() throws Exception {
    // given
    SolrClient givenClient = givenSolrClient(true);
    RemoteSolrCatalogProvider provider = new MockedRemoteSolrCatalogProvider(givenClient);
    System.setProperty("test-property", "solr-url");
    // when
    provider.setUrl("https://hostname:443/${test-property}");
    // then
    assertThat(provider.getUrl(), is("https://hostname:443/solr-url"));
// should be no failures/exceptions
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) Test(org.junit.Test)

Example 75 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project ddf by codice.

the class RemoteSolrCatalogProviderTest method testUnconfiguredCreateSolrException.

/**
     * Tests what happens when a {@link SolrException} is thrown when Solr is pinged
     *
     * @throws IngestException
     * @throws SolrServerException
     * @throws IOException
     */
@Test
public void testUnconfiguredCreateSolrException() throws IngestException, SolrServerException, IOException {
    // given
    SolrClient givenClient = mock(SolrClient.class);
    when(givenClient.ping()).thenThrow(SolrException.class);
    CatalogProvider provider = new MockedRemoteSolrCatalogProvider(givenClient);
    // when
    String message = null;
    try {
        provider.create(mock(CreateRequest.class));
    } catch (IllegalStateException e) {
        message = e.getMessage();
    }
    // then
    assertThat(message, containsString("Solr client is not connected"));
    verify(givenClient, times(1)).ping();
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) CatalogProvider(ddf.catalog.source.CatalogProvider) CreateRequest(ddf.catalog.operation.CreateRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

SolrClient (org.apache.solr.client.solrj.SolrClient)172 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)105 Test (org.junit.Test)67 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)38 ArrayList (java.util.ArrayList)36 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)31 SolrQuery (org.apache.solr.client.solrj.SolrQuery)28 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)28 SolrInputDocument (org.apache.solr.common.SolrInputDocument)28 IOException (java.io.IOException)24 NamedList (org.apache.solr.common.util.NamedList)23 SolrServerException (org.apache.solr.client.solrj.SolrServerException)18 SolrException (org.apache.solr.common.SolrException)18 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)17 Map (java.util.Map)16 Replica (org.apache.solr.common.cloud.Replica)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)15 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)14 SolrDocument (org.apache.solr.common.SolrDocument)14 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)13