List of usage examples for org.apache.solr.client.solrj SolrClient optimize
public UpdateResponse optimize(String collection) throws SolrServerException, IOException
From source file:org.codice.ddf.commands.solr.RestoreCommandTest.java
License:Open Source License
/** * See/*from ww w . j a va 2 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.SolrCommands.java
License:Open Source License
protected void optimizeCollection(SolrClient client, String collection) throws IOException, SolrServerException { LOGGER.debug("Optimization of collection [{}] is in progress.", collection); printInfoMessage(String.format("Optimizing of collection [%s] is in progress.", collection)); UpdateResponse updateResponse = client.optimize(collection); LOGGER.debug("Optimization status: {}", updateResponse.getStatus()); if (updateResponse.getStatus() != 0) { throw new SolrServerException(String.format("Unable to optimize collection [%s].", collection)); }/*from w ww. j a va 2s. c om*/ }