1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.errorhandling;
19
20 import static org.junit.Assert.assertArrayEquals;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertTrue;
24
25 import org.apache.hadoop.hbase.testclassification.SmallTests;
26 import org.junit.Test;
27 import org.junit.experimental.categories.Category;
28
29 import com.google.protobuf.InvalidProtocolBufferException;
30
31
32
33
34 @Category(SmallTests.class)
35 public class TestForeignExceptionSerialization {
36 private static final String srcName = "someNode";
37
38
39
40
41
42 @Test
43 public void testSimpleException() throws InvalidProtocolBufferException {
44 String data = "some bytes";
45 ForeignException in = new ForeignException("SRC", new IllegalArgumentException(data));
46
47 ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, in));
48 assertNotNull(e);
49
50
51 StackTraceElement elem = new StackTraceElement(this.getClass().toString(), "method", "file", 1);
52 in.setStackTrace(new StackTraceElement[] { elem });
53 e = ForeignException.deserialize(ForeignException.serialize(srcName, in));
54
55 assertNotNull(e);
56 assertEquals("Stack trace got corrupted", elem, e.getCause().getStackTrace()[0]);
57 assertEquals("Got an unexpectedly long stack trace", 1, e.getCause().getStackTrace().length);
58 }
59
60
61
62
63
64
65 @Test
66 public void testRemoteFromLocal() throws InvalidProtocolBufferException {
67 String errorMsg = "some message";
68 Exception generic = new Exception(errorMsg);
69 generic.printStackTrace();
70 assertTrue(generic.getMessage().contains(errorMsg));
71
72 ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, generic));
73 assertArrayEquals("Local stack trace got corrupted", generic.getStackTrace(), e.getCause().getStackTrace());
74
75 e.printStackTrace();
76 assertTrue(e.getCause().getCause() == null);
77
78
79 assertTrue(e.getCause().getMessage().contains(errorMsg));
80 }
81
82 }