HBASE-4800 Result.compareResults is incorrect (James Taylor and Lars H)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1202827 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2011-11-16 18:38:12 +00:00
parent 207ca9895f
commit 99724ae460
3 changed files with 25 additions and 1 deletions

View File

@ -846,6 +846,7 @@ Release 0.90.5 - Unreleased
via todd)
HBASE-4562 When split doing offlineParentInMeta encounters error, it'll
cause data loss (bluedavy via Lars H)
HBASE-4800 Result.compareResults is incorrect (James Taylor and Lars H)
IMPROVEMENT
HBASE-4205 Enhance HTable javadoc (Eric Charles)

View File

@ -634,7 +634,7 @@ public class Result implements Writable, WritableWithSize {
KeyValue[] ourKVs = res1.raw();
KeyValue[] replicatedKVs = res2.raw();
for (int i = 0; i < res1.size(); i++) {
if (!ourKVs[i].equals(replicatedKVs[i]) &&
if (!ourKVs[i].equals(replicatedKVs[i]) ||
!Bytes.equals(ourKVs[i].getValue(), replicatedKVs[i].getValue())) {
throw new Exception("This result was different: "
+ res1.toString() + " compared to " + res2.toString());

View File

@ -98,4 +98,27 @@ public class TestResult extends TestCase {
assertTrue(r.containsColumn(family, qf));
}
}
/**
* Verify that Result.compareResults(...) behaves correctly.
*/
public void testCompareResults() throws Exception {
byte [] value1 = Bytes.toBytes("value1");
byte [] qual = Bytes.toBytes("qual");
KeyValue kv1 = new KeyValue(row, family, qual, value);
KeyValue kv2 = new KeyValue(row, family, qual, value1);
Result r1 = new Result(new KeyValue[] {kv1});
Result r2 = new Result(new KeyValue[] {kv2});
// no exception thrown
Result.compareResults(r1, r1);
try {
// these are different (HBASE-4800)
Result.compareResults(r1, r2);
fail();
} catch (Exception x) {
assertTrue(x.getMessage().startsWith("This result was different:"));
}
}
}