Example usage for org.apache.solr.client.solrj SolrClient request

List of usage examples for org.apache.solr.client.solrj SolrClient request

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrClient request.

Prototype

public abstract NamedList<Object> request(final SolrRequest request, String collection)
        throws SolrServerException, IOException;

Source Link

Document

Execute a request against a Solr server for a given collection

Usage

From source file:net.yacy.cora.federate.solr.instance.ServerShard.java

License:Open Source License

/**
 * SolrServer implementations need to implement how a request is actually processed
 *///from w w  w.  j a v a  2 s. c  om
@Override
public NamedList<Object> request(@SuppressWarnings("rawtypes") SolrRequest request, String collection)
        throws SolrServerException, IOException {
    ResponseAccumulator acc = new ResponseAccumulator();
    for (SolrClient s : this.shards.server4read())
        acc.addResponse(s.request(request, collection));
    return acc.getAccumulatedResponse();
}

From source file:org.codice.ddf.commands.solr.RestoreCommandTest.java

License:Open Source License

/**
 * See/*from w  w  w.ja  v a2  s .  co m*/
 * https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-BACKUP:BackupCollection
 * for requests and responses.
 */
private SolrClient getMockSolrClientForRestore(String collection, int optimizationStatusCode,
        int restoreStatusCode, NamedList<String> restoreErrorMessages) throws Exception {

    SolrClient mockSolrClient = mock(SolrClient.class);
    UpdateResponse optimizationResponse = getMockOptimizationResponse(optimizationStatusCode);
    when(mockSolrClient.optimize(eq(collection))).thenReturn(optimizationResponse);

    NamedList<Object> responseHeader = getResponseHeader(restoreStatusCode);

    NamedList<Object> mockResponse = new NamedList<>();
    mockResponse.add("responseHeader", responseHeader);
    if (restoreErrorMessages != null) {
        mockResponse.add("failure", restoreErrorMessages);
    } else {
        mockResponse.add("success", new Object());
    }

    if (collection != null) {
        when(mockSolrClient.request(any(SolrRequest.class), eq(collection))).thenReturn(mockResponse);
    }
    return mockSolrClient;
}

From source file:org.codice.ddf.commands.solr.RestoreCommandTest.java

License:Open Source License

private SolrClient getMockSolrClientForRestoreStatusFailure(NamedList<String> restoreErrorMessages)
        throws Exception {
    SolrClient mockSolrClient = mock(SolrClient.class);
    NamedList<Object> response = getResponseForStatus(FAILURE_STATUS_CODE, RequestStatusState.FAILED,
            restoreErrorMessages);//from w  ww  .  j  av  a  2  s. c  om
    when(mockSolrClient.request(any(SolrRequest.class), isNull(String.class))).thenReturn(response);
    return mockSolrClient;
}

From source file:org.codice.ddf.commands.solr.RestoreCommandTest.java

License:Open Source License

private SolrClient getMockSolrClientForStatusThrowsException() throws Exception {
    SolrClient mockSolrClient = mock(SolrClient.class);
    when(mockSolrClient.request(any(SolrRequest.class), isNull(String.class)))
            .thenThrow(SolrServerException.class);
    return mockSolrClient;
}

From source file:org.roda.core.migration.MigrationManager.java

private Map<String, Integer> getIndexVersionsFromSolr(SolrClient solrClient, List<String> collections) {
    Map<String, Integer> ret = new HashMap<>();

    SolrRequest request = new SchemaRequest.SchemaName();
    try {//from w w w.  java  2s  .  c o m
        for (String collection : collections) {
            NamedList<Object> response = solrClient.request(request, collection);
            for (Entry<String, Object> entry : response) {
                String value = entry.getValue().toString();
                if ("name".equals(entry.getKey()) && StringUtils.isNotBlank(value)) {
                    String version = value.replaceFirst(".*-", "");
                    try {
                        ret.put(collection, Integer.parseInt(version));
                    } catch (NumberFormatException e) {
                        // do nothing
                    }
                    break;
                }
            }
        }
    } catch (SolrServerException | IOException e) {
        // do nothing
    }
    return ret;
}

From source file:org.springframework.boot.actuate.solr.SolrHealthIndicatorTests.java

License:Apache License

@Test
public void solrIsUp() throws Exception {
    SolrClient solrClient = mock(SolrClient.class);
    given(solrClient.request(any(CoreAdminRequest.class), isNull())).willReturn(mockResponse(0));
    SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("status")).isEqualTo(0);
}

From source file:org.springframework.boot.actuate.solr.SolrHealthIndicatorTests.java

License:Apache License

@Test
public void solrIsUpAndRequestFailed() throws Exception {
    SolrClient solrClient = mock(SolrClient.class);
    given(solrClient.request(any(CoreAdminRequest.class), isNull())).willReturn(mockResponse(400));
    SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("status")).isEqualTo(400);
}

From source file:org.springframework.boot.actuate.solr.SolrHealthIndicatorTests.java

License:Apache License

@Test
public void solrIsDown() throws Exception {
    SolrClient solrClient = mock(SolrClient.class);
    given(solrClient.request(any(CoreAdminRequest.class), isNull()))
            .willThrow(new IOException("Connection failed"));
    SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat((String) health.getDetails().get("error")).contains("Connection failed");
}