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 java.io.IOException;
22 import java.util.concurrent.atomic.AtomicBoolean;
23
24 import org.apache.hadoop.hbase.MediumTests;
25 import org.apache.hadoop.hbase.RegionTooBusyException;
26 import org.apache.hadoop.hbase.client.Get;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31
32
33
34
35 @Category(MediumTests.class)
36 @SuppressWarnings("deprecation")
37 public class TestHRegionBusyWait extends TestHRegion {
38
39
40 public TestHRegionBusyWait() {
41 conf.set("hbase.busy.wait.duration", "1000");
42 }
43
44
45
46
47 @Test (timeout=2000)
48 public void testRegionTooBusy() throws IOException {
49 String method = "testRegionTooBusy";
50 byte[] tableName = Bytes.toBytes(method);
51 byte[] family = Bytes.toBytes("family");
52 region = initHRegion(tableName, method, conf, family);
53 final AtomicBoolean stopped = new AtomicBoolean(true);
54 Thread t = new Thread(new Runnable() {
55 @Override
56 public void run() {
57 try {
58 region.lock.writeLock().lock();
59 stopped.set(false);
60 while (!stopped.get()) {
61 Thread.sleep(100);
62 }
63 } catch (InterruptedException ie) {
64 } finally {
65 region.lock.writeLock().unlock();
66 }
67 }
68 });
69 t.start();
70 Get get = new Get(row);
71 try {
72 while (stopped.get()) {
73 Thread.sleep(100);
74 }
75 region.get(get);
76 fail("Should throw RegionTooBusyException");
77 } catch (InterruptedException ie) {
78 fail("test interrupted");
79 } catch (RegionTooBusyException e) {
80
81 } finally {
82 stopped.set(true);
83 try {
84 t.join();
85 } catch (Throwable e) {
86 }
87
88 HRegion.closeHRegion(region);
89 region = null;
90 }
91 }
92 }