@Test public void testGetExceptionKey() throws Exception { // matching: assertEquals(" UnknownHostException: <redacted>.foo.bar.com ", getExceptionKey(" UnknownHostException: vb0706.foo.bar.com ")); assertEquals(" collection: collection1 slice: shard<redacted> ", getExceptionKey(" collection: collection1 slice: shard130 ")); assertEquals(" _SHARD<redacted>_REPLICA<redacted> ", getExceptionKey(" _SHARD110_REPLICA3 ")); assertEquals("Xhttps://<redacted>.foo.bar.com:8983y", getExceptionKey("Xhttps://vb0706.foo.bar.com:8983y")); assertEquals("Xhttp://<redacted>.foo.bar.com", getExceptionKey("Xhttp://vb0706.foo.bar.com")); // no port assertEquals("Xhttp://<redacted>.foo.bar.com/", getExceptionKey("Xhttp://vb0706.foo.bar.com/")); // no port assertEquals("Xhttp://<redacted>.foo.bar.com]", getExceptionKey("Xhttp://vb0706.foo.bar.com]")); // no port assertEquals("Xhttp%3A%2F%2F<redacted>.foo.bar.com]", getExceptionKey("Xhttp%3A%2F%2Fvb0706.foo.bar.com]")); // escaped :// assertEquals("ftp://<redacted>.foo.bar:8983/some/path", getExceptionKey("ftp://vb0706.foo.bar:8983/some/path")); // with path assertEquals("Ftp+-.://<redacted>.foo.bar:8983/some/path", getExceptionKey("Ftp+-.://vb0706.foo.bar:8983/some/path")); // scheme with plus, minus and dot assertEquals("insertAndQueryTweets_shard<redacted>_replica<redacted>", getExceptionKey("insertAndQueryTweets_shard30_replica3")); assertEquals("foo bar", getExceptionKey("foo bar")); // whitespace assertEquals("foo bar", getExceptionKey("foo\nbar")); // whitespace assertEquals("foo bar", getExceptionKey("foo\n\tbar")); // whitespace assertEquals("IOException msg", getExceptionKey("java.io.IOException msg")); // omit package name of well known Exception classes // not matching: String str; assertEquals(str = "Xhttps:/vb0706.foo.bar.com:8983y", getExceptionKey(str)); // missing :// assertEquals(str = "://vb0706.foo.bar.com:8983y", getExceptionKey(str)); // missing scheme assertEquals(str = "foo", getExceptionKey(str)); }
@Test public void testGetUnderlyingSolrServer() throws Exception { RetryingSolrServer retryingSolr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); assertSame(solrServer, retryingSolr.getUnderlyingSolrServer()); }
@BeforeClass public static void beforeClass() throws Exception { initCore( "solrconfig.xml", "schema.xml", RESOURCES_DIR + File.separator + DEFAULT_BASE_DIR ); }
@Test public void testNormalizeRequestKey() throws Exception { assertEquals("&NOW=<redacted>", normalizeRequestKey("&NOW=1448689151133")); }
@Test public void testGoodRequestNeedsNoRetriesWithNonNullMetricsFacade() throws Exception { testGoodRequestNeedsNoRetries(getMetricsFacade()); }
@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 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 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()); } }
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 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 testRetries() throws Exception { new DefaultRetryPolicyFactory(); SolrQuery query = getDefaultQuery(); FailingSolrServer failingSolrServer = new FailingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer( 20, TimeUnit.MINUTES.toNanos(5))), getMetricsFacade() ); Assert.assertNotNull(solr.query(query)); try { solr.query(query); fail(); } catch (RetriesExhaustedException e) { assertTrue(e.getCause() instanceof FailingSolrServer.InjectedSolrServerException); Assert.assertEquals(1, failingSolrServer.getNumRequests()); Assert.assertEquals(1, failingSolrServer.getNumInjectedFailures());
private String normalizeRequestKey(String str) { RetryingSolrServer solr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); return solr.normalizeRequestKey(str); }
@Test public void testGetBinder() throws Exception { RetryingSolrServer retryingSolr = new RetryingSolrServer(solrServer, getNoRetryPolicyFactory(), getMetricsFacade()); assertSame(solrServer.getBinder(), retryingSolr.getBinder()); }