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