DocumentLoader getLoader(RetryPolicyFactory retryPolicyFactory, MetricsFacade retryMetricsFacade) { if (context instanceof SolrMorphlineContext) { DocumentLoader loader = ((SolrMorphlineContext)context).getDocumentLoader(); if (loader != null) { return loader; } } SolrClient solrServer = getSolrServer(); if (solrServer instanceof CloudSolrClient) { try { ((CloudSolrClient)solrServer).setIdField(getIndexSchema().getUniqueKeyField().getName()); } catch (RuntimeException e) { try { solrServer.close(); // release resources } catch (Exception ex2) { LOG.debug("Cannot get index schema and cannot shutdown CloudSolrServer", ex2); } throw new RuntimeException(e); // rethrow root cause } } if (retryPolicyFactory != null) { solrServer = new RetryingSolrServer(solrServer, retryPolicyFactory, retryMetricsFacade); } return new SolrServerDocumentLoader(solrServer, batchSize); }
private String getExceptionKey(final String str) { RetryingSolrServer solr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); return solr.getExceptionKey(new Throwable() { @Override public String toString() { return str; } }); }
private String normalizeRequestKey(String str) { RetryingSolrServer solr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); return solr.normalizeRequestKey(str); }
@Test public void testGetUnderlyingSolrServer() throws Exception { RetryingSolrServer retryingSolr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); assertSame(solrServer, retryingSolr.getUnderlyingSolrServer()); }
private void testGoodRequestNeedsNoRetries(MetricsFacade metricsFacade) throws Exception { CountingSolrServer countingSolrServer = new CountingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(countingSolrServer, getNoRetryPolicyFactory(), metricsFacade); SolrQuery query = getDefaultQuery(); solr.query(query); Assert.assertEquals(1, countingSolrServer.getNumRequests()); }
@Test public void testGetBinder() throws Exception { RetryingSolrServer retryingSolr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); assertSame(solrServer.getBinder(), retryingSolr.getBinder()); }
@Test public void testRetryTwice() throws Exception { SolrQuery query = getDefaultQuery(); solrServer.query(query); FailingSolrServer failingSolrServer = new FailingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(failingSolrServer, getRetryTwicePolicyFactory(), getMetricsFacade()); try { solr.query(query); fail(); } catch (RetriesExhaustedException e) { Assert.assertTrue(e.getCause() instanceof FailingSolrServer.InjectedSolrServerException); Assert.assertEquals(3, failingSolrServer.getNumRequests()); Assert.assertEquals(3, failingSolrServer.getNumInjectedFailures()); LOG.info("RetriesExhaustedException.getMessage(): " + e.getMessage()); } }
@Test public void testNoRetries() throws Exception { SolrQuery query = getDefaultQuery(); solrServer.query(query); FailingSolrServer failingSolrServer = new FailingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(failingSolrServer, getNoRetryPolicyFactory(), getMetricsFacade()); try { solr.query(query); fail(); } catch (RetriesExhaustedException e) { assertTrue(e.getCause() instanceof FailingSolrServer.InjectedSolrServerException); Assert.assertEquals(1, failingSolrServer.getNumRequests()); Assert.assertEquals(1, failingSolrServer.getNumInjectedFailures()); } }
@Test public void testRetryOfBadRequest() throws Exception { SolrInputDocument doc = new SolrInputDocument(); // bad doc is missing 'id' field // without RetryingSolrServer try { solrServer.add(doc); fail(); } catch (SolrException e) { assertEquals(ErrorCode.BAD_REQUEST.code, e.code()); } // RetryingSolrServer, retry twice CountingSolrServer countingSolrServer = new CountingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(countingSolrServer, getRetryTwicePolicyFactory(), getMetricsFacade()); try { solr.add(doc); fail(); } catch (RetriesExhaustedException e) { Assert.assertEquals(3, countingSolrServer.getNumRequests()); Assert.assertTrue(e.getCause() instanceof SolrException); SolrException sex = (SolrException) e.getCause(); Assert.assertEquals(ErrorCode.BAD_REQUEST.code, sex.code()); } }
SolrQuery query = getDefaultQuery(); FailingSolrServer failingSolrServer = new FailingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer( failingSolrServer, new DefaultRetryPolicyFactory(new FlexibleBoundedExponentialBackoffRetry(