InterleavedSearchInvoker extends SearchInvoker implements ResponseMonitor<SearchInvoker> { private Coverage createCoverage() { adjustDegradedCoverage(); Coverage coverage = new Coverage(answeredDocs, answeredActiveDocs, answeredNodesParticipated, 1); coverage.setNodesTried(askedNodes); coverage.setSoonActive(answeredSoonActiveDocs); int degradedReason = 0; if (timedOut) { degradedReason |= (adaptiveTimeoutCalculated ? DEGRADED_BY_ADAPTIVE_TIMEOUT : DEGRADED_BY_TIMEOUT); } if (degradedByMatchPhase) { degradedReason |= DEGRADED_BY_MATCH_PHASE; } coverage.setDegradedReason(degradedReason); return coverage; } InterleavedSearchInvoker(Collection<SearchInvoker> invokers, SearchCluster searchCluster, Set<Integer> alreadyFailedNodes); @Override void responseAvailable(SearchInvoker from);  }
@Test public void requireCorrectCoverageCalculationWhenAllNodesOk() throws IOException { SearchCluster cluster = new MockSearchCluster("!", 1, 2); invokers.add(new MockInvoker(0, createCoverage(50155, 50155, 50155, 1, 1, 0))); invokers.add(new MockInvoker(1, createCoverage(49845, 49845, 49845, 1, 1, 0))); SearchInvoker invoker = createInterleavedInvoker(cluster, 0); expectedEvents.add(new Event(null, 100, 0)); expectedEvents.add(new Event(null, 200, 1)); Result result = invoker.search(query, null); Coverage cov = result.getCoverage(true); assertThat(cov.getDocs(), is(100000L)); assertThat(cov.getNodes(), is(2)); assertThat(cov.getFull(), is(true)); assertThat(cov.getResultPercentage(), is(100)); assertThat(cov.getResultSets(), is(1)); assertThat(cov.getFullResultSets(), is(1)); }
@Test public void requireCorrectCoverageCalculationWhenResultsAreLimitedByMatchPhase() throws IOException { SearchCluster cluster = new MockSearchCluster("!", 1, 2); invokers.add(new MockInvoker(0, createCoverage(10101, 50155, 50155, 1, 1, DEGRADED_BY_MATCH_PHASE))); invokers.add(new MockInvoker(1, createCoverage(13319, 49845, 49845, 1, 1, DEGRADED_BY_MATCH_PHASE))); SearchInvoker invoker = createInterleavedInvoker(cluster, 0); expectedEvents.add(new Event(null, 100, 0)); expectedEvents.add(new Event(null, 200, 1)); Result result = invoker.search(query, null); Coverage cov = result.getCoverage(true); assertThat(cov.getDocs(), is(23420L)); assertThat(cov.getNodes(), is(2)); assertThat(cov.getFull(), is(false)); assertThat(cov.getResultPercentage(), is(23)); assertThat(cov.getResultSets(), is(1)); assertThat(cov.getFullResultSets(), is(0)); assertThat(cov.isDegradedByMatchPhase(), is(true)); }
@Test public void requireCorrectCoverageCalculationWhenResultsAreLimitedBySoftTimeout() throws IOException { SearchCluster cluster = new MockSearchCluster("!", 1, 2); invokers.add(new MockInvoker(0, createCoverage(5000, 50155, 50155, 1, 1, DEGRADED_BY_TIMEOUT))); invokers.add(new MockInvoker(1, createCoverage(4900, 49845, 49845, 1, 1, DEGRADED_BY_TIMEOUT))); SearchInvoker invoker = createInterleavedInvoker(cluster, 0); expectedEvents.add(new Event(null, 100, 0)); expectedEvents.add(new Event(null, 200, 1)); Result result = invoker.search(query, null); Coverage cov = result.getCoverage(true); assertThat(cov.getDocs(), is(9900L)); assertThat(cov.getNodes(), is(2)); assertThat(cov.getFull(), is(false)); assertThat(cov.getResultPercentage(), is(10)); assertThat(cov.getResultSets(), is(1)); assertThat(cov.getFullResultSets(), is(0)); assertThat(cov.isDegradedByTimeout(), is(true)); }
@Test public void requireCorrectCoverageCalculationWhenOneNodeIsUnexpectedlyDown() throws IOException { SearchCluster cluster = new MockSearchCluster("!", 1, 2); invokers.add(new MockInvoker(0, createCoverage(50155, 50155, 50155, 1, 1, 0))); invokers.add(new MockInvoker(1, createCoverage(49845, 49845, 49845, 1, 1, 0))); SearchInvoker invoker = createInterleavedInvoker(cluster, 0); expectedEvents.add(new Event(null, 100, 0)); expectedEvents.add(null); Result result = invoker.search(query, null); Coverage cov = result.getCoverage(true); assertThat(cov.getDocs(), is(50155L)); assertThat(cov.getNodes(), is(1)); assertThat(cov.getNodesTried(), is(2)); assertThat(cov.getFull(), is(false)); assertThat(cov.getResultPercentage(), is(50)); assertThat(cov.getResultSets(), is(1)); assertThat(cov.getFullResultSets(), is(0)); assertThat(cov.isDegradedByTimeout(), is(true)); }
@Test public void requireCorrectCoverageCalculationWhenDegradedCoverageIsExpected() throws IOException { SearchCluster cluster = new MockSearchCluster("!", 1, 2); invokers.add(new MockInvoker(0, createCoverage(50155, 50155, 50155, 1, 1, 0))); Coverage errorCoverage = new Coverage(0, 0, 0); errorCoverage.setNodesTried(1); invokers.add(new SearchErrorInvoker(ErrorMessage.createBackendCommunicationError("node is down"), errorCoverage)); SearchInvoker invoker = createInterleavedInvoker(cluster, 0); expectedEvents.add(new Event(null, 1, 1)); expectedEvents.add(new Event(null, 100, 0)); Result result = invoker.search(query, null); Coverage cov = result.getCoverage(true); assertThat(cov.getDocs(), is(50155L)); assertThat(cov.getNodes(), is(1)); assertThat(cov.getNodesTried(), is(2)); assertThat(cov.getFull(), is(false)); assertThat(cov.getResultPercentage(), is(50)); assertThat(cov.getResultSets(), is(1)); assertThat(cov.getFullResultSets(), is(0)); assertThat(cov.isDegradedByTimeout(), is(true)); }