diff --git a/core/src/test/java/org/elasticsearch/index/translog/SnapshotMatchers.java b/core/src/test/java/org/elasticsearch/index/translog/SnapshotMatchers.java index b9ce6fea21f5f..4ca6057bd6bc9 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/SnapshotMatchers.java +++ b/core/src/test/java/org/elasticsearch/index/translog/SnapshotMatchers.java @@ -22,7 +22,6 @@ import org.elasticsearch.ElasticsearchException; import org.hamcrest.Description; import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hamcrest.TypeSafeMatcher; import java.io.IOException; @@ -135,9 +134,10 @@ public void describeTo(Description description) { } } - - public static class ContainingInAnyOrderMatcher extends TypeSafeDiagnosingMatcher { + public static class ContainingInAnyOrderMatcher extends TypeSafeMatcher { private final Collection expectedOps; + private List notFoundOps; + private List notExpectedOps; static List drainAll(Translog.Snapshot snapshot) throws IOException { final List actualOps = new ArrayList<>(); @@ -153,34 +153,41 @@ public ContainingInAnyOrderMatcher(Collection expectedOps) { } @Override - protected boolean matchesSafely(Translog.Snapshot snapshot, Description mismatchDescription) { + protected boolean matchesSafely(Translog.Snapshot snapshot) { try { List actualOps = drainAll(snapshot); - - List notFound = expectedOps.stream() + notFoundOps = expectedOps.stream() .filter(o -> actualOps.contains(o) == false) .collect(Collectors.toList()); - if (notFound.isEmpty() == false) { - mismatchDescription - .appendText(" Operations not found").appendValueList("[", ", ", "]", notFound); - } - - List notExpected = actualOps.stream() + notExpectedOps = actualOps.stream() .filter(o -> expectedOps.contains(o) == false) .collect(Collectors.toList()); - if (notExpected.isEmpty() == false) { - mismatchDescription - .appendText(" Operations not expected ").appendValueList("[", ", ", "]", notExpected); - } - return notFound.isEmpty() && notExpected.isEmpty(); + return notFoundOps.isEmpty() && notExpectedOps.isEmpty(); } catch (IOException ex) { throw new ElasticsearchException("failed to read snapshot content", ex); } } @Override - public void describeTo(Description description) { + protected void describeMismatchSafely(Translog.Snapshot snapshot, Description mismatchDescription) { + if (notFoundOps.isEmpty() == false) { + mismatchDescription + .appendText("not found ").appendValueList("[", ", ", "]", notFoundOps); + } + if (notExpectedOps.isEmpty() == false) { + if (notFoundOps.isEmpty() == false) { + mismatchDescription.appendText("; "); + } + mismatchDescription + .appendText("not expected ").appendValueList("[", ", ", "]", notExpectedOps); + } + } + @Override + public void describeTo(Description description) { + description.appendText("snapshot contains ") + .appendValueList("[", ", ", "]", expectedOps) + .appendText(" in any order."); } } }