1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import static org.junit.Assert.fail;
22
23 import java.io.IOException;
24 import java.util.concurrent.atomic.AtomicBoolean;
25
26 import org.apache.hadoop.hbase.MediumTests;
27 import org.apache.hadoop.hbase.RegionTooBusyException;
28 import org.apache.hadoop.hbase.client.Get;
29 import org.apache.hadoop.hbase.util.Bytes;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.experimental.categories.Category;
33
34
35
36
37
38 @Category(MediumTests.class)
39 public class TestHRegionBusyWait extends TestHRegion {
40
41
42 @Before
43 public void setup() throws IOException {
44 super.setup();
45 CONF.set("hbase.busy.wait.duration", "1000");
46 }
47
48
49
50
51 @Test (timeout=6000)
52 public void testRegionTooBusy() throws IOException {
53 String method = "testRegionTooBusy";
54 byte[] tableName = Bytes.toBytes(method);
55 byte[] family = Bytes.toBytes("family");
56 region = initHRegion(tableName, method, CONF, family);
57 final AtomicBoolean stopped = new AtomicBoolean(true);
58 Thread t = new Thread(new Runnable() {
59 @Override
60 public void run() {
61 try {
62 region.lock.writeLock().lock();
63 stopped.set(false);
64 while (!stopped.get()) {
65 Thread.sleep(100);
66 }
67 } catch (InterruptedException ie) {
68 } finally {
69 region.lock.writeLock().unlock();
70 }
71 }
72 });
73 t.start();
74 Get get = new Get(row);
75 try {
76 while (stopped.get()) {
77 Thread.sleep(100);
78 }
79 region.get(get);
80 fail("Should throw RegionTooBusyException");
81 } catch (InterruptedException ie) {
82 fail("test interrupted");
83 } catch (RegionTooBusyException e) {
84
85 } finally {
86 stopped.set(true);
87 try {
88 t.join();
89 } catch (Throwable e) {
90 }
91
92 HRegion.closeHRegion(region);
93 region = null;
94 }
95 }
96 }