You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mrunit.apache.org by db...@apache.org on 2012/12/01 00:19:27 UTC
git commit: MRUNIT-158: withOutput doesn't generate useful
information with MapWritable on error
Updated Branches:
refs/heads/trunk 3c7740677 -> 2f9b6f787
MRUNIT-158: withOutput doesn't generate useful information with MapWritable on error
Project: http://git-wip-us.apache.org/repos/asf/mrunit/repo
Commit: http://git-wip-us.apache.org/repos/asf/mrunit/commit/2f9b6f78
Tree: http://git-wip-us.apache.org/repos/asf/mrunit/tree/2f9b6f78
Diff: http://git-wip-us.apache.org/repos/asf/mrunit/diff/2f9b6f78
Branch: refs/heads/trunk
Commit: 2f9b6f787f9ceeb18509f5d984fe24f8db29cf42
Parents: 3c77406
Author: Dave Beech <db...@apache.org>
Authored: Fri Nov 30 23:18:27 2012 +0000
Committer: Dave Beech <db...@apache.org>
Committed: Fri Nov 30 23:18:27 2012 +0000
----------------------------------------------------------------------
.../java/org/apache/hadoop/mrunit/TestDriver.java | 37 +++++++++++++-
1 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mrunit/blob/2f9b6f78/src/main/java/org/apache/hadoop/mrunit/TestDriver.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/mrunit/TestDriver.java b/src/main/java/org/apache/hadoop/mrunit/TestDriver.java
index 7fd82b5..6d0db44 100644
--- a/src/main/java/org/apache/hadoop/mrunit/TestDriver.java
+++ b/src/main/java/org/apache/hadoop/mrunit/TestDriver.java
@@ -595,9 +595,13 @@ public abstract class TestDriver<K1, V1, K2, V2, T extends TestDriver<K1, V1, K2
final Errors errors = new Errors(LOG);
- // were we supposed to get output in the first place?
- if (expectedOutputs.isEmpty() && !outputs.isEmpty()) {
- errors.record("Expected no outputs; got %d outputs.", outputs.size());
+ if (!outputs.isEmpty()) {
+ // were we supposed to get output in the first place?
+ if (expectedOutputs.isEmpty()) {
+ errors.record("Expected no outputs; got %d outputs.", outputs.size());
+ }
+ // check that user's key and value writables implement equals, hashCode, toString
+ checkOverrides(outputs.get(0));
}
final Map<Pair<K2, V2>, List<Integer>> expectedPositions = buildPositionMap(expectedOutputs);
@@ -676,6 +680,33 @@ public abstract class TestDriver<K1, V1, K2, V2, T extends TestDriver<K1, V1, K2
errors.assertNone();
}
+ private void checkOverrides(final Pair<K2,V2> outputPair) {
+ checkOverride(outputPair.getFirst().getClass());
+ checkOverride(outputPair.getSecond().getClass());
+ }
+
+ private void checkOverride(final Class<?> clazz) {
+ try {
+ if (clazz.getMethod("equals", Object.class).getDeclaringClass() != clazz) {
+ LOG.warn(clazz.getCanonicalName() + ".equals(Object) " +
+ "is not being overridden - tests may fail!");
+ }
+ if (clazz.getMethod("hashCode").getDeclaringClass() != clazz) {
+ LOG.warn(clazz.getCanonicalName() + ".hashCode() " +
+ "is not being overridden - tests may fail!");
+ }
+ if (clazz.getMethod("toString").getDeclaringClass() != clazz) {
+ LOG.warn(clazz.getCanonicalName() + ".toString() " +
+ "is not being overridden - test failures may be difficult to diagnose.");
+ LOG.warn("Consider executing test using run() to access outputs");
+ }
+ } catch (SecurityException e) {
+ LOG.error(e);
+ } catch (NoSuchMethodException e) {
+ LOG.error(e);
+ }
+ }
+
private void checkTypesAndLogError(final List<Pair<K2, V2>> outputs,
final Pair<K2, V2> output, final List<Integer> positions,
final boolean orderMatters, final Errors errors,