1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver.handler;
19
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23
24 import java.io.IOException;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.hadoop.hbase.HBaseTestingUtility;
29 import org.apache.hadoop.hbase.HConstants;
30 import org.apache.hadoop.hbase.HRegionInfo;
31 import org.apache.hadoop.hbase.HTableDescriptor;
32 import org.apache.hadoop.hbase.Server;
33 import org.apache.hadoop.hbase.regionserver.HRegion;
34 import org.apache.hadoop.hbase.regionserver.RegionServerServices;
35 import org.apache.hadoop.hbase.util.MockRegionServerServices;
36 import org.apache.hadoop.hbase.util.MockServer;
37 import org.apache.zookeeper.KeeperException;
38 import org.apache.zookeeper.KeeperException.NodeExistsException;
39 import org.junit.Test;
40 import org.mockito.Mockito;
41
42
43
44
45 public class TestCloseRegionHandler {
46 static final Log LOG = LogFactory.getLog(TestCloseRegionHandler.class);
47 private final static HBaseTestingUtility HTU = new HBaseTestingUtility();
48
49
50
51
52
53
54
55
56 @Test public void testFailedFlushAborts()
57 throws IOException, NodeExistsException, KeeperException {
58 final Server server = new MockServer(HTU, false);
59 final RegionServerServices rss = new MockRegionServerServices();
60 HTableDescriptor htd = new HTableDescriptor("testFailedFlushAborts");
61 final HRegionInfo hri =
62 new HRegionInfo(htd.getName(), HConstants.EMPTY_END_ROW,
63 HConstants.EMPTY_END_ROW);
64 HRegion region =
65 HRegion.createHRegion(hri, HTU.getDataTestDir(),
66 HTU.getConfiguration(), htd);
67 assertNotNull(region);
68
69 HRegion spy = Mockito.spy(region);
70 final boolean abort = false;
71 Mockito.when(spy.close(abort)).
72 thenThrow(new RuntimeException("Mocked failed close!"));
73
74
75 rss.addToOnlineRegions(spy);
76
77 assertFalse(server.isStopped());
78 CloseRegionHandler handler =
79 new CloseRegionHandler(server, rss, hri, false, false);
80 boolean throwable = false;
81 try {
82 handler.process();
83 } catch (Throwable t) {
84 throwable = true;
85 } finally {
86 assertTrue(throwable);
87
88 assertTrue(server.isStopped());
89 }
90 }
91 }