1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase;
22
23
24
25
26
27
28
29
30
31 public class ResourceCheckerJUnitRule extends org.junit.rules.TestWatcher {
32 private ResourceChecker cu;
33 private boolean endDone;
34
35
36
37
38
39 private void start(String testName) {
40 cu = new ResourceChecker("before "+testName);
41 endDone = false;
42 }
43
44
45
46
47
48 private void end(String testName) {
49 if (!endDone) {
50 endDone = true;
51 cu.logInfo(ResourceChecker.Phase.END, "after " + testName);
52 cu.check("after "+testName);
53 }
54 }
55
56
57
58
59
60
61 private String descriptionToShortTestName(
62 org.junit.runner.Description description) {
63 final int toRemove = "org.apache.hadoop.hbase.".length();
64 return description.getTestClass().getName().substring(toRemove) +
65 "#" + description.getMethodName();
66 }
67
68 @Override
69 protected void succeeded(org.junit.runner.Description description) {
70 end(descriptionToShortTestName(description));
71 }
72
73 @Override
74 protected void failed(java.lang.Throwable e, org.junit.runner.Description description) {
75 end(descriptionToShortTestName(description));
76 }
77
78 @Override
79 protected void starting(org.junit.runner.Description description) {
80 start(descriptionToShortTestName(description));
81 }
82
83 @Override
84 protected void finished(org.junit.runner.Description description) {
85 end(descriptionToShortTestName(description));
86 }
87 }
88