summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-08-15 10:29:54 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-08-15 10:29:54 +0200
commit5f8b1eaa920b24776db1b997c2b0c4e2e13af9be (patch)
tree43962a80fa70a4e6b6582d0c68851c2595996fb9 /container-search
parentd77ef6014424dacdae78fed5d06b9869f58d0288 (diff)
Whitespace changes only
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java26
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java98
2 files changed, 53 insertions, 71 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java
index 4ec04d0d577..2c2264deec9 100644
--- a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java
+++ b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java
@@ -60,6 +60,7 @@ import java.util.logging.Logger;
@Provides(FederationSearcher.FEDERATION)
@After("*")
public class FederationSearcher extends ForkingSearcher {
+
public static final String FEDERATION = "Federation";
private static abstract class TargetHandler {
@@ -136,8 +137,6 @@ public class FederationSearcher extends ForkingSearcher {
}
}
-
-
private static class ExecutionInfo {
final TargetHandler targetHandler;
final FederationOptions federationOptions;
@@ -151,8 +150,10 @@ public class FederationSearcher extends ForkingSearcher {
}
private static class CompoundKey {
+
private final String sourceName;
private final String propertyName;
+
CompoundKey(String sourceName, String propertyName) {
this.sourceName = sourceName;
this.propertyName = propertyName;
@@ -176,7 +177,9 @@ public class FederationSearcher extends ForkingSearcher {
}
private static class SourceKey extends CompoundKey {
+
public static final String SOURCE = "source.";
+
SourceKey(String sourceName, String propertyName) {
super(sourceName, propertyName);
}
@@ -196,8 +199,11 @@ public class FederationSearcher extends ForkingSearcher {
return SOURCE + super.toString();
}
}
+
private static class ProviderKey extends CompoundKey {
+
public static final String PROVIDER = "provider.";
+
ProviderKey(String sourceName, String propertyName) {
super(sourceName, propertyName);
}
@@ -216,6 +222,7 @@ public class FederationSearcher extends ForkingSearcher {
public String toString() {
return PROVIDER + super.toString();
}
+
}
private static final Logger log = Logger.getLogger(FederationSearcher.class.getName());
@@ -241,19 +248,18 @@ public class FederationSearcher extends ForkingSearcher {
public FederationSearcher(FederationConfig config, StrictContractsConfig strict,
ComponentRegistry<TargetSelector> targetSelectors) {
this(createResolver(config), strict.searchchains(), strict.propagateSourceProperties(),
- resolveSelector(config.targetSelector(), targetSelectors));
+ resolveSelector(config.targetSelector(), targetSelectors));
}
- private static TargetSelector resolveSelector(String selectorId, ComponentRegistry<TargetSelector> targetSelectors) {
- if (selectorId.isEmpty())
- return null;
+ private static TargetSelector resolveSelector(String selectorId,
+ ComponentRegistry<TargetSelector> targetSelectors) {
+ if (selectorId.isEmpty()) return null;
- return checkNotNull(
- targetSelectors.getComponent(selectorId),
- "Missing target selector with id" + quote(selectorId));
+ return checkNotNull(targetSelectors.getComponent(selectorId),
+ "Missing target selector with id" + quote(selectorId));
}
- //for testing
+ // for testing
public FederationSearcher(ComponentId id, SearchChainResolver searchChainResolver) {
this(searchChainResolver, false, PropagateSourceProperties.ALL, null);
}
diff --git a/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java
index bc00890624b..8c6940dd2c1 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java
@@ -99,18 +99,14 @@ public class FederationSearcherTestCase {
private Searcher createStrictFederationSearcher() {
StrictContractsConfig.Builder builder = new StrictContractsConfig.Builder();
builder.searchchains(true);
- final StrictContractsConfig contracts = new StrictContractsConfig(builder);
- return buildFederation(contracts);
+ return buildFederation(new StrictContractsConfig(builder));
}
- private Searcher buildFederation(final StrictContractsConfig contracts)
- throws RuntimeException {
-
- return new FederationSearcher(new FederationConfig(builder), contracts, new ComponentRegistry<TargetSelector>());
+ private Searcher buildFederation(StrictContractsConfig contracts) throws RuntimeException {
+ return new FederationSearcher(new FederationConfig(builder), contracts, new ComponentRegistry<>());
}
- private SearchChain createSearchChain(final ComponentId chainId,
- final Searcher searcher) {
+ private SearchChain createSearchChain(ComponentId chainId,Searcher searcher) {
return new SearchChain(chainId, searcher);
}
@@ -121,7 +117,7 @@ public class FederationSearcherTestCase {
Chain<Searcher> mainChain = new Chain<>("default", createFederationSearcher());
QueryProfile defaultProfile = new QueryProfile("default");
- defaultProfile.set("source.mySource1.hits", "%{hits}", (QueryProfileRegistry)null);
+ defaultProfile.set("source.mySource1.hits", "%{hits}", null);
defaultProfile.freeze();
Query q = new Query(QueryTestCase.httpEncode("?query=test"), defaultProfile.compile(null));
@@ -165,7 +161,7 @@ public class FederationSearcherTestCase {
}, SOURCE2);
- final Chain<Searcher> mainChain = new Chain<>("default",
+ Chain<Searcher> mainChain = new Chain<>("default",
new FederationSearcher(new FederationConfig(builder),
new StrictContractsConfig(
new StrictContractsConfig.Builder().searchchains(strictContracts)),
@@ -175,12 +171,12 @@ public class FederationSearcherTestCase {
@Test
public void testTraceOneSourceNoCloning() {
- final Chain<Searcher> mainChain = twoTracingSources(true);
+ Chain<Searcher> mainChain = twoTracingSources(true);
- final Query q = new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&traceLevel=1&sources=source1"));
+ Query q = new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&traceLevel=1&sources=source1"));
- final Execution execution = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null));
- final Result result = execution.search(q);
+ Execution execution = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null));
+ Result result = execution.search(q);
assertNull(result.hits().getError());
TwoSourceChecker lookForTraces = new TwoSourceChecker();
execution.trace().accept(lookForTraces);
@@ -190,12 +186,12 @@ public class FederationSearcherTestCase {
@Test
public void testTraceOneSourceWithCloning() {
- final Chain<Searcher> mainChain = twoTracingSources(false);
+ Chain<Searcher> mainChain = twoTracingSources(false);
- final Query q = new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&traceLevel=1&sources=source1"));
+ Query q = new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&traceLevel=1&sources=source1"));
- final Execution execution = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null));
- final Result result = execution.search(q);
+ Execution execution = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null));
+ Result result = execution.search(q);
assertNull(result.hits().getError());
TwoSourceChecker lookForTraces = new TwoSourceChecker();
execution.trace().accept(lookForTraces);
@@ -223,11 +219,11 @@ public class FederationSearcherTestCase {
private Result searchWithPropertyPropagation(PropagateSourceProperties.Enum propagateSourceProperties) {
addChained(new MockSearcher(), "mySource1");
addChained(new MockSearcher(), "mySource2");
- final Chain<Searcher> mainChain = new Chain<>("default", createFederationSearcher(propagateSourceProperties));
+ Chain<Searcher> mainChain = new Chain<>("default", createFederationSearcher(propagateSourceProperties));
- final Query q = new Query(QueryTestCase.httpEncode("?query=test&source.mySource1.presentation.summary=nalle"));
+ Query q = new Query(QueryTestCase.httpEncode("?query=test&source.mySource1.presentation.summary=nalle"));
- final Result result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(q);
+ Result result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(q);
assertNull(result.hits().getError());
return result;
}
@@ -236,13 +232,12 @@ public class FederationSearcherTestCase {
public void testDisablePropertyPropagation() {
Result result = searchWithPropertyPropagation(PropagateSourceProperties.NONE);
- assertNull(result.hits().get(0).getQuery().getPresentation()
- .getSummary());
+ assertNull(result.hits().get(0).getQuery().getPresentation().getSummary());
}
@Test
public void testNoCloning() {
- final String sourceName = "cloningcheck";
+ String sourceName = "cloningcheck";
Query query = new Query(QueryTestCase.httpEncode("?query=test&sources=" + sourceName));
addChained(new QueryCheckSearcher(query), sourceName);
addChained(new MockSearcher(), "mySource1");
@@ -255,18 +250,15 @@ public class FederationSearcherTestCase {
mainChain = new Chain<>("default", createFederationSearcher());
result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(query);
h = (HitGroup) result.hits().get(0);
- assertSame(QueryCheckSearcher.FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY,
- h.getError().getDetailedMessage());
+ assertSame(QueryCheckSearcher.FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY, h.getError().getDetailedMessage());
query = new Query(QueryTestCase.httpEncode("?query=test&sources=" + sourceName + ",mySource1"));
addChained(new QueryCheckSearcher(query), sourceName);
result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(query);
h = (HitGroup) result.hits().get(0);
assertEquals("source:" + sourceName, h.getId().stringValue());
- assertSame(QueryCheckSearcher.FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY,
- h.getError().getDetailedMessage());
- assertEquals("source:mySource1", result.hits().get(1).getId()
- .stringValue());
+ assertSame(QueryCheckSearcher.FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY, h.getError().getDetailedMessage());
+ assertEquals("source:mySource1", result.hits().get(1).getId().stringValue());
}
@Test
@@ -293,7 +285,7 @@ public class FederationSearcherTestCase {
String sourceName = query.properties().getString("sourceName", "unknown");
Result result = new Result(query);
for (int i = 1; i <= query.getHits(); i++) {
- final Hit hit = new Hit(sourceName + ":" + i, 1d / i);
+ Hit hit = new Hit(sourceName + ":" + i, 1d / i);
hit.setSource(sourceName);
result.hits().add(hit);
}
@@ -302,20 +294,6 @@ public class FederationSearcherTestCase {
}
- private static class SleepingMockSearcher extends Searcher {
-
- @Override
- public Result search(Query query, Execution execution) {
- try {
- Thread.sleep(100);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return execution.search(query);
- }
- }
-
-
private static class AnotherMockSearcher extends Searcher {
private static final String PROPAGATION_KEY = "hello";
@@ -349,20 +327,16 @@ public class FederationSearcherTestCase {
}
private FederationSearcher createMultiProviderFederationSearcher() {
- final FederationOptions options = new FederationOptions();
- final SearchChainResolver.Builder builder = new SearchChainResolver.Builder();
-
- final ComponentId provider1 = new ComponentId("provider1");
- final ComponentId provider2 = new ComponentId("provider2");
- final ComponentId news = new ComponentId("news");
- builder.addSearchChain(provider1, options,
- Collections.<String> emptyList());
- builder.addSearchChain(provider2, options,
- Collections.<String> emptyList());
- builder.addSourceForProvider(news, provider1, provider1, true, options,
- Collections.<String> emptyList());
- builder.addSourceForProvider(news, provider2, provider2, false,
- options, Collections.<String> emptyList());
+ FederationOptions options = new FederationOptions();
+ SearchChainResolver.Builder builder = new SearchChainResolver.Builder();
+
+ ComponentId provider1 = new ComponentId("provider1");
+ ComponentId provider2 = new ComponentId("provider2");
+ ComponentId news = new ComponentId("news");
+ builder.addSearchChain(provider1, options, Collections.<String> emptyList());
+ builder.addSearchChain(provider2, options, Collections.<String> emptyList());
+ builder.addSourceForProvider(news, provider1, provider1, true, options, Collections.<String> emptyList());
+ builder.addSourceForProvider(news, provider2, provider2, false, options, Collections.<String> emptyList());
return new FederationSearcher(new ComponentId("federation"), builder.build());
}
@@ -377,7 +351,7 @@ public class FederationSearcherTestCase {
@Override
public Result search(final Query query, final Execution execution) {
- final Result result = new Result(query);
+ Result result = new Result(query);
result.hits().add(new Hit(name + ":1"));
return result;
}
@@ -385,6 +359,7 @@ public class FederationSearcherTestCase {
}
private static class QueryCheckSearcher extends Searcher {
+
private static final String STATUS = "status";
public static final String FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY = "FederationSearcher has cloned the query.";
public static final String OK = "Got the correct query.";
@@ -396,7 +371,7 @@ public class FederationSearcherTestCase {
@Override
public Result search(final Query query, final Execution execution) {
- final Result result = new Result(query);
+ Result result = new Result(query);
if (query != this.query) {
result.hits().addError(ErrorMessage
.createErrorInPluginSearcher(FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY));
@@ -408,4 +383,5 @@ public class FederationSearcherTestCase {
return result;
}
}
+
}