HBASE-22536 TestForeignExceptionSerialization fails when run on JDK11

Signed-off-by: Sean Busbey <busbey@apache.org>
(cherry picked from commit 2280c8f4a88350278447515deb0811c42d0bb476)
This commit is contained in:
Sakthi 2019-06-03 22:47:27 -07:00 committed by Sean Busbey
parent 2c98f5eb8b
commit 44c3a63160
1 changed files with 17 additions and 2 deletions

View File

@ -17,12 +17,13 @@
*/
package org.apache.hadoop.hbase.errorhandling;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Objects;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
@ -75,7 +76,15 @@ public class TestForeignExceptionSerialization {
assertTrue(generic.getMessage().contains(errorMsg));
ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, generic));
assertArrayEquals("Local stack trace got corrupted", generic.getStackTrace(), e.getCause().getStackTrace());
// Workaround for java 11 - replaced assertArrayEquals with individual elements comparison
// using custom comparison helper method
assertEquals("Stacktrace lengths don't match", generic.getStackTrace().length,
e.getCause().getStackTrace().length);
for (int i = 0; i < generic.getStackTrace().length; i++) {
assertTrue("Local stack trace got corrupted at " + i + "th index",
compareStackTraceElement(generic.getStackTrace()[i], e.getCause().getStackTrace()[i]));
}
e.printStackTrace(); // should have ForeignException and source node in it.
assertTrue(e.getCause().getCause() == null);
@ -84,4 +93,10 @@ public class TestForeignExceptionSerialization {
assertTrue(e.getCause().getMessage().contains(errorMsg));
}
// Helper method to compare two stackTraceElements
private boolean compareStackTraceElement(StackTraceElement obj1, StackTraceElement obj2) {
return obj1.getClassName().equals(obj2.getClassName()) && obj1.getLineNumber() == obj2
.getLineNumber() && Objects.equals(obj1.getMethodName(), obj2.getMethodName()) && Objects
.equals(obj1.getFileName(), obj2.getFileName());
}
}