Fixing occasional test failure in RankEvalSpecTests

This commit is contained in:
Christoph Büscher 2017-11-15 18:35:52 +01:00 committed by Christoph Büscher
parent 3348d2317f
commit fdb24cd3e4
2 changed files with 7 additions and 4 deletions

View File

@ -262,11 +262,12 @@ public class RankEvalSpec implements Writeable, ToXContentObject {
return Objects.equals(ratedRequests, other.ratedRequests) && return Objects.equals(ratedRequests, other.ratedRequests) &&
Objects.equals(metric, other.metric) && Objects.equals(metric, other.metric) &&
Objects.equals(maxConcurrentSearches, other.maxConcurrentSearches) && Objects.equals(maxConcurrentSearches, other.maxConcurrentSearches) &&
Objects.equals(templates, other.templates); Objects.equals(templates, other.templates) &&
Objects.equals(indices, other.indices);
} }
@Override @Override
public final int hashCode() { public final int hashCode() {
return Objects.hash(ratedRequests, metric, templates, maxConcurrentSearches); return Objects.hash(ratedRequests, metric, templates, maxConcurrentSearches, indices);
} }
} }

View File

@ -110,7 +110,9 @@ public class RankEvalSpecTests extends ESTestCase {
try (XContentParser parser = createParser(JsonXContent.jsonXContent, shuffled.bytes())) { try (XContentParser parser = createParser(JsonXContent.jsonXContent, shuffled.bytes())) {
RankEvalSpec parsedItem = RankEvalSpec.parse(parser); RankEvalSpec parsedItem = RankEvalSpec.parse(parser);
// IRL these come from URL parameters - see RestRankEvalAction // indices, come from URL parameters, so they don't survive xContent roundtrip
// for the sake of being able to use equals() next, we add it to the parsed object
parsedItem.addIndices(testItem.getIndices());
assertNotSame(testItem, parsedItem); assertNotSame(testItem, parsedItem);
assertEquals(testItem, parsedItem); assertEquals(testItem, parsedItem);
assertEquals(testItem.hashCode(), parsedItem.hashCode()); assertEquals(testItem.hashCode(), parsedItem.hashCode());
@ -142,7 +144,7 @@ public class RankEvalSpecTests extends ESTestCase {
private static RankEvalSpec mutateTestItem(RankEvalSpec original) { private static RankEvalSpec mutateTestItem(RankEvalSpec original) {
List<RatedRequest> ratedRequests = new ArrayList<>(original.getRatedRequests()); List<RatedRequest> ratedRequests = new ArrayList<>(original.getRatedRequests());
EvaluationMetric metric = original.getMetric(); EvaluationMetric metric = original.getMetric();
Map<String, Script> templates = original.getTemplates(); Map<String, Script> templates = new HashMap<>(original.getTemplates());
List<String> indices = new ArrayList<>(original.getIndices()); List<String> indices = new ArrayList<>(original.getIndices());
int mutate = randomIntBetween(0, 3); int mutate = randomIntBetween(0, 3);